home of the madduck/ blog/
A good interface for selection?

I am working on a script to help me switch mail profiles from within vim, because mutt's profile abilities are seriously limited (even with muttprofile).

The script will have three modes: manual, menu, and auto. In manual mode, you tell it something like switch-profile debian and it converts an existing mail to use my Debian profile. In menu mode, it displays a menu of available profiles, and in auto mode uses heuristics defined by the profiles to determine which one to use.

My problem at the moment is menu mode. What I want is a good selection interface that (a) works over most any terminal, and (b) allows quick and dependable keyboard-driven selection. So far, I've had multiple ideas:

  1. A simple shell script that would assign [0-9a-z] to the profiles and then expect me to press one of the letters to select the profile I want (also see ssft). I don't particularly like this because if I added a profile to the presumably alphabetically sorted list, I'd have to relearn which keys to press when doing quick (subconscious) selection.

  2. debconf, which comes with multiple interfaces, but doesn't really seem made for the task. In the end, it would probably end up giving the same experience as (1) above.

  3. A method which I've implemented in the script (run it with the --menu option), which is reminiscent of "autocomplete". I need to add arrow selection and I have to figure out how to actually access $result from outside the while loop (this method doesn't work, because I need stdout for the interface and I have not managed to figure out using file descriptors 3 and above), but I already like it very much, although it seems rather brittle so far.

Do you have any other ideas? Or do you know of a tool/library I could use for this? I'd much rather have this work without having to install a separate package, but there's also no point in reinventing the wheel.

PS: I am using POSIX shell for this even though Perl or Python would be much better suited, simply because it's faster and available everywhere.

NP: Man on Fire / Habitat

Update: Jan Hudec points me to Vim's console-menus and now makes me ponder whether I want a vim-only solution, or one that could be used by friends of other editors too.

And Simon Huggins is trying to get me to use htag, which I'll have to check out.