summaryrefslogtreecommitdiff
path: root/src/widgets/luaeditor/mod.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 20:16:54 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 20:16:54 +0200
commit595bcac243cb9cdd87e7484ab102c86f3235db8a (patch)
treec89c275b175933efc59e9cba68aff607d489a8e2 /src/widgets/luaeditor/mod.rs
parentde9ad07b2a4737713f1473641fe195d7e3023928 (diff)
add editor theme
Diffstat (limited to 'src/widgets/luaeditor/mod.rs')
-rw-r--r--src/widgets/luaeditor/mod.rs57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/widgets/luaeditor/mod.rs b/src/widgets/luaeditor/mod.rs
index 0bcffc8..c777190 100644
--- a/src/widgets/luaeditor/mod.rs
+++ b/src/widgets/luaeditor/mod.rs
@@ -1,9 +1,16 @@
use ratatui::{
- crossterm::event::{KeyCode, KeyEvent, KeyModifiers}, text::{ToLine, ToSpan}, widgets::Widget
+ crossterm::event::{KeyCode, KeyEvent, KeyModifiers},
+ layout::Rect,
+ text::{ToLine, ToSpan},
+ widgets::{Paragraph, Widget},
};
use tree_sitter_highlight::HighlightConfiguration;
-use crate::{state::{editor::EditorState, window::Window, GlobalState}, tuicursor::TuiCursor};
+use crate::{
+ config::GlobalConfig,
+ state::{editor::EditorState, window::Window, GlobalState},
+ tuicursor::TuiCursor,
+};
use crate::{cursor::CursorMove, lua};
use super::statusbar::StatusBar;
@@ -87,7 +94,10 @@ impl LuaEditor {
let nr_width = (buffer.lines().len().to_string().len() + 1).max(4) as u16;
Some(TuiCursor {
- position: (buffer.cursor().y() as u16, buffer.cursor().x() as u16 + nr_width),
+ position: (
+ buffer.cursor().y() as u16,
+ buffer.cursor().x() as u16 + nr_width,
+ ),
style: ratatui::crossterm::cursor::SetCursorStyle::SteadyBar,
})
}
@@ -101,6 +111,9 @@ impl Widget for &mut LuaEditor {
let state = GlobalState::instance();
let buffer = &state.editor.buffer;
+ let config = GlobalConfig::instance();
+ let theme = &config.theme.editor;
+
self.bar.render(area, buf);
let inner_area = self.bar.area(area);
@@ -114,6 +127,28 @@ impl Widget for &mut LuaEditor {
let mut span_area = text_area;
let mut current_line = 0;
+ theme
+ .background
+ .get((), &lua::get())
+ .unwrap_or_default()
+ .apply(Paragraph::default())
+ .render(area, buf);
+
+ theme
+ .cursor_line
+ .get((), &lua::get())
+ .unwrap_or_default()
+ .apply(Paragraph::default())
+ .render(
+ Rect::new(
+ text_area.x,
+ text_area.y + buffer.cursor().y() as u16,
+ text_area.width,
+ 1,
+ ),
+ buf,
+ );
+
for (hl, group) in highlights.iter() {
if *group == "\n" {
if current_line >= self.scroll {
@@ -127,7 +162,7 @@ impl Widget for &mut LuaEditor {
let span = group.to_span();
if inner_area.contains(span_area.into()) {
- theme::theme_highlight_group(*hl, span).render(span_area, buf);
+ theme.highlight.highlight(*hl, span).render(span_area, buf);
}
span_area.x += group.len() as u16;
@@ -137,7 +172,7 @@ impl Widget for &mut LuaEditor {
for i in self.scroll..buffer.lines().len() {
let mut nr_area = span_area;
nr_area.x = inner_area.x;
- nr_area.width = nr_width - 1;
+ nr_area.width = nr_width;
nr_area.y = inner_area.y + (i - self.scroll) as u16;
nr_area.height = 1;
@@ -145,7 +180,17 @@ impl Widget for &mut LuaEditor {
break;
}
- (i + 1).to_line().right_aligned().render(nr_area, buf);
+ if buffer.cursor().y() == i {
+ theme
+ .active_line_number
+ .get((), &lua::get())
+ .unwrap_or_default()
+ } else {
+ theme.line_number.get((), &lua::get()).unwrap_or_default()
+ }
+ .apply(((i + 1).to_string() + " ").to_line())
+ .right_aligned()
+ .render(nr_area, buf);
}
}
}