33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6+ mod color;
67mod input;
78pub mod stat;
9+
810pub use input:: * ;
911
1012use crate :: header:: { format_memory, Header } ;
13+ use crate :: tui:: color:: TuiColor ;
1114use crate :: tui:: stat:: { CpuGraphMode , MemoryGraphMode , TuiStat } ;
1215use crate :: ProcList ;
1316use ratatui:: prelude:: * ;
@@ -64,6 +67,7 @@ impl<'a> Tui<'a> {
6467
6568 fn render_header ( & self , area : Rect , buf : & mut Buffer ) {
6669 let constraints = vec ! [ Constraint :: Length ( 1 ) ; self . calc_header_height( ) as usize ] ;
70+ let colorful = self . stat . colorful ;
6771
6872 let cpu = & self . header . cpu ;
6973
@@ -100,7 +104,7 @@ impl<'a> Tui<'a> {
100104 if i_columns > 0 {
101105 Line :: from ( vec ! [
102106 Span :: raw( " " ) ,
103- Span :: styled( " " , Style :: default ( ) . bg ( Color :: Yellow ) ) ,
107+ Span :: styled( " " , Style :: default ( ) . bg_secondary ( colorful ) ) ,
104108 Span :: raw( " " ) ,
105109 ] )
106110 . render ( cpu_column. as_ref ( ) . unwrap ( ) [ column_offset - 1 ] , buf) ;
@@ -118,7 +122,7 @@ impl<'a> Tui<'a> {
118122 . split ( area) ;
119123 i_columns += 1 ;
120124
121- Span :: styled ( format ! ( "%{tag:<6}:" , ) , Style :: default ( ) . red ( ) )
125+ Span :: styled ( format ! ( "%{tag:<6}:" , ) , Style :: default ( ) . primary ( colorful ) )
122126 . render ( line_layout[ 0 ] , buf) ;
123127 let percentage = if print_percentage {
124128 format ! ( "{:>5.0}" , ( ( red + yellow) * 100.0 ) . round( ) )
@@ -127,7 +131,10 @@ impl<'a> Tui<'a> {
127131 } ;
128132 Line :: from ( vec ! [
129133 Span :: raw( format!( "{l:>5.1}" ) ) ,
130- Span :: styled( format!( "/{r:<5.1}{percentage}" ) , Style :: default ( ) . red( ) ) ,
134+ Span :: styled(
135+ format!( "/{r:<5.1}{percentage}" ) ,
136+ Style :: default ( ) . primary( colorful) ,
137+ ) ,
131138 ] )
132139 . render ( line_layout[ 1 ] , buf) ;
133140 Paragraph :: new ( "[" ) . render ( line_layout[ 2 ] , buf) ;
@@ -139,17 +146,17 @@ impl<'a> Tui<'a> {
139146 let red_span = Span :: styled (
140147 content. to_string ( ) . repeat ( red_width as usize ) ,
141148 if content == ' ' {
142- Style :: default ( ) . bg ( Color :: Red )
149+ Style :: default ( ) . bg_primary ( colorful )
143150 } else {
144- Style :: default ( ) . red ( )
151+ Style :: default ( ) . primary ( colorful )
145152 } ,
146153 ) ;
147154 let yellow_span = Span :: styled (
148155 content. to_string ( ) . repeat ( yellow_width as usize ) ,
149156 if content == ' ' {
150- Style :: default ( ) . bg ( Color :: Yellow )
157+ Style :: default ( ) . bg_secondary ( colorful )
151158 } else {
152- Style :: default ( ) . yellow ( )
159+ Style :: default ( ) . secondary ( colorful )
153160 } ,
154161 ) ;
155162
@@ -175,17 +182,17 @@ impl<'a> Tui<'a> {
175182 if self . stat . cpu_graph_mode != CpuGraphMode :: Hide {
176183 let task = & self . header . task ;
177184 let task_line = vec ! [
178- Span :: styled( "Tasks: " , Style :: default ( ) . red ( ) ) ,
185+ Span :: styled( "Tasks: " , Style :: default ( ) . primary ( colorful ) ) ,
179186 Span :: raw( task. total. to_string( ) ) ,
180- Span :: styled( " total, " , Style :: default ( ) . red ( ) ) ,
187+ Span :: styled( " total, " , Style :: default ( ) . primary ( colorful ) ) ,
181188 Span :: raw( task. running. to_string( ) ) ,
182- Span :: styled( " running, " , Style :: default ( ) . red ( ) ) ,
189+ Span :: styled( " running, " , Style :: default ( ) . primary ( colorful ) ) ,
183190 Span :: raw( task. sleeping. to_string( ) ) ,
184- Span :: styled( " sleeping, " , Style :: default ( ) . red ( ) ) ,
191+ Span :: styled( " sleeping, " , Style :: default ( ) . primary ( colorful ) ) ,
185192 Span :: raw( task. stopped. to_string( ) ) ,
186- Span :: styled( " stopped, " , Style :: default ( ) . red ( ) ) ,
193+ Span :: styled( " stopped, " , Style :: default ( ) . primary ( colorful ) ) ,
187194 Span :: raw( task. zombie. to_string( ) ) ,
188- Span :: styled( " zombie" , Style :: default ( ) . red ( ) ) ,
195+ Span :: styled( " zombie" , Style :: default ( ) . primary ( colorful ) ) ,
189196 ] ;
190197 Line :: from ( task_line) . render ( header_layout[ i] , buf) ;
191198 i += 1 ;
@@ -254,28 +261,34 @@ impl<'a> Tui<'a> {
254261
255262 if self . stat . memory_graph_mode == MemoryGraphMode :: Sum {
256263 Line :: from ( vec ! [
257- Span :: styled( format!( "{unit_name} Mem : " ) , Style :: default ( ) . red( ) ) ,
264+ Span :: styled(
265+ format!( "{unit_name} Mem : " ) ,
266+ Style :: default ( ) . primary( colorful) ,
267+ ) ,
258268 Span :: raw( format!( "{:8.1}" , format_memory( mem. total, unit) ) ) ,
259- Span :: styled( " total, " , Style :: default ( ) . red ( ) ) ,
269+ Span :: styled( " total, " , Style :: default ( ) . primary ( colorful ) ) ,
260270 Span :: raw( format!( "{:8.1}" , format_memory( mem. free, unit) ) ) ,
261- Span :: styled( " free, " , Style :: default ( ) . red ( ) ) ,
271+ Span :: styled( " free, " , Style :: default ( ) . primary ( colorful ) ) ,
262272 Span :: raw( format!( "{:8.1}" , format_memory( mem. used, unit) ) ) ,
263- Span :: styled( " used, " , Style :: default ( ) . red ( ) ) ,
273+ Span :: styled( " used, " , Style :: default ( ) . primary ( colorful ) ) ,
264274 Span :: raw( format!( "{:8.1}" , format_memory( mem. buff_cache, unit) ) ) ,
265- Span :: styled( " buff/cache" , Style :: default ( ) . red ( ) ) ,
275+ Span :: styled( " buff/cache" , Style :: default ( ) . primary ( colorful ) ) ,
266276 ] )
267277 . render ( header_layout[ i] , buf) ;
268278 i += 1 ;
269279 Line :: from ( vec ! [
270- Span :: styled( format!( "{unit_name} Swap: " ) , Style :: default ( ) . red( ) ) ,
280+ Span :: styled(
281+ format!( "{unit_name} Swap: " ) ,
282+ Style :: default ( ) . primary( colorful) ,
283+ ) ,
271284 Span :: raw( format!( "{:8.1}" , format_memory( mem. total_swap, unit) ) ) ,
272- Span :: styled( " total, " , Style :: default ( ) . red ( ) ) ,
285+ Span :: styled( " total, " , Style :: default ( ) . primary ( colorful ) ) ,
273286 Span :: raw( format!( "{:8.1}" , format_memory( mem. free_swap, unit) ) ) ,
274- Span :: styled( " free, " , Style :: default ( ) . red ( ) ) ,
287+ Span :: styled( " free, " , Style :: default ( ) . primary ( colorful ) ) ,
275288 Span :: raw( format!( "{:8.1}" , format_memory( mem. used_swap, unit) ) ) ,
276- Span :: styled( " used, " , Style :: default ( ) . red ( ) ) ,
289+ Span :: styled( " used, " , Style :: default ( ) . primary ( colorful ) ) ,
277290 Span :: raw( format!( "{:8.1}" , format_memory( mem. available, unit) ) ) ,
278- Span :: styled( " avail Mem" , Style :: default ( ) . red ( ) ) ,
291+ Span :: styled( " avail Mem" , Style :: default ( ) . primary ( colorful ) ) ,
279292 ] )
280293 . render ( header_layout[ i] , buf) ;
281294 } else {
@@ -322,21 +335,28 @@ impl<'a> Tui<'a> {
322335 }
323336
324337 fn render_input ( & self , area : Rect , buf : & mut Buffer ) {
338+ let colorful = self . stat . colorful ;
325339 if let Some ( v) = self . stat . input_error . as_ref ( ) {
340+ let layout = Layout :: new (
341+ Direction :: Horizontal ,
342+ [ Constraint :: Length ( v. len ( ) as u16 ) , Constraint :: Fill ( 1 ) ] ,
343+ )
344+ . split ( area) ;
326345 Paragraph :: new ( v. as_str ( ) )
327- . style ( Style :: default ( ) . fg ( Color :: Red ) )
328- . render ( area , buf) ;
346+ . style ( Style :: default ( ) . error ( colorful ) )
347+ . render ( layout [ 0 ] , buf) ;
329348 return ;
330349 }
331350 let input = Line :: from ( vec ! [
332- Span :: styled( & self . stat. input_label, Style :: default ( ) . red ( ) ) ,
351+ Span :: styled( & self . stat. input_label, Style :: default ( ) . primary ( colorful ) ) ,
333352 Span :: raw( " " ) ,
334353 Span :: raw( & self . stat. input_value) ,
335354 ] ) ;
336355 input. render ( area, buf) ;
337356 }
338357
339358 fn render_list ( & mut self , area : Rect , buf : & mut Buffer ) {
359+ let colorful = self . stat . colorful ;
340360 let build_constraint = |field : & str | match field {
341361 "PID" => Constraint :: Length ( 7 ) ,
342362 "USER" => Constraint :: Length ( 10 ) ,
@@ -362,9 +382,8 @@ impl<'a> Tui<'a> {
362382
363383 self . stat . list_offset = min ( self . stat . list_offset , self . proc_list . collected . len ( ) - 1 ) ;
364384
365- let header = Row :: new ( self . proc_list . fields . clone ( ) )
366- . style ( Style :: default ( ) . bg ( Color :: Yellow ) )
367- . height ( 1 ) ;
385+ let header =
386+ Row :: new ( self . proc_list . fields . clone ( ) ) . style ( Style :: default ( ) . bg_secondary ( colorful) ) ;
368387
369388 let rows = self . proc_list . collected . iter ( ) . map ( |item| {
370389 let cells = item. iter ( ) . map ( |c| Cell :: from ( c. as_str ( ) ) ) ;
0 commit comments