@@ -13,7 +13,7 @@ use std::borrow::Cow;
1313use crate :: header:: { format_memory, Header } ;
1414use crate :: tui:: color:: TuiColor ;
1515use crate :: tui:: stat:: { CpuGraphMode , MemoryGraphMode , TuiStat } ;
16- use crate :: ProcList ;
16+ use crate :: { InfoBar , ProcList } ;
1717use ratatui:: prelude:: * ;
1818use ratatui:: widgets:: { Cell , Paragraph , Row , Table , TableState } ;
1919use std:: cmp:: min;
@@ -22,19 +22,21 @@ pub struct Tui<'a> {
2222 settings : & ' a crate :: Settings ,
2323 header : & ' a Header ,
2424 proc_list : & ' a ProcList ,
25+ info_bar : & ' a Option < InfoBar > ,
2526 stat : & ' a mut TuiStat ,
2627}
2728
2829impl < ' a > Tui < ' a > {
2930 pub fn new (
3031 settings : & ' a crate :: Settings ,
31- data : & ' a ( Header , ProcList ) ,
32+ data : & ' a ( Header , ProcList , Option < InfoBar > ) ,
3233 stat : & ' a mut TuiStat ,
3334 ) -> Self {
3435 Self {
3536 settings,
3637 header : & data. 0 ,
3738 proc_list : & data. 1 ,
39+ info_bar : & data. 2 ,
3840 stat,
3941 }
4042 }
@@ -66,6 +68,19 @@ impl<'a> Tui<'a> {
6668 height
6769 }
6870
71+ fn calc_info_bar_height ( & self , width : u16 ) -> u16 {
72+ if let Some ( info_bar) = & self . info_bar {
73+ let lines: u16 = info_bar
74+ . content
75+ . lines ( )
76+ . map ( |s| ( s. len ( ) as u16 ) . div_ceil ( width) )
77+ . sum ( ) ;
78+ lines + 1 // 1 for title
79+ } else {
80+ 0
81+ }
82+ }
83+
6984 fn calc_list_coordinates ( & self ) -> ( usize , usize ) {
7085 let list_total = self . proc_list . collected . len ( ) ;
7186 let list_offset = self . stat . list_offset ;
@@ -506,6 +521,19 @@ impl<'a> Tui<'a> {
506521 let table = Table :: new ( rows, constraints. clone ( ) ) . header ( header) ;
507522 StatefulWidget :: render ( table, area, buf, & mut state) ;
508523 }
524+
525+ fn render_info_bar ( & self , area : Rect , buf : & mut Buffer ) {
526+ if let Some ( info_bar) = self . info_bar . as_ref ( ) {
527+ let constraints = [ Constraint :: Length ( 1 ) , Constraint :: Min ( 1 ) ] ;
528+ let layout = Layout :: new ( Direction :: Vertical , constraints) . split ( area) ;
529+ Line :: from ( Span :: styled (
530+ format ! ( "{:<width$}" , & info_bar. title, width = area. width as usize ) ,
531+ Style :: default ( ) . bg_secondary ( self . stat . colorful ) ,
532+ ) )
533+ . render ( layout[ 0 ] , buf) ;
534+ Span :: raw ( & info_bar. content ) . render ( layout[ 1 ] , buf) ;
535+ }
536+ }
509537}
510538
511539impl Widget for Tui < ' _ > {
@@ -524,6 +552,7 @@ impl Widget for Tui<'_> {
524552 Constraint :: Length ( self . calc_header_height ( ) ) ,
525553 Constraint :: Length ( 1 ) ,
526554 Constraint :: Min ( 0 ) ,
555+ Constraint :: Length ( self . calc_info_bar_height ( area. width ) ) ,
527556 ] ,
528557 )
529558 . split ( area) ;
@@ -536,5 +565,6 @@ impl Widget for Tui<'_> {
536565 list_area. height = list_height;
537566 }
538567 self . render_list ( list_area, buf) ;
568+ self . render_info_bar ( layout[ 3 ] , buf) ;
539569 }
540570}
0 commit comments