LWN.net Logo

Design simple menus with Cursed Menu

By Forrest Cook
April 9, 2008

The Cursed Menu project implements a terminal-based menu system via the the Curses terminal control library:

Cursed Menu aims to create an ncurses based menu system for character based sessions. This menu program could be used to create user, system administration, or utility menus for clients connecting with text based clients such as telnet, ssh, or rlogin.

Version 1.0.3 of Cursed Menu was recently announced. Despite being unable to find any documentation whatsoever on the project page, your editor decided to try out the software. The code was downloaded as a tar.bz2 file, uncompressed and untared. The configure script was run on a system running Ubuntu 7.04. There was one dependency issue that was fairly easily solved by installing the libncurses5-dev package. After fixing that, the software configured and made correctly.

The next logical action was to take a look at the source code in the src/ subdirectory. The source files were mostly .cc and .hh indicating a C++ project. The cursedmenu binary was run and a blue curses screen similar to the example screenshot showed up. Navigating through the menus was simply a matter of using the arrow keys for movement and the Enter key for selecting an item. A longer description of the item under the cursor showed up on the lower left corner of the terminal screen.

A little more digging through the code revealed the configuration system for Cursed Menu. Each menu has an associated .cmd file, here's what the default main menu .cmd file looks like:

# default.cmd - The default Cursed Menu definition file
#
# Lines beginning with a pound sign (#) are comments.
# --------------------------------------------------------
#
debug = yes;
pause_after_execution = no;

   # Each menu file contain one "MainMenu" which is the
   # first menu displayed.
   # ---------------------------------------------------
   MenuBegin MainMenu
    
      MenuTitle=Default Menu
      MenuFore=white
      MenuBack=blue
    
      ItemName=Item #1
      ItemDesc=This is a very nice 1st item
      ItemExec=echo "Item #1"; sleep 5
      ItemEnd
    
      ItemName=Item #2
      ItemDesc=This is a very nice 2nd item
      ItemExec=echo "Item #2"; sleep 5
      ItemEnd
    
      ItemName=Sub Menu
      ItemDesc=Go to the Sub Menu
      ItemExec=MenuSub sub.cmd
      ItemEnd

      ItemName=Exit
      ItemDesc=Exit this menu
      ItemExec=MenuExit
      ItemEnd
   
   MenuEnd MainMenu

Customizing the .cmd file was fairly intuitive, shell commands were added to the ItemExec lines and ran when the menu item was selected. The cursedmenu binary picked up the changes in the .cmd file without recompilation.

Cursed Menu provides a quick and easy way to control simple shell scripts and could be useful for many purposes. The project could really benefit from some basic documentation, A simple README file with a description of the available commands would be a good start. Despite this lack, the code seems to function nicely and can be put to use as-is.


(Log in to post comments)

Design simple menus with Cursed Menu

Posted Apr 10, 2008 9:39 UTC (Thu) by tzafrir (subscriber, #11501) [Link]

I use pdmenu for similar tasks: http://kitenet.net/~joey/code/pdmenu/

Generally all the menu is in a single pdmenurc file (though you can include other files 
or even generate at startup. Generating menus at runtime is possible, but very 
limited)

Design simple menus with Cursed Menu

Posted Apr 14, 2008 21:46 UTC (Mon) by erwbgy (subscriber, #4104) [Link]

I'd certainly recommmend pdmenu. I used it to create a simple shell for users who has never seen Unix before - or even Windows in many cases. It's quick and pretty straightforward..

Design simple menus with Cursed Menu

Posted Apr 10, 2008 12:00 UTC (Thu) by nix (subscriber, #2304) [Link]

OK, now that's scary. I wrote a DOS-based menu system in Turbo Pascal fifteen years ago which
used a nearly-identical configuration file format: the names were identical, the nesting, as
far as I can see the semantics were too... The only bits I didn't have were the semicolons at
line ends.

(I didn't give my code to anyone that I can recall, so this must be an independent
reinvention.)

I suppose this is a fairly restricted problem domain, but even so it's a creepy coincidence.

Design simple menus with Cursed Menu

Posted Apr 10, 2008 19:07 UTC (Thu) by clugstj (subscriber, #4020) [Link]

It's also very similar to FMLI (Form and Menu Language Interpreter) that Sun ships with
Solaris.  It's old, crusty and buggy, but we've used it at work for at least 12 years now.

Design simple menus with Cursed Menu

Posted Apr 10, 2008 12:25 UTC (Thu) by rwmj (subscriber, #5474) [Link]

It's a bit unclear how you would go about modifying what appears in the menu. Write a new .cmd file?

Anyway I'll offer a couple of alternatives with my comments:

The first is the venerable dialog command, used (as a fork) by the Linux kernel configuration system. I think the original is also used by Debian. It's a bit limited in as much as you can basically only have a single menu / input form on screen at once, but two advantages are that it is easy to shell-script and available absolutely everywhere.

A second one is newt which is the system used by the Anaconda (Fedora, RHEL, CentOS, etc.) installer, at least when in text mode. This is a lot more flexible, but significantly harder to use. The C interface is barely documented and has a number of problems. I wrote some OCaml bindings and sent patches upstream to fix the most egregious problems in the C code.

Rich.

Design simple menus with Cursed Menu

Posted Apr 10, 2008 16:09 UTC (Thu) by tzafrir (subscriber, #11501) [Link]

In addition to newt, there's also S-Lang.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds