1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#![no_std] extern crate libw; use libw::*; extern crate alloc; use alloc::string::ToString; const XTERM_ESCAPE: &'static str = "\u{001b}"; pub fn clear() { print("\u{001b}c"); } pub fn dimensions() -> (u32, u32) { let mut rows = 0; let mut cols = 0; let vars = environment_variables(); for v in vars { if v.name == "LINES" { rows = v.value.parse::<u32>().unwrap() } if v.name == "COLUMNS" { cols = v.value.parse::<u32>().unwrap() } } (rows, cols) } pub fn set_cursor_position(row: u32, col: u32) { let mut cmd = XTERM_ESCAPE.to_string(); cmd.push_str("["); cmd.push_str(&row.to_string()); cmd.push_str(";"); cmd.push_str(&col.to_string()); cmd.push_str("f"); print(&cmd); } pub fn save_cursor_position() { print("\u{001b}[s"); } pub fn restore_cursor_position() { print("\u{001b}[u"); } pub fn set_foreground_color(r: u8, g: u8, b: u8) { let mut cmd = XTERM_ESCAPE.to_string(); cmd.push_str("[38;2;"); cmd.push_str(&r.to_string()); cmd.push_str(";"); cmd.push_str(&g.to_string()); cmd.push_str(";"); cmd.push_str(&b.to_string()); cmd.push_str("m"); print(&cmd); } pub fn set_background_color(r: u8, g: u8, b: u8) { let mut cmd = XTERM_ESCAPE.to_string(); cmd.push_str("[48;2;"); cmd.push_str(&r.to_string()); cmd.push_str(";"); cmd.push_str(&g.to_string()); cmd.push_str(";"); cmd.push_str(&b.to_string()); cmd.push_str("m"); print(&cmd); } pub fn reset_color() { print("\u{001b}[0m"); } pub fn bold() { print("\u{001b}[1m"); } pub fn italic() { print("\u{001b}[3m"); } pub fn slow_blink() { print("\u{001b}[5m"); } pub fn fast_blink() { print("\u{001b}[6m"); } pub fn underline() { print("\u{001b}[4m"); }