From ed6ce958d5f3d5aa495d4314288b995fb7bb358c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 25 Jan 2015 13:35:38 +0100 Subject: vtcol.rs: add option to list available color schemes --- vtcol.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vtcol.rs b/vtcol.rs index acf8db7..f734525 100644 --- a/vtcol.rs +++ b/vtcol.rs @@ -6,6 +6,8 @@ extern crate getopts; #[derive(Show)] enum Scheme { Default, SolarizedDark, SolarizedLight } +extern { fn exit (code : libc::c_int) -> !; } + /* struct Job -- Runtime parameters. */ #[derive(Show)] @@ -24,6 +26,7 @@ impl Job { let this = argv[0].clone(); let opts = &[ getopts::optopt("s", "scheme", "predefined color scheme", "NAME"), + getopts::optflag("l", "list", "list available color schemes"), getopts::optflag("h", "help", "print this message") ]; let matches = match getopts::getopts(argv.tail(), opts) @@ -31,6 +34,10 @@ impl Job { Ok(m) => m, Err(f) => panic!(f.to_string()) }; + if matches.opt_present("l") { + Job::schemes(); + unsafe { exit(0) }; + }; let scheme = match matches.opt_str("s") { None => { Job::usage(&this, opts); @@ -61,6 +68,15 @@ impl Job { print!("{}", getopts::usage(brief.as_slice(), opts)); } + fn + schemes () + { + println!("Available color schemes:"); + println!(" · solarized_dark"); + println!(" · solarized_light"); + println!(" · default"); + } + } /* [impl Job] */ /* Rust appears to come with two wrappers for ``ioctl(2)``, but neither can be utilized for our -- cgit v1.2.3