zsh-users
 help / color / mirror / code / Atom feed
* Interactive program in Zsh
@ 2004-06-09 14:32 DervishD
  2004-06-09 14:44 ` Pierre HABOUZIT
  2004-06-10 15:37 ` Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: DervishD @ 2004-06-09 14:32 UTC (permalink / raw)
  To: Zsh Users

    Hello all :)

    I need a program that processes some text and presents a few
options to the user. I know how to do it using 'read -k' for reading
keystrokes and using a couple of escape sequences and 'print' for
printing the output, but I would like to use zle widgets for that.

    What I mean is that I would like to use widget names instead of
escape sequences, something like getting 'up-line-or-history' instead
of "^[[A" if the user presses 'up arrow', so I can use the key combo
that the user wants for going up in a list instead of a fixed
sequence.

    I don't know if this is the proper approach for what I need to
do: the user is limited to use up arrow and down arrow for travelling
into the list of options (maybe pg-up and pg-down for scrolling) and
'enter' to select the highlighted option. The program must process a
text, present a list of options containing the text that matched
certain regex and allow the user to choose one of the options.

    Could you please point me to a source of information? Is this a
good approach or should I write a C program with ncurses? Portability
is not an issue, so to say I want the program be 'zsh-portable', able
to run in any zsh configuration (that's the reason I don't want to
use key sequences).

    Thanks a lot in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Interactive program in Zsh
  2004-06-09 14:32 Interactive program in Zsh DervishD
@ 2004-06-09 14:44 ` Pierre HABOUZIT
  2004-06-09 14:52   ` DervishD
  2004-06-10 15:37 ` Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: Pierre HABOUZIT @ 2004-06-09 14:44 UTC (permalink / raw)
  To: Zsh Users

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

>     I don't know if this is the proper approach for what I need to
> do: the user is limited to use up arrow and down arrow for travelling
> into the list of options (maybe pg-up and pg-down for scrolling) and
> 'enter' to select the highlighted option. The program must process a
> text, present a list of options containing the text that matched
> certain regex and allow the user to choose one of the options.

why don't you use dialog for that ?
I may be wrong, but i think it already implements all what you need
-- 
Pierre Habouzit
 
http://www.madism.org/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: Interactive program in Zsh
  2004-06-09 14:44 ` Pierre HABOUZIT
@ 2004-06-09 14:52   ` DervishD
  0 siblings, 0 replies; 8+ messages in thread
From: DervishD @ 2004-06-09 14:52 UTC (permalink / raw)
  To: Zsh Users

    Hi Pierre :)

 * Pierre HABOUZIT <pierre.habouzit@m4x.org> dixit:
> >     I don't know if this is the proper approach for what I need to
> > do: the user is limited to use up arrow and down arrow for travelling
> > into the list of options (maybe pg-up and pg-down for scrolling) and
> > 'enter' to select the highlighted option. The program must process a
> > text, present a list of options containing the text that matched
> > certain regex and allow the user to choose one of the options.
> why don't you use dialog for that ?
> I may be wrong, but i think it already implements all what you need

    AFAIK, dialog won't be able to do the processing, so I will end up
doing an script using sed, grep or awk to do the processing and
dialog (is not called cdialog nowadays?) for the user to choose the
options and run a program on them. I prefer to do all of it in an
script, although dialog will do the option-choosing part easily.

    Thanks for pointing, anyway :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Interactive program in Zsh
  2004-06-09 14:32 Interactive program in Zsh DervishD
  2004-06-09 14:44 ` Pierre HABOUZIT
@ 2004-06-10 15:37 ` Bart Schaefer
  2004-06-10 17:21   ` DervishD
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2004-06-10 15:37 UTC (permalink / raw)
  To: Zsh Users

On Wed, 9 Jun 2004, DervishD wrote:

>     I don't know if this is the proper approach for what I need to
> do: the user is limited to use up arrow and down arrow for travelling
> into the list of options (maybe pg-up and pg-down for scrolling) and
> 'enter' to select the highlighted option. The program must process a
> text, present a list of options containing the text that matched
> certain regex and allow the user to choose one of the options.

I would say the canonical way to do this is using a "select x in ..."  
loop -- "select" already being clever enough these days to paginate its
list of choices -- but that doesn't allow the user to scroll up and down
with arrow keys.  (I think that's only because the history is disabled,
as it uses the default keymaps.)

Or you could stuff the list of options into the history with "print -s"  
and then use "vared -h" to let the user choose one, but then they aren't
actually navigating through the list, just displaying them each in turn.
Maybe that would be good enough, combined with first printing out the
entire list, except then you run into pagination issues.  You'll have to
play with key bindings to keep the user from modifying the choices --
that'd be easier in recent zsh that let you redefine the whole keymap.

Also in 4.2.x you might be able to do something with zle-line-init to
start up one of the widgets (previously posted) that invoke menu selection
on the history, which would then be pretty nearly what you asked for.


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

* Re: Interactive program in Zsh
  2004-06-10 15:37 ` Bart Schaefer
@ 2004-06-10 17:21   ` DervishD
  2004-06-11  6:19     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: DervishD @ 2004-06-10 17:21 UTC (permalink / raw)
  To: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> >     I don't know if this is the proper approach for what I need to
> > do: the user is limited to use up arrow and down arrow for travelling
> > into the list of options (maybe pg-up and pg-down for scrolling) and
> > 'enter' to select the highlighted option. The program must process a
> > text, present a list of options containing the text that matched
> > certain regex and allow the user to choose one of the options.
> I would say the canonical way to do this is using a "select x in ..."  
> loop -- "select" already being clever enough these days to paginate its
> list of choices -- but that doesn't allow the user to scroll up and down
> with arrow keys.  (I think that's only because the history is disabled,
> as it uses the default keymaps.)

    And doesn't let me implement the navigation... I mean, I can use
'select', no problem, and that will do since it will present me the
list of choices, but I would like to do the navigation too, and
selects doesn't allow me to do that, since it reads from the keyboard
and does it's own output formatting (not configurable AFAIK).

> Or you could stuff the list of options into the history with "print -s"  
> and then use "vared -h" to let the user choose one, but then they aren't
> actually navigating through the list, just displaying them each in turn.
> Maybe that would be good enough, combined with first printing out the
> entire list, except then you run into pagination issues.  You'll have to
> play with key bindings to keep the user from modifying the choices --
> that'd be easier in recent zsh that let you redefine the whole keymap.

    Nice, but very complex if I need to modify the whole keymap. For
me would be easy to do the 'print -s', but instead of the list I will
print into the history the command to run the chosen option followed
by each option. Something like:

    command option1 
    command option2
    ...

    Don't know, very... ugly.
 
> Also in 4.2.x you might be able to do something with zle-line-init to
> start up one of the widgets (previously posted) that invoke menu selection
> on the history, which would then be pretty nearly what you asked for.

    That would be nice, too, but limited to zsh 4.2.x No problem for
me, but I would like to have this running at least in 4.0.x too.

    Anyway, I think I will use the 'select' way (I will rarely need
more than 20-30 options, and 'select' fills the lines beautifully) or
maybe I will try my first solution, using the key codes or bindkey to
get the mappings. The problem with that last solution is the speed:
slow and weird screen refreshing, etc. In addition to this, 'read -k',
when used with keys that generates multiple characters (an escape
sequence, for example), will read each character separately, so I
must assemble the individual chars and process the result. Very
complex...

    BTW, what I want to do is something like urlview, but with
multiple regexes each handled by a different handler. Currently it
can be done (but in a very ugly way) using a very BIG regex and using
url_handler.sh to do the discrimination, or maybe with multiple
configuration files, etc. Or even rewriting it (which I certainly
won't do!). But the point is that I would like to do with zsh just
for the sake of it, because I want, for learning O:)

    Thanks a lot for your help :) I'll try the 'select' way, for now.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Interactive program in Zsh
  2004-06-10 17:21   ` DervishD
@ 2004-06-11  6:19     ` Bart Schaefer
  2004-06-11  9:38       ` Peter Stephenson
  2004-06-11  9:41       ` DervishD
  0 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2004-06-11  6:19 UTC (permalink / raw)
  To: Zsh Users

On Thu, 10 Jun 2004, DervishD wrote:

>  * Bart Schaefer <schaefer@brasslantern.com> dixit:
> > Or you could stuff the list of options into the history with "print -s"  
> > and then use "vared -h"
> 
>     Nice, but very complex if I need to modify the whole keymap.

No, you just create a new empty keymap, insert only the bindings you want
to allow, and swap it in.  I _think_ it's possible to replace the map used
by vared that way ...

> For me would be easy to do the 'print -s', but instead of the list I
> will print into the history the command to run the chosen option
> followed by each option.

You've lost me, I fear.  Why would you need to do that?  Vared is going
to assign the selected value to a variable, not run it as a command.


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

* Re: Interactive program in Zsh
  2004-06-11  6:19     ` Bart Schaefer
@ 2004-06-11  9:38       ` Peter Stephenson
  2004-06-11  9:41       ` DervishD
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2004-06-11  9:38 UTC (permalink / raw)
  To: Zsh Users

Bart Schaefer wrote:
> No, you just create a new empty keymap, insert only the bindings you want
> to allow, and swap it in.  I _think_ it's possible to replace the map used
> by vared that way ...

Yes, this is very easy in... er... 4.2.1... vared takes options -M and
-m so you can explicitly specify the main and alternate keymaps to use.

pws


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: Interactive program in Zsh
  2004-06-11  6:19     ` Bart Schaefer
  2004-06-11  9:38       ` Peter Stephenson
@ 2004-06-11  9:41       ` DervishD
  1 sibling, 0 replies; 8+ messages in thread
From: DervishD @ 2004-06-11  9:41 UTC (permalink / raw)
  To: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> > For me would be easy to do the 'print -s', but instead of the list I
> > will print into the history the command to run the chosen option
> > followed by each option.
> You've lost me, I fear.  Why would you need to do that?  Vared is going
> to assign the selected value to a variable, not run it as a command.

    Sorry, I forgot that O:) Anyway, by now I'm testing a solution
using select and a little sed script to munge the text, script that I
don't know if it can be replaced by shell code, I will try in the
future but since I'm certainly not a sed guru nor a shell guru FWIW,
I will need some more help. The important point is that it works now,
no matter if it is not the most elegant piece of code in the world.

    Thanks for all :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

end of thread, other threads:[~2004-06-11  9:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-09 14:32 Interactive program in Zsh DervishD
2004-06-09 14:44 ` Pierre HABOUZIT
2004-06-09 14:52   ` DervishD
2004-06-10 15:37 ` Bart Schaefer
2004-06-10 17:21   ` DervishD
2004-06-11  6:19     ` Bart Schaefer
2004-06-11  9:38       ` Peter Stephenson
2004-06-11  9:41       ` DervishD

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