From 4d1560717eb71ad3c1a2917e73471512f183e369 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 19 Sep 2019 12:25:36 -0400 Subject: [PATCH] Make syntax_to_color a standalone function --- src/editor.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index af96328..32afa5b 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -624,21 +624,6 @@ impl Editor { } } - fn syntax_to_color(syntax_type: Highlight) -> i32 { - use Highlight::*; - - match syntax_type { - Keyword1 => 33, // Yellow - Keyword2 => 32, // Green - LineComment => 36, // Cyan - MultiLineComment => 90, // Bright Black - Normal => 37, // White - Number => 31, // Red - SearchMatch => 7, // Reverse! - String => 35, // Magenta - } - } - fn select_syntax_highlight(&mut self) { if self.filename.is_empty() { return; @@ -826,7 +811,7 @@ impl Editor { return None; } _ => (), - } + }, Function(_) => (), OtherKey(c) => { self.insert_char(c); @@ -971,7 +956,7 @@ impl Editor { } self.append_out_char(ch); } else { - let color = Self::syntax_to_color(self.rows[file_row].highlight[x]); + let color = syntax_to_color(self.rows[file_row].highlight[x]); if color != current_color { current_color = color; let code = format!("\x1b[{}m", color); @@ -1567,7 +1552,7 @@ fn get_syntax_db() -> Vec { /// Convert Ctrl+letter chord to their /// letter equivalent -pub fn ctrl_to_letter(c: char) -> char { +fn ctrl_to_letter(c: char) -> char { let key = c as u8; if (!c.is_ascii_control()) || c == '\x7f' { @@ -1596,6 +1581,23 @@ fn is_separator(input_char: char) -> bool { false } +/// Get the highlight color escape sequence for +/// the type of syntax +fn syntax_to_color(syntax_type: Highlight) -> i32 { + use Highlight::*; + + match syntax_type { + Keyword1 => 33, // Yellow + Keyword2 => 32, // Green + LineComment => 36, // Cyan + MultiLineComment => 90, // Bright Black + Normal => 37, // White + Number => 31, // Red + SearchMatch => 7, // Reverse! + String => 35, // Magenta + } +} + /// Get a range for a slice of a string or vector, checking the length of the /// string or vector to prevent panics on invalid access. ///