zsh-workers
 help / color / mirror / code / Atom feed
* Re: A Completion Function for FIGlet
@ 2002-03-24 21:15 Felix Rosencrantz
  0 siblings, 0 replies; 4+ messages in thread
From: Felix Rosencrantz @ 2002-03-24 21:15 UTC (permalink / raw)
  To: zsh-workers, beppu

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 4088 bytes --]

Just a shameless plug for my xml to completion tools....
The figlet command doesn't have usage information in a format that is
usable by my tool.   There is simple usage information and there is a man
page.  Though if you created a GNU style usage/help screen like so (this
is based on the previously posted completion function and the man page).

    -c          center justify
    -k          use kerning
    -l          left justify
    -n          normal mode
    -o          let letters overlap
    -p          paragraph mode
    -r          right justify
    -s          smushed spacing
    -t          use terminal width
    -v          version
    -x          use default justification of font
    -D          use Deutsch character set
    -E          use English character set
    -L          left-to-right
    -N          clear controlfile list
    -R          right-to-left
    -S          smush letters together or else!
    -W          wide spacing
    -X          use default writing direction of font
    -w Width     output width (in columns)
    -d dir       Font Directory 
    -f change_font   Font 
    -C change_controlfile   Control file
    -I -1       Normal operation (default)
    -I -v       Version, copyright and usage information
    -I 0        Version, copyright and usage information
    -I 1        Version in integer format
    -I 2        Default font directory.
    -I 3        Name of font figlet would use
    -I 4        Output width in number columns.

And then giving a help2simple.pl command like so:
  help2simple.pl -c figlet -S -a message  \
    -x -c,-l,-r,-x \
    -x -t,-w -x -n,-p \
    -x -D,-E -x -N,-C \
    -x -S,-s,-k,-W,-o \
    -x -L,-R,-X \
    -x -v,-I < Figlet.help >! figlet_simple.xml

The -S says that all single dash flags are single letters.  The -x flag
says that the following comma separated list of flags are mutually exclusive.
The -a says that the first argument is a message.

The processing figlet_simple.xml with the XSLT script simple2long.xsl, and
then  arg.xsl you get a version of _figlet that looks like the following.
It still needs work, but it gets you part of the way and does some of
the book keeping for exclusion lists, backslashes on the help for the
constants for the -I flag.  And building a case statements for the "$state".
And it works as is, no problems with syntax errors.

-FR.

#compdef figlet 
#Generated by
#   simple2long.xsl
#   args.xsl
#   For details see:
#       http://www.geocities.com/f_rosencrantz/xml_completion.htm

 local context state line
           typeset -A opt_args
	_arguments  \
		"(-r -l -x)-c[center justify]" \
		"(-S -s -o -W)-k[use kerning]" \
		"(-r -c -x)-l[left justify]" \
		"(-p)-n[normal mode]" \
		"(-k -S -s -W)-o[let letters overlap]" \
		"(-n)-p[paragraph mode]" \
		"(-c -l -x)-r[right justify]" \
		"(-k -S -o -W)-s[smushed spacing]" \
		"(-w)-t[use terminal width]" \
		"(-I)-v[version]" \
		"(-r -c -l)-x[use default justification of font]" \
		"(-E)-D[use Deutsch character set]" \
		"(-D)-E[use English character set]" \
		"(-X -R)-L[left-to-right]" \
		"(-C)-N[clear controlfile list]" \
		"(-L -X)-R[right-to-left]" \
		"(-k -s -o -W)-S[smush letters together or else!]" \
		"(-k -S -s -o)-W[wide spacing]" \
		"(-L -R)-X[use default writing direction of font]" \
		"(-t)-w:output width (in columns):->Width" \
		"-d:Font Directory:->dir" \
		"-f:Font:->change_font" \
		"(-N)-C:Control file:->change_controlfile" \
		"(-v)-I: :((-1\:Normal\ operation\ \(default\)\  -v\:Version,\ copyright\
and\ usage\ information\  0\:Version,\ copyright\ and\ usage\ information\ 
1\:Version\ in\ integer\ format\  2\:Default\ font\ directory.\  3\:Name\ of\
font\ figlet\ would\ use\  4\:Output\ width\ in\ number\ columns.\ ))" \
		"*:Handling Tag message:->message" \
           && return 0
            
case $state in
  "change_controlfile");;
  "change_font");;
  "dir");;
  "message");;
  "Width");;
esac



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


^ permalink raw reply	[flat|nested] 4+ messages in thread
* A Completion Function for FIGlet
@ 2002-03-20  9:19 John Beppu
  2002-03-20 12:13 ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: John Beppu @ 2002-03-20  9:19 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1680 bytes --]

The attached file contains a completion function for figlet[1] that I just
finished writing, and I would like to donate it to the zsh distribution.
I don't think I've done anything terrible, but then again, this is 
my first completion function, so it wouldn't be surprising if I made
a few mistakes.  If there's anything wrong w/ it, please let me know.


I also have a few questions:

  regarding $opt_args
    Is it only set when you use the '->state' mechanism?
    It seems to be empty, otherwise.

  arguments to _arguments
    The following is a line from the completion function:

        "-d+[directory]:directory:_path_files -/" \
                        ^^^^^^^^^

    What is the purpose of the underlined string?
    When might this string be useful to someone who is
    writing completion functions?  Is their a proper name
    for the strings that go there?


[1] a program for rendering text using ascii art fonts
    http://ianchai.50megs.com/figlet.html


PS: I'm going to use this as the basis for a little article on writing
    completion functions.  I still need to improve my understanding of
    how this all works, though.  Zsh is so complicated...  My head
    hurts from RTFM.

    Many times, I've wished for a tool like perldoc.  It could be called
    zdoc, and you'd be able to do things like:

    Reading about modifiers
        zdoc -m :q
        zdoc -m :r

    Reading about flags
        zdoc -F @
        zdoc -F U

    Reading about options
        zdoc -o promptsubst

    Reading about functions that come w/ the distribution
        zdoc -f _arguments
        zdoc -f _tags

    etc. 

    just another perl hacker (spoiled by perldoc)


[-- Attachment #2: _figlet --]
[-- Type: text/plain, Size: 1262 bytes --]

#compdef figlet

_figlet() {
  local context state line
  local fontdir
  typeset -A opt_args

  fontdir=$(figlet -I2)

  _arguments -C -s \
    "-c[center justify]" \
    "-k[use kerning]" \
    "-l[left justify]" \
    "-n[normal mode]" \
    "-o[let letters overlap]" \
    "-p[paragraph mode]" \
    "-r[right justify]" \
    "-s[smushed spacing]" \
    "-t[use terminal width]" \
    "-v[version]" \
    "-x[use default justification of font]" \
    "-D[use Deutsch character set]" \
    "-E[use English character set]" \
    "-L[left-to-right]" \
    "-N[clear controlfile list]" \
    "-R[right-to-left]" \
    "-S[smush letters together or else!]" \
    "-W[wide spacing]" \
    "-X[use default writing direction of font]" \
    "-w+[output width]" \
    "-d+[directory]:directory:_path_files -/" \
    "-f+[font]:font:->change_font" \
    "-C+[control file]:->change_controlfile" \
    "-I+[info]:info:compadd 0 1 2 3 4" \
    && return 0


  (( $+opt_args[-d] )) && fontdir=$opt_args[-d]

  case $state in
  (change_font)
    _files -W $fontdir -g '*flf*' && return 0
    ;;
  (change_controlfile)
    _files -W $fontdir -g '*flc*' && return 0
    ;;
  esac

  return 1
}

# this is going to be what I use as the basis for my article.
# vim:sw=2 sts=2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-03-24 21:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-24 21:15 A Completion Function for FIGlet Felix Rosencrantz
  -- strict thread matches above, loose matches on Subject: below --
2002-03-20  9:19 John Beppu
2002-03-20 12:13 ` Oliver Kiddle
2002-03-20 22:55   ` John Beppu

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).