aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-04-03 01:01:47 -0500
committerJesse Luehrs <doy@tozt.net>2013-04-03 01:01:47 -0500
commit30f95efebb4ce102cdae25e0c837709f830a106d (patch)
tree1631ea329c98910b0db5a5c01ce402d086979772
parent0867d1894ce27b06e7ffce7ef3d52c8048e359d1 (diff)
downloadrust-term-30f95efebb4ce102cdae25e0c837709f830a106d.tar.gz
rust-term-30f95efebb4ce102cdae25e0c837709f830a106d.zip
add a few more examples
-rw-r--r--Makefile2
-rw-r--r--test/attrs.rs46
-rw-r--r--test/password.rs9
-rw-r--r--test/tput.rs10
4 files changed, 66 insertions, 1 deletions
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 <terminfo capability>");
+ }
+
+ term::info::init();
+ print(term::info::escape(os::args()[1]));
+}