1
- use crate :: interactive:: state:: { AppState , Mode , InputFocus } ;
1
+ use crate :: interactive:: state:: { AppState , InputFocus , Mode } ;
2
+ use ratatui:: Frame ;
2
3
use ratatui:: layout:: { Constraint , Direction , Layout , Rect } ;
3
4
use ratatui:: style:: { Color , Modifier , Style } ;
4
5
use ratatui:: text:: { Line , Span } ;
5
- use ratatui:: widgets:: { Block , Borders , BorderType , List , ListItem , ListState , Paragraph , Wrap } ;
6
- use ratatui:: Frame ;
6
+ use ratatui:: widgets:: { Block , BorderType , Borders , List , ListItem , ListState , Paragraph , Wrap } ;
7
7
8
8
pub fn render ( state : & AppState , f : & mut Frame ) {
9
9
let size = f. area ( ) ;
@@ -15,33 +15,44 @@ pub fn render(state: &AppState, f: &mut Frame) {
15
15
16
16
match & state. mode {
17
17
Mode :: List => {
18
- let items: Vec < ListItem > = state. entries . iter ( ) . enumerate ( ) . map ( |( i, ( k, v) ) | {
19
- let marker = if i == state. current_index { "> " } else { " " } ;
20
- let key_field = format ! ( "{:30}" , k) ;
21
- let content = format ! ( "{}{} {}" , marker, key_field, v) ;
22
- let style = if i == state. current_index {
23
- Style :: default ( ) . fg ( Color :: Green ) . add_modifier ( Modifier :: BOLD )
24
- } else {
25
- Style :: default ( ) . fg ( Color :: White )
26
- } ;
27
- ListItem :: new ( Line :: from ( Span :: styled ( content, style) ) )
28
- } ) . collect ( ) ;
18
+ let items: Vec < ListItem > = state
19
+ . entries
20
+ . iter ( )
21
+ . enumerate ( )
22
+ . map ( |( i, ( k, v) ) | {
23
+ let marker = if i == state. current_index { "> " } else { " " } ;
24
+ let key_field = format ! ( "{:30}" , k) ;
25
+ let content = format ! ( "{}{} {}" , marker, key_field, v) ;
26
+ let style = if i == state. current_index {
27
+ Style :: default ( )
28
+ . fg ( Color :: Green )
29
+ . add_modifier ( Modifier :: BOLD )
30
+ } else {
31
+ Style :: default ( ) . fg ( Color :: White )
32
+ } ;
33
+ ListItem :: new ( Line :: from ( Span :: styled ( content, style) ) )
34
+ } )
35
+ . collect ( ) ;
29
36
30
- let list = List :: new ( items)
31
- . block (
32
- Block :: default ( )
33
- . borders ( Borders :: ALL )
34
- . border_type ( BorderType :: Rounded )
35
- . border_style ( Style :: default ( ) . fg ( Color :: Blue ) )
36
- . title ( "Variables" ) ,
37
- ) ;
37
+ let list = List :: new ( items) . block (
38
+ Block :: default ( )
39
+ . borders ( Borders :: ALL )
40
+ . border_type ( BorderType :: Rounded )
41
+ . border_style ( Style :: default ( ) . fg ( Color :: Blue ) )
42
+ . title ( "Variables" ) ,
43
+ ) ;
38
44
let mut list_state = ListState :: default ( ) ;
39
45
list_state. select ( Some ( state. current_index ) ) ;
40
46
f. render_stateful_widget ( list, chunks[ 0 ] , & mut list_state) ;
41
47
}
42
48
Mode :: Add => {
43
49
let modal = Paragraph :: new ( vec ! [
44
- Line :: from( Span :: styled( "Add New Variable" , Style :: default ( ) . fg( Color :: Yellow ) . add_modifier( Modifier :: BOLD ) ) ) ,
50
+ Line :: from( Span :: styled(
51
+ "Add New Variable" ,
52
+ Style :: default ( )
53
+ . fg( Color :: Yellow )
54
+ . add_modifier( Modifier :: BOLD ) ,
55
+ ) ) ,
45
56
Line :: from( format!( "Key: {}" , state. input_key) ) ,
46
57
Line :: from( format!( "Value: {}" , state. input_value) ) ,
47
58
Line :: from( "Enter=confirm, Esc=cancel, Tab=switch field, ←/→ move cursor" ) ,
@@ -77,7 +88,12 @@ pub fn render(state: &AppState, f: &mut Frame) {
77
88
}
78
89
Mode :: Edit ( key) => {
79
90
let modal = Paragraph :: new ( vec ! [
80
- Line :: from( Span :: styled( format!( "Editing: {}" , key) , Style :: default ( ) . fg( Color :: Yellow ) . add_modifier( Modifier :: BOLD ) ) ) ,
91
+ Line :: from( Span :: styled(
92
+ format!( "Editing: {}" , key) ,
93
+ Style :: default ( )
94
+ . fg( Color :: Yellow )
95
+ . add_modifier( Modifier :: BOLD ) ,
96
+ ) ) ,
81
97
Line :: from( format!( "New Value: {}" , state. input_value) ) ,
82
98
Line :: from( "Enter=confirm, Esc=cancel, ←/→ move cursor" ) ,
83
99
] )
@@ -99,7 +115,10 @@ pub fn render(state: &AppState, f: &mut Frame) {
99
115
}
100
116
Mode :: Delete ( key) => {
101
117
let modal = Paragraph :: new ( vec ! [
102
- Line :: from( Span :: styled( format!( "Delete: {}" , key) , Style :: default ( ) . fg( Color :: Red ) . add_modifier( Modifier :: BOLD ) ) ) ,
118
+ Line :: from( Span :: styled(
119
+ format!( "Delete: {}" , key) ,
120
+ Style :: default ( ) . fg( Color :: Red ) . add_modifier( Modifier :: BOLD ) ,
121
+ ) ) ,
103
122
Line :: from( "Confirm deletion? [y]es / [n]o" ) ,
104
123
] )
105
124
. block (
0 commit comments