@@ -8,7 +8,7 @@ use crossterm::{
8
8
} ;
9
9
use ratatui:: {
10
10
backend:: CrosstermBackend ,
11
- style:: { Color , Modifier , Style } ,
11
+ style:: { Color , Modifier , Style , Stylize } ,
12
12
text:: Line ,
13
13
widgets:: { Block , Borders } ,
14
14
Terminal ,
@@ -21,6 +21,7 @@ pub enum Mode {
21
21
Normal ,
22
22
Insert ,
23
23
Visual ,
24
+ Replace ,
24
25
Operator ( char ) ,
25
26
}
26
27
@@ -30,6 +31,7 @@ impl Mode {
30
31
Self :: Normal => "type i to enter insert mode" ,
31
32
Self :: Insert => "type Esc to back to normal mode" ,
32
33
Self :: Visual => "type y to yank, type d to delete, type Esc to back to normal mode" ,
34
+ Self :: Replace => "type character to replace underlined" ,
33
35
Self :: Operator ( _) => "move cursor to apply operator" ,
34
36
} ;
35
37
let title = format ! ( "{} MODE ({})" , self , help) ;
@@ -41,9 +43,10 @@ impl Mode {
41
43
Self :: Normal => Color :: Reset ,
42
44
Self :: Insert => Color :: LightBlue ,
43
45
Self :: Visual => Color :: LightYellow ,
46
+ Self :: Replace => Color :: LightGreen ,
44
47
Self :: Operator ( _) => Color :: LightGreen ,
45
48
} ;
46
- Style :: default ( ) . add_modifier ( Modifier :: SLOW_BLINK )
49
+ Style :: default ( ) . add_modifier ( Modifier :: REVERSED )
47
50
}
48
51
}
49
52
@@ -53,6 +56,7 @@ impl fmt::Display for Mode {
53
56
Self :: Normal => write ! ( f, "NORMAL" ) ,
54
57
Self :: Insert => write ! ( f, "INSERT" ) ,
55
58
Self :: Visual => write ! ( f, "VISUAL" ) ,
59
+ Self :: Replace => write ! ( f, "REPLACE" ) ,
56
60
Self :: Operator ( c) => write ! ( f, "OPERATOR({})" , c) ,
57
61
}
58
62
}
@@ -119,6 +123,9 @@ impl Vim {
119
123
textarea. redo ( ) ;
120
124
return Transition :: Mode ( Mode :: Normal ) ;
121
125
} ,
126
+ Input { key : Key :: Char ( 'r' ) , ctrl : false , .. } => {
127
+ return Transition :: Mode ( Mode :: Replace ) ;
128
+ } ,
122
129
Input { key : Key :: Char ( 'x' ) , .. } => {
123
130
textarea. delete_next_char ( ) ;
124
131
return Transition :: Mode ( Mode :: Normal ) ;
@@ -238,6 +245,14 @@ impl Vim {
238
245
} ,
239
246
}
240
247
} ,
248
+ Mode :: Replace => match input {
249
+ Input { key : Key :: Esc , .. } | Input { key : Key :: Char ( 'c' ) , ctrl : true , .. } => Transition :: Mode ( Mode :: Normal ) ,
250
+ input => {
251
+ textarea. delete_str ( 1 ) ;
252
+ textarea. input ( input) ;
253
+ Transition :: Mode ( Mode :: Normal )
254
+ } ,
255
+ } ,
241
256
}
242
257
}
243
258
}
0 commit comments