Menu

Introduction

A simple command-line menu system in Rust. Works on embedded systems, but also on your command-line.

NOTE: This crates works only in &str - there's no heap allocation, but there's also no automatic conversion to integers, boolean, etc.

``console user@host: ~/menu $ cargo run --example simple Compiling menu v0.2.0 (file:///home/user/menu) Finished dev [unoptimized + debuginfo] target(s) in 0.84 secs Runningtarget/debug/examples/simple` In enter_root()

help AVAILABLE ITEMS: foo [ ] [ OPTIONS... ] bar sub help [ ]

help foo SUMMARY: foo [ ] [ --verbose ] [ --level=INT ]

PARAMETERS: This is the help text for 'a' No help text found --verbose No help text found --level=INT Set the level of the dangle

DESCRIPTION: Makes a foo appear.

This is some extensive help text.

It contains multiple paragraphs and should be preceeded by the parameter list.

foo --level=3 --verbose 1 2 In selectfoo. Args = ["--level=3", "--verbose", "1", "2"] a = Ok(Some("1")) b = Ok(Some("2")) verbose = Ok(Some("")) level = Ok(Some("3")) nosuch_arg = Err(())

foo Error: Insufficient arguments given!

foo 1 2 3 3 Error: Too many arguments given

sub

/sub> help AVAILABLE ITEMS: baz quux exit help [ ]

exit

help AVAILABLE ITEMS: foo [ ] [ OPTIONS... ] bar sub help [ ]

^C user@host: ~/menu $ ```

Using

See examples/simple.rs for a working example that runs on Linux or Windows. Here's the menu definition from that example:

```rust const ROOTMENU: Menu = Menu { label: "root", items: &[ &Item { itemtype: ItemType::Callback { function: selectfoo, parameters: &[ Parameter::Mandatory { parametername: "a", help: Some("This is the help text for 'a'"), }, Parameter::Optional { parametername: "b", help: None, }, Parameter::Named { parametername: "verbose", help: None, }, Parameter::NamedValue { parametername: "level", argumentname: "INT", help: Some("Set the level of the dangle"), }, ], }, command: "foo", help: Some( "Makes a foo appear.

This is some extensive help text.

It contains multiple paragraphs and should be preceeded by the parameter list. ", ), }, &Item { itemtype: ItemType::Callback { function: selectbar, parameters: &[], }, command: "bar", help: Some("fandoggles a bar"), }, &Item { itemtype: ItemType::Menu(&Menu { label: "sub", items: &[ &Item { itemtype: ItemType::Callback { function: selectbaz, parameters: &[], }, command: "baz", help: Some("thingamobob a baz"), }, &Item { itemtype: ItemType::Callback { function: selectquux, parameters: &[], }, command: "quux", help: Some("maximum quux"), }, ], entry: Some(entersub), exit: Some(exitsub), }), command: "sub", help: Some("enter sub-menu"), }, ], entry: Some(enterroot), exit: Some(exit_root), };

```

Changelog

Unreleased changes

  • None

v0.3.2

  • Shortened help output.

v0.3.1

  • Updated crate metadata

v0.3.0

  • Parameter / Argument support
  • Re-worked help text system
  • Example uses pancurses
  • Remove use of fixed width (assumes a Western set with one byte per glyph)

v0.2.0

  • Add context to menu callback
  • Fix width of help text

v0.1.0

  • First release