From 9722d01b078dbf554431a3af3767012fce341b95 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 25 Jul 2024 16:39:49 +0200 Subject: editor add syntax highlighting using treesitter --- src/widgets/luaeditor/theme.rs | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/widgets/luaeditor/theme.rs (limited to 'src/widgets/luaeditor/theme.rs') diff --git a/src/widgets/luaeditor/theme.rs b/src/widgets/luaeditor/theme.rs new file mode 100644 index 0000000..2af8534 --- /dev/null +++ b/src/widgets/luaeditor/theme.rs @@ -0,0 +1,43 @@ +use ratatui::{style::{Color, Stylize}, text::Span}; +use tree_sitter_highlight::Highlight; + + +static HIGHLIGHT_THEME: [Color; 29] = [ + Color::White, // attribute + Color::White, // boolean + Color::DarkGray, // comment + Color::LightYellow, // conditional + Color::White, // constant + Color::White, // constant.builtin + Color::White, // constructor + Color::White, // field + Color::White, // function + Color::White, // function.builtin + Color::White, // function.call + Color::Yellow, // keyword + Color::LightYellow, // keyword.function + Color::White, // keyword.operator + Color::LightYellow, // keyword.return + Color::White, // label + Color::White, // method + Color::White, // method.call + Color::Blue, // number + Color::Gray, // operator + Color::White, // parameter + Color::White, // preproc + Color::Gray, // punctuation.bracket + Color::Gray, // punctuation.delimiter + Color::LightYellow, // repeat + Color::LightGreen, // string + Color::Yellow, // string.escape + Color::Gray, // variable + Color::White, // variable.builtin +]; + +pub fn theme_highlight_group(hl: Option, span: Span) -> Span { + if let Some(hl) = hl { + span.fg(HIGHLIGHT_THEME[hl.0]) + } else { + span + } +} -- cgit v1.2.3-70-g09d2