1
- // vim emulation for tui_textarea. from :
1
+ // vim emulation for tui_textarea. based on :
2
2
// https://github.com/rhysd/tui-textarea/blob/main/examples/vim.rs
3
3
use std:: { env, fmt, fs, io, io:: BufRead } ;
4
4
@@ -9,6 +9,7 @@ use crossterm::{
9
9
use ratatui:: {
10
10
backend:: CrosstermBackend ,
11
11
style:: { Color , Modifier , Style } ,
12
+ text:: Line ,
12
13
widgets:: { Block , Borders } ,
13
14
Terminal ,
14
15
} ;
@@ -26,13 +27,13 @@ pub enum Mode {
26
27
impl Mode {
27
28
pub fn block < ' a > ( & self ) -> Block < ' a > {
28
29
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" ,
30
31
Self :: Insert => "type Esc to back to normal mode" ,
31
32
Self :: Visual => "type y to yank, type d to delete, type Esc to back to normal mode" ,
32
33
Self :: Operator ( _) => "move cursor to apply operator" ,
33
34
} ;
34
35
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 ( ) )
36
37
}
37
38
38
39
pub fn cursor_style ( & self ) -> Style {
@@ -42,7 +43,7 @@ impl Mode {
42
43
Self :: Visual => Color :: LightYellow ,
43
44
Self :: Operator ( _) => Color :: LightGreen ,
44
45
} ;
45
- Style :: default ( ) . fg ( color ) . add_modifier ( Modifier :: REVERSED )
46
+ Style :: default ( ) . add_modifier ( Modifier :: SLOW_BLINK )
46
47
}
47
48
}
48
49
@@ -93,6 +94,7 @@ impl Vim {
93
94
Input { key : Key :: Char ( 'k' ) , .. } => textarea. move_cursor ( CursorMove :: Up ) ,
94
95
Input { key : Key :: Char ( 'l' ) , .. } => textarea. move_cursor ( CursorMove :: Forward ) ,
95
96
Input { key : Key :: Char ( 'w' ) , .. } => textarea. move_cursor ( CursorMove :: WordForward ) ,
97
+ Input { key : Key :: Char ( 'e' ) , ctrl : false , .. } => textarea. move_cursor ( CursorMove :: WordForward ) ,
96
98
Input { key : Key :: Char ( 'b' ) , ctrl : false , .. } => textarea. move_cursor ( CursorMove :: WordBack ) ,
97
99
Input { key : Key :: Char ( '^' ) , .. } => textarea. move_cursor ( CursorMove :: Head ) ,
98
100
Input { key : Key :: Char ( '$' ) , .. } => textarea. move_cursor ( CursorMove :: End ) ,
@@ -203,6 +205,10 @@ impl Vim {
203
205
textarea. cut ( ) ;
204
206
return Transition :: Mode ( Mode :: Insert ) ;
205
207
} ,
208
+ Input { key : Key :: Esc , .. } => {
209
+ textarea. cancel_selection ( ) ;
210
+ return Transition :: Mode ( Mode :: Normal ) ;
211
+ } ,
206
212
input => return Transition :: Pending ( input) ,
207
213
}
208
214
0 commit comments