@@ -3,7 +3,7 @@ use helix_view::{
3
3
document:: { Mode , SCRATCH_BUFFER_NAME } ,
4
4
graphics:: Rect ,
5
5
theme:: Style ,
6
- Document , Editor , Theme , View ,
6
+ Document , Editor , View ,
7
7
} ;
8
8
9
9
use crate :: ui:: ProgressSpinners ;
@@ -13,26 +13,26 @@ use tui::buffer::Buffer as Surface;
13
13
use tui:: text:: { Span , Spans } ;
14
14
15
15
pub struct RenderContext < ' a > {
16
+ pub editor : & ' a Editor ,
16
17
pub doc : & ' a Document ,
17
18
pub view : & ' a View ,
18
- pub theme : & ' a Theme ,
19
19
pub focused : bool ,
20
20
pub spinners : & ' a ProgressSpinners ,
21
21
pub parts : RenderBuffer < ' a > ,
22
22
}
23
23
24
24
impl < ' a > RenderContext < ' a > {
25
25
pub fn new (
26
+ editor : & ' a Editor ,
26
27
doc : & ' a Document ,
27
28
view : & ' a View ,
28
- theme : & ' a Theme ,
29
29
focused : bool ,
30
30
spinners : & ' a ProgressSpinners ,
31
31
) -> Self {
32
32
RenderContext {
33
+ editor,
33
34
doc,
34
35
view,
35
- theme,
36
36
focused,
37
37
spinners,
38
38
parts : RenderBuffer :: default ( ) ,
@@ -47,11 +47,11 @@ pub struct RenderBuffer<'a> {
47
47
pub right : Spans < ' a > ,
48
48
}
49
49
50
- pub fn render ( editor : & Editor , context : & mut RenderContext , viewport : Rect , surface : & mut Surface ) {
50
+ pub fn render ( context : & mut RenderContext , viewport : Rect , surface : & mut Surface ) {
51
51
let base_style = if context. focused {
52
- context. theme . get ( "ui.statusline" )
52
+ context. editor . theme . get ( "ui.statusline" )
53
53
} else {
54
- context. theme . get ( "ui.statusline.inactive" )
54
+ context. editor . theme . get ( "ui.statusline.inactive" )
55
55
} ;
56
56
57
57
surface. set_style ( viewport. with_height ( 1 ) , base_style) ;
@@ -68,7 +68,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf
68
68
69
69
// Left side of the status line.
70
70
71
- let element_ids = & editor. config ( ) . statusline . left ;
71
+ let element_ids = & context . editor . config ( ) . statusline . left ;
72
72
element_ids
73
73
. iter ( )
74
74
. map ( |element_id| get_render_function ( * element_id) )
@@ -83,7 +83,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf
83
83
84
84
// Right side of the status line.
85
85
86
- let element_ids = & editor. config ( ) . statusline . right ;
86
+ let element_ids = & context . editor . config ( ) . statusline . right ;
87
87
element_ids
88
88
. iter ( )
89
89
. map ( |element_id| get_render_function ( * element_id) )
@@ -101,7 +101,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf
101
101
102
102
// Center of the status line.
103
103
104
- let element_ids = & editor. config ( ) . statusline . center ;
104
+ let element_ids = & context . editor . config ( ) . statusline . center ;
105
105
element_ids
106
106
. iter ( )
107
107
. map ( |element_id| get_render_function ( * element_id) )
@@ -166,11 +166,11 @@ where
166
166
" "
167
167
}
168
168
) ,
169
- if visible {
169
+ if visible && context . editor . config ( ) . color_modes {
170
170
match context. doc . mode ( ) {
171
- Mode :: Insert => Some ( context. theme . get ( "ui.statusline.insert" ) ) ,
172
- Mode :: Select => Some ( context. theme . get ( "ui.statusline.select" ) ) ,
173
- Mode :: Normal => Some ( context. theme . get ( "ui.statusline.normal" ) ) ,
171
+ Mode :: Insert => Some ( context. editor . theme . get ( "ui.statusline.insert" ) ) ,
172
+ Mode :: Select => Some ( context. editor . theme . get ( "ui.statusline.select" ) ) ,
173
+ Mode :: Normal => Some ( context. editor . theme . get ( "ui.statusline.normal" ) ) ,
174
174
}
175
175
} else {
176
176
None
@@ -219,12 +219,20 @@ where
219
219
} ) ;
220
220
221
221
if warnings > 0 {
222
- write ( context, "●" . to_string ( ) , Some ( context. theme . get ( "warning" ) ) ) ;
222
+ write (
223
+ context,
224
+ "●" . to_string ( ) ,
225
+ Some ( context. editor . theme . get ( "warning" ) ) ,
226
+ ) ;
223
227
write ( context, format ! ( " {} " , warnings) , None ) ;
224
228
}
225
229
226
230
if errors > 0 {
227
- write ( context, "●" . to_string ( ) , Some ( context. theme . get ( "error" ) ) ) ;
231
+ write (
232
+ context,
233
+ "●" . to_string ( ) ,
234
+ Some ( context. editor . theme . get ( "error" ) ) ,
235
+ ) ;
228
236
write ( context, format ! ( " {} " , errors) , None ) ;
229
237
}
230
238
}
0 commit comments