From d19a5f4c2f691912ea33c36e07ec67b60172b9fc Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 15 Sep 2020 16:01:57 -0500 Subject: [PATCH] add a few more ansi escape sequences (#2553) --- crates/nu-cli/src/commands/char_.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/nu-cli/src/commands/char_.rs b/crates/nu-cli/src/commands/char_.rs index d26184eab3..ccda668f4e 100644 --- a/crates/nu-cli/src/commands/char_.rs +++ b/crates/nu-cli/src/commands/char_.rs @@ -105,6 +105,24 @@ fn str_to_character(s: &str) -> Option { "haze" => Some("\x1b[33m\u{2591}\x1b[0m".to_string()), // Yellow ░ "snow" => Some("\x1b[37;1m\u{2744}\x1b[0m".to_string()), // White Bold ❄ "thunderstorm" => Some("\x1b[33;1m\u{26a1}\x1b[0m".to_string()), // Yellow Bold ⚡ + + // Reference for ansi codes https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 + // Another good reference http://ascii-table.com/ansi-escape-sequences.php + + // For setting title like `echo [$(char title) $(pwd) $(char bel)] | str collect` + "title" => Some("\x1b]2;".to_string()), // ESC]2; xterm sets window title + "bel" => Some('\x07'.to_string()), // Terminal Bell + "backspace" => Some('\x08'.to_string()), // Backspace + + // Ansi Erase Sequences + "clear_screen" => Some("\x1b[J".to_string()), // clears the screen + "clear_screen_from_cursor_to_end" => Some("\x1b[0J".to_string()), // clears from cursor until end of screen + "clear_screen_from_cursor_to_beginning" => Some("\x1b[1J".to_string()), // clears from cursor to beginning of screen + "cls" | "clear_entire_screen" => Some("\x1b[2J".to_string()), // clears the entire screen + "erase_line" => Some("\x1b[K".to_string()), // clears the current line + "erase_line_from_cursor_to_end" => Some("\x1b[0K".to_string()), // clears from cursor to end of line + "erase_line_from_cursor_to_beginning" => Some("\x1b[1K".to_string()), // clears from cursor to start of line + "erase_entire_line" => Some("\x1b[2K".to_string()), // clears entire line _ => None, } }