From 451cb95ee29826538dc0efe0ec18ca6c16814f7d Mon Sep 17 00:00:00 2001 From: Ticki Date: Fri, 8 Apr 2016 11:00:02 +0200 Subject: [PATCH] Add colors example --- examples/colors.rs | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 examples/colors.rs diff --git a/examples/colors.rs b/examples/colors.rs new file mode 100644 index 0000000..a48833f --- /dev/null +++ b/examples/colors.rs @@ -0,0 +1,137 @@ +extern crate termion; + +use termion::{TermWrite, Color, Style}; +use std::io::{self, Write}; + +const LINE_NUM_BG: Color = Color::Grayscale(5); +const LINE_NUM_FG: Color = Color::Grayscale(18); +const ERROR_FG: Color = Color::Grayscale(17); +const INFO_LINE: &'static str = "│ "; + +fn main() { + let stdout = io::stdout(); + let mut stdout = stdout.lock(); + + stdout.color(Color::LightGreen).unwrap(); + stdout.write("—— src/test/ui/borrow-errors.rs at 82:18 ——\n".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(Color::Red).unwrap(); + stdout.style(Style::Bold).unwrap(); + stdout.write(b"error: ").unwrap(); + stdout.reset().unwrap(); + + stdout.style(Style::Bold).unwrap(); + stdout.write(b"two closures require unique access to `vec` at the same time").unwrap(); + stdout.reset().unwrap(); + + stdout.style(Style::Bold).unwrap(); + stdout.color(Color::Magenta).unwrap(); + stdout.write(b" [E0524]\n").unwrap(); + stdout.reset().unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"79 ").unwrap(); + stdout.reset().unwrap(); + + stdout.write(b" let append = |e| {\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(INFO_LINE.as_bytes()).unwrap(); + stdout.reset().unwrap(); + stdout.color(Color::Red).unwrap(); + stdout.write(" ━━━ ".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(ERROR_FG).unwrap(); + stdout.write(b"first closure is constructed here\n").unwrap(); + stdout.reset().unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"80 ").unwrap(); + stdout.reset().unwrap(); + + stdout.write(b" vec.push(e)\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(INFO_LINE.as_bytes()).unwrap(); + stdout.reset().unwrap(); + stdout.color(Color::Red).unwrap(); + stdout.write(" ━━━ ".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(ERROR_FG).unwrap(); + stdout.write(b"previous borrow occurs due to use of `vec` in closure\n").unwrap(); + stdout.reset().unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"81 ").unwrap(); + stdout.reset().unwrap(); + stdout.write(b" };\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"82 ").unwrap(); + stdout.reset().unwrap(); + stdout.write(b" let append = |e| {\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(INFO_LINE.as_bytes()).unwrap(); + stdout.reset().unwrap(); + stdout.color(Color::Red).unwrap(); + stdout.write(" ━━━ ".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(ERROR_FG).unwrap(); + stdout.write(b"second closure is constructed here\n").unwrap(); + stdout.reset().unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"83 ").unwrap(); + stdout.reset().unwrap(); + + stdout.write(b" vec.push(e)\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(INFO_LINE.as_bytes()).unwrap(); + stdout.reset().unwrap(); + stdout.color(Color::Red).unwrap(); + stdout.write(" ━━━ ".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(ERROR_FG).unwrap(); + stdout.write(b"borrow occurs due to use of `vec` in closure\n").unwrap(); + stdout.reset().unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"84 ").unwrap(); + stdout.reset().unwrap(); + stdout.write(b" };\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(b"85 ").unwrap(); + stdout.reset().unwrap(); + stdout.write(b" }\n").unwrap(); + + stdout.color(LINE_NUM_FG).unwrap(); + stdout.bg_color(LINE_NUM_BG).unwrap(); + stdout.write(INFO_LINE.as_bytes()).unwrap(); + stdout.reset().unwrap(); + stdout.color(Color::Red).unwrap(); + stdout.write(" ━ ".as_bytes()).unwrap(); + stdout.reset().unwrap(); + + stdout.color(ERROR_FG).unwrap(); + stdout.write(b"borrow from first closure ends here\n").unwrap(); + stdout.reset().unwrap(); +}