zsh-workers
 help / color / mirror / code / Atom feed
* Completing option/value pairs without space
@ 2001-03-21 16:56 Mario Lang
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Lang @ 2001-03-21 16:56 UTC (permalink / raw)
  To: zsh-workers

Hello.

I am currently defining a _ecasound autoload function.

A typical command line of ecasound looks like this:
ecasound -d:3 -a:1 -i myfile.wav -efs:100,50 -kl:1,100,5000,10 -a:all -o /dev/dsp

relevant parts of the manpage are:
NAME
       ecasound  - sample editor, multitrack recorder, fx-proces-
       sor, etc.

SYNOPSIS
       ecasound  [  general_options  ]  {  [  chain_setup   ]   [
       effect_setup ] [ input_setup ] [ output_setup ] }

OPTIONS
       Notice  that  the order of parameters given on the command
       line is important!

       GLOBAL OPTIONS

       -d:debug_level
              Set  the  debug level to 'debug_level'. This a bit-
              masked value, that defaults  to  3.  See  ECA_DEBUG
              class  documentation  for  more detailed info about
              various debug_level values.

       GENERAL

       -a:chainname1, chainname2, ...
              Select active signal chains.  All  effects,  inputs
              and  outputs are assigned to these chains. If there
              are no -a options given,  default  chain  is  used.
              Chain  name  'all'  is  reserved and means that all
              chains are selected. By giving multiple -a options,
              you can control to which chains effects, inputs and
              outputs are assigned to. Look at the EXAMPLES  sec-
              tion for more detailed info about the usage of this
              option.

       EFFECT SETUP

       FILTER EFFECTS

       -efs:center-freq,width
              Resonator.  'center_freq'  is the center frequency.
              Width is specified in Hz. Basicly just another res-
              onating bandpass filter.

For the rest of the stuff, go figure.

I tried to use the _arguments function, but I came across
a problem which someone here perhaps can cast a little light on:

The colon and the comma should be regarded as separators.
Here is my current code:

#compdef ecasound

local context state line
typeset -A opt_args

_arguments \
  '-c[Start in interactive mode]' \
  '-d\:[Debug level]:Debug level:' \
  '-D[Print all debug information to stderr]' \
  '-q[Quiet mode, no output]' \
  '--help[Show help]' \
  '--version[Show version information]' \
  '-n\:[Set the name of chainsetup]' \
  '-s\:[Create a new chainsetup from file]:filename:_files' \
  '-sr\:[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)'

When I now e.g. do:
ecasound -sr:<TAB>
i get a space, and when hitting tab again, I get the sampling rates for completion.

The same problem would strike when I come to the more complicated
effects. e.g. I would like to have:
ecasound ... -efs:<TAB>
and get
-efs: -- Resonator center freq

and when doing
ecasound ... -efs:100,<TAB>
Id like to get
-efs:*, -- resonator width

And a really reall neat(tm) gadget would be:
ecasound ... -efs:100,50 -kl:<TAB>
should give
-kl:1 -- Linear controller controlling Resonator freq
-kl:2 -- Linear controller controlling Resonator width

and so on.

Is this possible with current completion system?
Ecasound has so many different command line parameters that
such type of completion would be necessary. Otherwise the completion
for ecasoud will not improve usability a lot...

Any hints here?

  

-- 
CYa,
   Mario <mlang@delysid.org>
Homepage(s): http://delysid.org | http://piss.at/


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

* Re: Completing option/value pairs without space
  2001-03-22  9:27 Sven Wischnowsky
  2001-03-22 23:29 ` Mario Lang
@ 2001-03-24 15:03 ` Oliver Kiddle
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2001-03-24 15:03 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
> 
> And one remark to all -workers: with the function below completion
> after `ecasound -efs:<TAB>' makes _arguments report (and show) `-efs:'
> as a possible completion.  That's correct somehow, but looks very
> weird in this case.  Hm.

I don't really understand why it is "correct somehow". It seems to occur
only with options ending in a colon and there shouldn't be anything
special about the colon, only that if not quoted, it would mean
something different. Isn't this _arguments failing to account for the
quoting somewhere? Or is 13725 fixing this?

Oliver



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

* Re: Completing option/value pairs without space
  2001-03-22  9:27 Sven Wischnowsky
@ 2001-03-22 23:29 ` Mario Lang
  2001-03-24 15:03 ` Oliver Kiddle
  1 sibling, 0 replies; 4+ messages in thread
From: Mario Lang @ 2001-03-22 23:29 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-workers

Sven Wischnowsky <wischnow@informatik.hu-berlin.de> wrote a very
clear explanation of what I had missed regarding completion programming till yet.

Thanks alot. 10% of ecasound already work. If I were on debian-devel
I'd say: "I am going to package this". Would you like to integrate such
a thing into the distribution? _ecasound following next week...

Once again, thanks for the really nice tutorial.


-- 
CYa,
   Mario <mlang@delysid.org>
Homepage(s): http://delysid.org | http://piss.at/


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

* Re: Completing option/value pairs without space
@ 2001-03-22  9:27 Sven Wischnowsky
  2001-03-22 23:29 ` Mario Lang
  2001-03-24 15:03 ` Oliver Kiddle
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2001-03-22  9:27 UTC (permalink / raw)
  To: zsh-workers


Mario Lang wrote:

> ...
> 
> _arguments \
>   '-c[Start in interactive mode]' \
>   '-d\:[Debug level]:Debug level:' \
>   '-D[Print all debug information to stderr]' \
>   '-q[Quiet mode, no output]' \
>   '--help[Show help]' \
>   '--version[Show version information]' \
>   '-n\:[Set the name of chainsetup]' \
>   '-s\:[Create a new chainsetup from file]:filename:_files' \
>   '-sr\:[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)'
> 
> When I now e.g. do:
> ecasound -sr:<TAB>
> i get a space, and when hitting tab again, I get the sampling rates for completion.

You have to tell _arguments that the option's argument comes directly
after the option.  That's done by adding `-' after the option name
(before the description), as in:

  '-sr\:-[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)' \

> The same problem would strike when I come to the more complicated
> effects. e.g. I would like to have:
> ecasound ... -efs:<TAB>
> and get
> -efs: -- Resonator center freq
> 
> and when doing
> ecasound ... -efs:100,<TAB>
> Id like to get
> -efs:*, -- resonator width

That's done using actions of the `->state' form, e.g.:

  '-efs\:-[Set resonator parameters]: :->efs' \

After the call to _arguments one can then test if the real action for
`efs' has to be taken:

  case $state in
  efs)
    if compset -P '*,'; then
      _message 'Resonator width'
    else
      _message 'Resonator center frequency'
    fi
    ;;
    ...
  esac

> And a really reall neat(tm) gadget would be:
> ecasound ... -efs:100,50 -kl:<TAB>
> should give
> -kl:1 -- Linear controller controlling Resonator freq
> -kl:2 -- Linear controller controlling Resonator width
> 
> and so on.

You didn't describe `-kl' so I don't know what it gets as arguments.
If you only need it to complete `1' or `2' (or `3',...) with some
description and some other values separated by commas one woul use
another:

  '-kl\:-[linear controller]: :->kl'

with a case-branch such as:

  kl)
    if compset -P '*,'; then
      _message 'Linear controller value...'
    else
      _values 'Linear controller parameters' \
        '1[Linear controller controlling resonator freq]' \
        '2[Linear controller controlling resonator width]'
    fi

If the values and descriptions completed after `-kl' depend on
previous options one could still do it but one would have to look
either into the opt_args associative array to find the options set on
the line (and their values) or one could loop through the $words array 
set up by the completion system to contain the words on the line (one
would probably start at element $CURSOR-1 -- the word before the
cursor -- and go back to the first word to find the options on which
one has to decide what to complete).

Below are all the code snippets above merged into your function.

Two remarks: without a `->state' action one doesn't need to make local 
all those parameters.  And the `&& return 0' makes sure that the
function is left if `_arguments' says that it's sure to have
completely handled completion in the current context.

And one remark to all -workers: with the function below completion
after `ecasound -efs:<TAB>' makes _arguments report (and show) `-efs:' 
as a possible completion.  That's correct somehow, but looks very
weird in this case.  Hm.


Bye
 Sven

#compdef ecasound

local context state line
typeset -A opt_args

_arguments \
  '-c[Start in interactive mode]' \
  '-d\:[Debug level]:Debug level:' \
  '-D[Print all debug information to stderr]' \
  '-q[Quiet mode, no output]' \
  '--help[Show help]' \
  '--version[Show version information]' \
  '-n\:[Set the name of chainsetup]' \
  '-s\:[Create a new chainsetup from file]:filename:_files' \
  '-sr\:-[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)' \
  '-efs\:-[Set resonator parameters]: :->efs' \
  '-kl\:-[linear controller]: :->kl' && return 0

case $state in
efs)
  if compset -P '*,'; then
    _message 'Resonator width'
  else
    _message 'Resonator center frequency'
  fi
  ;;
kl)
  if compset -P '*,'; then
    _message 'Linear controller value...'
  else
    _values 'Linear controller parameters' \
      '1[Linear controller controlling resonator freq]' \
      '2[Linear controller controlling resonator width]'
  fi
  ;;
esac

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~2001-03-25 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-21 16:56 Completing option/value pairs without space Mario Lang
2001-03-22  9:27 Sven Wischnowsky
2001-03-22 23:29 ` Mario Lang
2001-03-24 15:03 ` Oliver Kiddle

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).