Make syntax_to_color a standalone function

This commit is contained in:
Timothy Warren 2019-09-19 12:25:36 -04:00
parent 92155aa762
commit 4d1560717e

View File

@ -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) { fn select_syntax_highlight(&mut self) {
if self.filename.is_empty() { if self.filename.is_empty() {
return; return;
@ -826,7 +811,7 @@ impl Editor {
return None; return None;
} }
_ => (), _ => (),
} },
Function(_) => (), Function(_) => (),
OtherKey(c) => { OtherKey(c) => {
self.insert_char(c); self.insert_char(c);
@ -971,7 +956,7 @@ impl Editor {
} }
self.append_out_char(ch); self.append_out_char(ch);
} else { } 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 { if color != current_color {
current_color = color; current_color = color;
let code = format!("\x1b[{}m", color); let code = format!("\x1b[{}m", color);
@ -1567,7 +1552,7 @@ fn get_syntax_db() -> Vec<Syntax> {
/// Convert Ctrl+letter chord to their /// Convert Ctrl+letter chord to their
/// letter equivalent /// letter equivalent
pub fn ctrl_to_letter(c: char) -> char { fn ctrl_to_letter(c: char) -> char {
let key = c as u8; let key = c as u8;
if (!c.is_ascii_control()) || c == '\x7f' { if (!c.is_ascii_control()) || c == '\x7f' {
@ -1596,6 +1581,23 @@ fn is_separator(input_char: char) -> bool {
false 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 /// 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. /// string or vector to prevent panics on invalid access.
/// ///