From 30f95efebb4ce102cdae25e0c837709f830a106d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 3 Apr 2013 01:01:47 -0500 Subject: add a few more examples --- Makefile | 2 +- test/attrs.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/password.rs | 9 +++++++++ test/tput.rs | 10 ++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/attrs.rs create mode 100644 test/password.rs create mode 100644 test/tput.rs diff --git a/Makefile b/Makefile index 9136f47..152fe5f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ RUSTC = rustc MAIN_SOURCE = src/term.rs OTHER_SOURCES = src/ios.rs src/info.rs src/util.rs src/trie.rs -TESTS = bin/termios bin/termios2 bin/termios3 bin/rl +TESTS = bin/termios bin/termios2 bin/termios3 bin/rl bin/password bin/attrs bin/tput all: build tests diff --git a/test/attrs.rs b/test/attrs.rs new file mode 100644 index 0000000..6d8086b --- /dev/null +++ b/test/attrs.rs @@ -0,0 +1,46 @@ +extern mod term; + +fn main () { + term::info::init(); + print(term::info::exit_attribute_mode()); + loop { + print("Attribute? "); + + let attr = io::stdin().read_line(); + + if attr.starts_with("fg:") || attr.starts_with("bg:") { + let set = if attr.starts_with("fg:") { + |c| { print(term::info::set_a_foreground(c)) } + } + else { + |c| { print(term::info::set_a_background(c)) } + }; + + match attr.slice(3, attr.len()) { + &"black" => set(term::info::ColorBlack), + &"red" => set(term::info::ColorRed), + &"green" => set(term::info::ColorGreen), + &"yellow" => set(term::info::ColorYellow), + &"blue" => set(term::info::ColorBlue), + &"magenta" => set(term::info::ColorMagenta), + &"cyan" => set(term::info::ColorCyan), + &"white" => set(term::info::ColorWhite), + _ => (), + } + } + else { + match attr { + ~"underline" => print(term::info::enter_underline_mode()), + ~"standout" => print(term::info::enter_standout_mode()), + ~"reverse" => print(term::info::enter_reverse_mode()), + ~"bold" => print(term::info::enter_bold_mode()), + ~"blink" => print(term::info::enter_blink_mode()), + ~"reset" => print(term::info::exit_attribute_mode()), + ~"reset_color" => print(term::info::orig_pair()), + ~"" => break, + _ => (), + } + } + } + print(term::info::exit_attribute_mode()); +} diff --git a/test/password.rs b/test/password.rs new file mode 100644 index 0000000..2900c51 --- /dev/null +++ b/test/password.rs @@ -0,0 +1,9 @@ +extern mod term; + +fn main () { + print("Enter password: "); + term::ios::echo(false); + let pass = io::stdin().read_line(); + term::ios::echo(true); + println(fmt!("\nYour password is: %s", pass)); +} diff --git a/test/tput.rs b/test/tput.rs new file mode 100644 index 0000000..b2cfc59 --- /dev/null +++ b/test/tput.rs @@ -0,0 +1,10 @@ +extern mod term; + +fn main () { + if os::args().len() < 2 { + fail!(~"usage: tput "); + } + + term::info::init(); + print(term::info::escape(os::args()[1])); +} -- cgit v1.2.3