diff --git a/src/render.rs b/src/render.rs index c09c349..da6f50a 100644 --- a/src/render.rs +++ b/src/render.rs @@ -31,6 +31,57 @@ pub struct GlyphAtlas { metrics: GlyphMetrics, } +struct ColorRGB { + red: u8, + green: u8, + blue: u8, +} + +impl ColorRGB { + fn new(red: u8, green: u8, blue: u8) -> ColorRGB { + ColorRGB { red, green, blue } + } +} + +#[allow(dead_code)] +enum Colors { + Background, + Foreground, + Error, + Warning, + FindBg, + StdFunction, + Comment, + Keyword, + Number, + Operator, + Preprocessor, + SelectionBg, + SelectionFg, + String, +} + +impl Colors { + fn color(&self) -> ColorRGB { + match self { + Colors::Background => ColorRGB::new( 32, 32, 32), + Colors::Foreground => ColorRGB::new(255, 255, 255), + Colors::Error => ColorRGB::new(255, 0, 0), + Colors::Warning => ColorRGB::new(255, 170, 0), + Colors::FindBg => ColorRGB::new(246, 185, 63), + Colors::StdFunction => ColorRGB::new(170, 255, 255), + Colors::Comment => ColorRGB::new( 0, 255, 0), + Colors::Keyword => ColorRGB::new( 0, 170, 255), + Colors::Number => ColorRGB::new( 85, 255, 255), + Colors::Operator => ColorRGB::new(255, 85, 0), + Colors::Preprocessor => ColorRGB::new(127, 0, 0), + Colors::SelectionBg => ColorRGB::new(110, 161, 241), + Colors::SelectionFg => ColorRGB::new(255, 255, 255), + Colors::String => ColorRGB::new(255, 85, 255), + } + } +} + pub fn generate_glyph_data() -> Result { // Retrieve font data from file // TODO: Get crate path instead of working directory path @@ -144,12 +195,15 @@ pub fn draw_everything(canvas: &mut Canvas, let window_size = canvas.output_size()?; let text_offset = Point::new(10, 10); + let bg_color = Colors::Background.color(); + let fg_color = Colors::Foreground.color(); + // Draw background - canvas.set_draw_color(Color::RGB(32, 32, 32)); + canvas.set_draw_color(Color::RGB(bg_color.red, bg_color.green, bg_color.blue)); canvas.clear(); // Draw text - canvas.set_draw_color(Color::RGB(240, 240, 240)); + canvas.set_draw_color(Color::RGB(fg_color.red, fg_color.green, fg_color.blue)); let fb_text = draw_text(&glyph_atlas, buffer, text_offset); canvas.draw_points(&fb_text[..])?; diff --git a/src/syntax-highlight.rs b/src/syntax-highlight.rs new file mode 100644 index 0000000..a47e4fb --- /dev/null +++ b/src/syntax-highlight.rs @@ -0,0 +1,70 @@ +pub enum Token { + ILLEGAL, + EOF, + IDENT(Vec), + INT(Vec), + ASSIGN(char), + PLUS(char), + COMMA(char), + SEMICOLON(char), + LPAREN(char), + RPAREN(char), + LBRACE(char), + RBRACE(char), + FUNCTION, + LET, + TRUE, + FALSE, + IF, + ELSE, + RETURN, + MINUS(char), + BANG(char), + ASTERISK(char), + SLASH(char), + LT(char), + GT(char) +} + +fn find_keyword(input: &str) { + match input { + "async" => {}, + "await" => {}, + "as" => {}, + "break" => {}, + "const" => {}, + "continue" => {}, + "crate" => {}, + "dyn" => {}, + "else" => {}, + "enum" => {}, + "extern" => {}, + "false" => {}, + "fn" => {}, + "for" => {}, + "if" => {}, + "impl" => {}, + "in" => {}, + "let" => {}, + "loop" => {}, + "match" => {}, + "mod" => {}, + "move" => {}, + "mut" => {}, + "pub" => {}, + "ref" => {}, + "return" => {}, + "self" => {}, + "Self" => {}, + "static" => {}, + "struct" => {}, + "super" => {}, + "trait" => {}, + "true" => {}, + "type" => {}, + "unsafe" => {}, + "use" => {}, + "where" => {}, + "while" => {}, + } +}