Skip to content

Commit 72ac494

Browse files
committed
Implement a faster input field and get rid of edtui
1 parent c1aa925 commit 72ac494

10 files changed

Lines changed: 244 additions & 947 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 592 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ git2 = "0.20.3"
1313
colored = "3"
1414
chrono = "0.4"
1515
rand = "0.9"
16-
edtui = "0.10.0"
1716
encoding_rs = "0.8.35"
1817
im = "15.1.0"
1918
indexmap = "2.12.1"

src/app/app.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ use std::{
2121
io,
2222
};
2323
#[rustfmt::skip]
24-
use edtui::{
25-
EditorEventHandler,
26-
EditorState
27-
};
28-
#[rustfmt::skip]
2924
use git2::{
3025
Repository
3126
};
@@ -50,7 +45,7 @@ use ratatui::{
5045
Span
5146
},
5247
};
53-
use crate::{core::stashes::Stashes, helpers::{copy::{STR_CREATE_BRANCH, STR_CREATE_COMMIT, STR_CREATE_TAG, STR_FIND_SHA}, heatmap::{DAYS, WEEKS}, keymap::{Command, KeyBinding}}};
48+
use crate::{app::input::TextInput, core::stashes::Stashes, helpers::{copy::{STR_CREATE_BRANCH, STR_CREATE_COMMIT, STR_CREATE_TAG, STR_FIND_SHA}, heatmap::{DAYS, WEEKS}, keymap::{Command, KeyBinding}}};
5449
#[rustfmt::skip]
5550
use crate::{
5651
app::{
@@ -105,7 +100,6 @@ use crate::{
105100
pub enum Viewport {
106101
Graph,
107102
Viewer,
108-
Editor,
109103
Splash,
110104
Settings
111105
}
@@ -208,10 +202,6 @@ pub struct App {
208202
pub settings_selected: usize,
209203
pub settings_selections: Vec<usize>,
210204

211-
// Editor
212-
pub file_editor: EditorState,
213-
pub file_editor_event_handler: EditorEventHandler,
214-
215205
// Inspector
216206
pub inspector_selected: usize,
217207
pub inspector_scroll: Cell<usize>,
@@ -231,8 +221,7 @@ pub struct App {
231221
pub modal_solo_selected: i32,
232222

233223
// Modal editor
234-
pub modal_editor: EditorState,
235-
pub modal_editor_event_handler: EditorEventHandler,
224+
pub modal_input: TextInput,
236225

237226
// Modal delete a branch
238227
pub modal_delete_branch_selected: i32,
@@ -297,9 +286,6 @@ impl App {
297286
Viewport::Viewer => {
298287
self.draw_viewer(frame);
299288
}
300-
Viewport::Editor => {
301-
self.draw_editor(frame);
302-
}
303289
Viewport::Splash => {
304290
self.draw_splash(frame);
305291
}

src/app/app_default.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ use ratatui::{
1818
}
1919
};
2020
#[rustfmt::skip]
21-
use edtui::{
22-
EditorEventHandler,
23-
EditorState
24-
};
25-
use crate::{core::stashes::Stashes, git::queries::helpers::commits_per_day, helpers::heatmap::build_heatmap};
21+
use crate::{app::input::TextInput, core::stashes::Stashes, git::queries::helpers::commits_per_day, helpers::heatmap::build_heatmap};
2622
#[rustfmt::skip]
2723
use crate::{
2824
app::{
@@ -157,10 +153,6 @@ impl Default for App {
157153
// Viewer
158154
viewer_selected: 0,
159155
viewer_scroll: 0.into(),
160-
161-
// Editor
162-
file_editor: EditorState::default(),
163-
file_editor_event_handler: EditorEventHandler::default(),
164156

165157
// Inspector
166158
inspector_selected: 0,
@@ -181,8 +173,7 @@ impl Default for App {
181173
modal_solo_selected: 0,
182174

183175
// Modal editor
184-
modal_editor: EditorState::default(),
185-
modal_editor_event_handler: EditorEventHandler::default(),
176+
modal_input: TextInput::default(),
186177

187178
// Modal delete branch
188179
modal_delete_branch_selected: 0,

src/app/app_draw_editor.rs

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/app/app_draw_modal_input.rs

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ use ratatui::{
2323
},
2424
};
2525
#[rustfmt::skip]
26-
use edtui::{
27-
EditorStatusLine,
28-
EditorTheme,
29-
EditorView,
30-
EditorMode
31-
};
32-
#[rustfmt::skip]
3326
use crate::app::app::{
3427
App
3528
};
@@ -38,103 +31,87 @@ impl App {
3831

3932
pub fn draw_modal_input(&mut self, frame: &mut Frame, title: &str) {
4033

34+
// Modal dimensions
4135
let length = 60;
42-
let height = 12;
36+
let height = 13;
37+
let fill = 7;
38+
39+
// Build the modal lines: title + empty padding + footer
40+
let mut lines: Vec<Line> = Vec::with_capacity(fill + 2);
4341

44-
let lines: Vec<Line> = vec![
45-
Line::from(vec![
46-
Span::styled(title, Style::default().fg(self.theme.COLOR_TEXT)),
47-
]),
48-
Line::from(""),
49-
Line::from(""),
50-
Line::from(""),
51-
Line::from(""),
52-
Line::from(""),
53-
Line::from(""),
54-
Line::from(vec![
55-
Span::styled(if self.modal_editor.mode == EditorMode::Normal {"(enter)".to_string()} else { "enter".to_string() }, Style::default().fg(if self.modal_editor.mode == EditorMode::Normal { self.theme.COLOR_GREY_500 } else { self.theme.COLOR_GREY_600 })),
56-
]),
57-
];
58-
42+
// Title line
43+
lines.push(Line::from(Span::styled(title, Style::default().fg(self.theme.COLOR_TEXT))));
44+
45+
// Vertical padding
46+
lines.extend(vec![Line::default(); fill]);
47+
48+
// Footer line
49+
lines.push(Line::from(Span::styled("(enter)".to_string(), Style::default().fg(self.theme.COLOR_GREY_500))));
50+
51+
// Render background block behind the modal
5952
let bg_block = Block::default().style(Style::default().fg(self.theme.COLOR_BORDER));
6053
bg_block.render(frame.area(), frame.buffer_mut());
6154

62-
// Modal size (smaller than area)
55+
// Compute modal area (centered and smaller than the full frame)
6356
let modal_width = length.min((frame.area().width as f32 * 0.8) as usize) as u16;
6457
let modal_height = height.min((frame.area().height as f32 * 0.6) as usize) as u16;
6558
let x = frame.area().x + (frame.area().width - modal_width) / 2;
6659
let y = frame.area().y + (frame.area().height - modal_height) / 2;
6760
let modal_area = Rect::new(x, y, modal_width, modal_height);
6861

62+
// Clear the modal area
6963
frame.render_widget(Clear, modal_area);
7064

71-
// Modal block
65+
// Render the main modal block with rounded borders and "esc" title
7266
let modal_block = Block::default()
7367
.borders(Borders::ALL)
7468
.border_style(Style::default().fg(self.theme.COLOR_GREY_600))
75-
.title(Span::styled(if self.modal_editor.mode == EditorMode::Normal {" (esc) "} else { "─ esc ─" }, Style::default().fg(if self.modal_editor.mode == EditorMode::Normal { self.theme.COLOR_GREY_500 } else { self.theme.COLOR_GREY_600 })))
69+
.title(Span::styled(" (esc) ", Style::default().fg(self.theme.COLOR_GREY_500)))
7670
.title_alignment(Alignment::Right)
77-
.padding(Padding { left: 3, right: 3, top: 1, bottom: 1})
71+
.padding(Padding { left: 3, right: 3, top: 1, bottom: 1 })
7872
.border_type(ratatui::widgets::BorderType::Rounded);
7973

80-
// Modal content
81-
let paragraph = Paragraph::new(Text::from(lines))
74+
// Render the text content (title + instructions)
75+
Paragraph::new(Text::from(lines))
8276
.block(modal_block)
83-
.alignment(Alignment::Center);
84-
85-
// Render the paragraph
86-
paragraph.render(modal_area, frame.buffer_mut());
87-
88-
let custom_theme = EditorTheme {
89-
base: Style::default().fg(self.theme.COLOR_GREY_500),
90-
cursor_style: Style::default().bg(self.theme.COLOR_TEXT),
91-
selection_style: Style::default(),
92-
block: Some(
93-
Block::default()
94-
.padding(Padding { left: 1, right: 1, top: 0, bottom: 0})
95-
.borders(Borders::TOP)
96-
.border_type(ratatui::widgets::BorderType::Rounded)
97-
.border_style(Style::default().fg(self.theme.COLOR_GREY_800))),
98-
status_line: Some(EditorStatusLine::default()
99-
.style_text(Style::default().fg(self.theme.COLOR_TEXT))
100-
.style_line(Style::default().fg(self.theme.COLOR_GREY_800))
101-
.align_left(true))
102-
};
103-
let editor_view = EditorView::new(&mut self.modal_editor).theme(custom_theme);
77+
.alignment(Alignment::Center)
78+
.render(modal_area, frame.buffer_mut());
10479

80+
// Input field area
10581
let input_area = Rect {
10682
x: modal_area.x + modal_area.width / 2 - 29,
10783
y: modal_area.y + 4,
10884
width: 58,
109-
height: 4,
85+
height: 5,
11086
};
11187

112-
// Render the editor in the modal area
113-
editor_view.render(input_area, frame.buffer_mut());
114-
115-
// Modal block
116-
Block::default()
117-
.borders(Borders::TOP)
118-
.border_style(Style::default().fg(self.theme.COLOR_GREY_800))
119-
.border_type(ratatui::widgets::BorderType::Rounded)
120-
.render(Rect {
121-
x: modal_area.x + 1,
122-
y: modal_area.y + 7,
123-
width: 2,
124-
height: 1,
125-
}, frame.buffer_mut());
88+
// Determine visible portion of input text
89+
let visible_width = input_area.width.saturating_sub(1) as usize;
90+
self.modal_input.set_max_width(visible_width);
91+
let start: usize = *self.modal_input.scroll();
92+
let end: usize = (start + visible_width).min(self.modal_input.value().len());
93+
let visible_text = &self.modal_input.value()[start..end];
94+
95+
// Calculate cursor x position relative to input area
96+
let cursor_x = (self.modal_input.cursor() - self.modal_input.scroll()) as u16 + 1;
97+
98+
// Top divider with input value
99+
frame.render_widget(Paragraph::new(Line::from(Span::styled(visible_text, Style::default().fg(self.theme.COLOR_TEXT)))).block(
100+
Block::default()
101+
.padding(ratatui::widgets::Padding {left: 1, right: 1, top: 1, bottom: 0})
102+
.borders(Borders::TOP)
103+
.border_style(Style::default()
104+
.fg(self.theme.COLOR_GREY_800))
105+
), input_area);
126106

127-
// Modal block
107+
// Cursor
108+
frame.set_cursor_position((input_area.x + cursor_x, input_area.y + 2));
109+
110+
// Bottom divider
128111
Block::default()
129112
.borders(Borders::TOP)
130113
.border_style(Style::default().fg(self.theme.COLOR_GREY_800))
131114
.border_type(ratatui::widgets::BorderType::Rounded)
132-
.render(Rect {
133-
x: modal_area.x + 11,
134-
y: modal_area.y + 7,
135-
width: modal_width - 12,
136-
height: 1,
137-
}, frame.buffer_mut());
138-
115+
.render(Rect { x: modal_area.x + 1, y: modal_area.y + 8, width: modal_width - 2, height: 1}, frame.buffer_mut());
139116
}
140117
}

0 commit comments

Comments
 (0)