Skip to content

Commit 9c66faf

Browse files
adjust vim emulation
1 parent 66ed756 commit 9c66faf

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/components/editor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ impl<'a> Component for Editor<'a> {
108108

109109
fn draw(&mut self, f: &mut Frame<'_>, area: Rect, app_state: &AppState) -> Result<()> {
110110
let focused = app_state.focus == Focus::Editor;
111-
let block =
112-
self.vim_state.mode.block().border_style(if focused { Style::new().green() } else { Style::new().dim() });
111+
let block = self.vim_state.mode.block().title("query").border_style(if focused {
112+
Style::new().green()
113+
} else {
114+
Style::new().dim()
115+
});
113116

114117
self.textarea.set_block(block);
115118
self.textarea.set_line_number_style(if focused { Style::default().fg(Color::Yellow) } else { Style::new().dim() });

src/components/menu.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ impl Component for Menu {
359359
f.render_stateful_widget(list, layout[layout_index], &mut self.list_state);
360360
let vertical_scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
361361
.symbols(scrollbar::VERTICAL)
362-
.style(Style::default().fg(if focused && !self.search_focused && self.menu_focus == MenuFocus::Tables {
363-
Color::Green
362+
.style(if focused && !self.search_focused && self.menu_focus == MenuFocus::Tables {
363+
Style::default().fg(Color::Green)
364364
} else {
365-
Color::DarkGray
366-
}));
365+
Style::default()
366+
});
367367
let mut vertical_scrollbar_state =
368368
ScrollbarState::new(table_length.saturating_sub(available_height)).position(self.list_state.offset());
369369
f.render_stateful_widget(vertical_scrollbar, block_margin, &mut vertical_scrollbar_state);

src/vim.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// vim emulation for tui_textarea. from:
1+
// vim emulation for tui_textarea. based on:
22
// https://github.com/rhysd/tui-textarea/blob/main/examples/vim.rs
33
use std::{env, fmt, fs, io, io::BufRead};
44

@@ -9,6 +9,7 @@ use crossterm::{
99
use ratatui::{
1010
backend::CrosstermBackend,
1111
style::{Color, Modifier, Style},
12+
text::Line,
1213
widgets::{Block, Borders},
1314
Terminal,
1415
};
@@ -26,13 +27,13 @@ pub enum Mode {
2627
impl Mode {
2728
pub fn block<'a>(&self) -> Block<'a> {
2829
let help = match self {
29-
Self::Normal => "type q to quit, type i to enter insert mode",
30+
Self::Normal => "type i to enter insert mode",
3031
Self::Insert => "type Esc to back to normal mode",
3132
Self::Visual => "type y to yank, type d to delete, type Esc to back to normal mode",
3233
Self::Operator(_) => "move cursor to apply operator",
3334
};
3435
let title = format!("{} MODE ({})", self, help);
35-
Block::default().borders(Borders::ALL).title(title)
36+
Block::default().borders(Borders::ALL).title_bottom(Line::from(title).right_aligned())
3637
}
3738

3839
pub fn cursor_style(&self) -> Style {
@@ -42,7 +43,7 @@ impl Mode {
4243
Self::Visual => Color::LightYellow,
4344
Self::Operator(_) => Color::LightGreen,
4445
};
45-
Style::default().fg(color).add_modifier(Modifier::REVERSED)
46+
Style::default().add_modifier(Modifier::SLOW_BLINK)
4647
}
4748
}
4849

@@ -93,6 +94,7 @@ impl Vim {
9394
Input { key: Key::Char('k'), .. } => textarea.move_cursor(CursorMove::Up),
9495
Input { key: Key::Char('l'), .. } => textarea.move_cursor(CursorMove::Forward),
9596
Input { key: Key::Char('w'), .. } => textarea.move_cursor(CursorMove::WordForward),
97+
Input { key: Key::Char('e'), ctrl: false, .. } => textarea.move_cursor(CursorMove::WordForward),
9698
Input { key: Key::Char('b'), ctrl: false, .. } => textarea.move_cursor(CursorMove::WordBack),
9799
Input { key: Key::Char('^'), .. } => textarea.move_cursor(CursorMove::Head),
98100
Input { key: Key::Char('$'), .. } => textarea.move_cursor(CursorMove::End),
@@ -203,6 +205,10 @@ impl Vim {
203205
textarea.cut();
204206
return Transition::Mode(Mode::Insert);
205207
},
208+
Input { key: Key::Esc, .. } => {
209+
textarea.cancel_selection();
210+
return Transition::Mode(Mode::Normal);
211+
},
206212
input => return Transition::Pending(input),
207213
}
208214

0 commit comments

Comments
 (0)