@@ -505,12 +505,18 @@ pub fn render_table(
505505///
506506/// # Arguments
507507/// * `table` - The table to render
508- /// * `style` - Style for all text (headers and cells use the same style)
508+ /// * `header_style` - Style for header text (colored/bold headers)
509+ /// * `cell_style` - Style for data cell text
509510/// * `max_width` - Maximum total width for the table
510511///
511512/// # Returns
512513/// A vector of `Line`s ready for display in ratatui.
513- pub fn render_table_simple ( table : & Table , style : Style , max_width : u16 ) -> Vec < Line < ' static > > {
514+ pub fn render_table_simple (
515+ table : & Table ,
516+ header_style : Style ,
517+ cell_style : Style ,
518+ max_width : u16 ,
519+ ) -> Vec < Line < ' static > > {
514520 // Handle empty table
515521 if table. is_empty ( ) {
516522 return Vec :: new ( ) ;
@@ -532,17 +538,22 @@ pub fn render_table_simple(table: &Table, style: Style, max_width: u16) -> Vec<L
532538
533539 let mut lines = Vec :: new ( ) ;
534540
535- // Header row (if present)
541+ // Header row (if present) - use header_style for colored headers
536542 if !table. headers . is_empty ( ) {
537- lines. push ( render_simple_row ( & table. headers , widths, alignments, style) ) ;
543+ lines. push ( render_simple_row (
544+ & table. headers ,
545+ widths,
546+ alignments,
547+ header_style,
548+ ) ) ;
538549
539550 // Header separator line: ---+---+---
540- lines. push ( render_simple_separator ( widths, style ) ) ;
551+ lines. push ( render_simple_separator ( widths, cell_style ) ) ;
541552 }
542553
543- // Data rows
554+ // Data rows - use cell_style
544555 for row in & table. rows {
545- lines. push ( render_simple_row ( row, widths, alignments, style ) ) ;
556+ lines. push ( render_simple_row ( row, widths, alignments, cell_style ) ) ;
546557 }
547558
548559 lines
@@ -1113,7 +1124,7 @@ mod tests {
11131124 #[ test]
11141125 fn test_simple_table_empty ( ) {
11151126 let table = Table :: default ( ) ;
1116- let lines = render_table_simple ( & table, Style :: default ( ) , 80 ) ;
1127+ let lines = render_table_simple ( & table, Style :: default ( ) , Style :: default ( ) , 80 ) ;
11171128 assert ! ( lines. is_empty( ) ) ;
11181129 }
11191130
@@ -1129,7 +1140,7 @@ mod tests {
11291140 builder. end_row ( ) ;
11301141
11311142 let table = builder. build ( ) ;
1132- let lines = render_table_simple ( & table, Style :: default ( ) , 80 ) ;
1143+ let lines = render_table_simple ( & table, Style :: default ( ) , Style :: default ( ) , 80 ) ;
11331144
11341145 // Should have: header, separator, data row = 3 lines (no outer borders)
11351146 assert_eq ! ( lines. len( ) , 3 ) ;
@@ -1151,7 +1162,7 @@ mod tests {
11511162 builder. end_row ( ) ;
11521163
11531164 let table = builder. build ( ) ;
1154- let lines = render_table_simple ( & table, Style :: default ( ) , 80 ) ;
1165+ let lines = render_table_simple ( & table, Style :: default ( ) , Style :: default ( ) , 80 ) ;
11551166
11561167 // Check that separator line contains + characters
11571168 let separator_content: String = lines[ 1 ] . spans . iter ( ) . map ( |s| & * s. content ) . collect ( ) ;
@@ -1180,7 +1191,7 @@ mod tests {
11801191 builder. end_row ( ) ;
11811192
11821193 let table = builder. build ( ) ;
1183- let lines = render_table_simple ( & table, Style :: default ( ) , 80 ) ;
1194+ let lines = render_table_simple ( & table, Style :: default ( ) , Style :: default ( ) , 80 ) ;
11841195
11851196 // Should have: 2 data rows only (no header, no separator)
11861197 assert_eq ! ( lines. len( ) , 2 ) ;
@@ -1200,7 +1211,7 @@ mod tests {
12001211 builder. end_row ( ) ;
12011212
12021213 let table = builder. build ( ) ;
1203- let lines = render_table_simple ( & table, Style :: default ( ) , 80 ) ;
1214+ let lines = render_table_simple ( & table, Style :: default ( ) , Style :: default ( ) , 80 ) ;
12041215
12051216 // First line should be header with | separator
12061217 let header_content: String = lines[ 0 ] . spans . iter ( ) . map ( |s| & * s. content ) . collect ( ) ;
@@ -1216,4 +1227,44 @@ mod tests {
12161227 "Separator should have + at column intersections"
12171228 ) ;
12181229 }
1230+
1231+ #[ test]
1232+ fn test_simple_table_header_styling ( ) {
1233+ let mut builder = TableBuilder :: new ( ) ;
1234+ builder. start_header ( ) ;
1235+ builder. add_cell ( "Header1" . to_string ( ) ) ;
1236+ builder. add_cell ( "Header2" . to_string ( ) ) ;
1237+ builder. end_header ( ) ;
1238+
1239+ builder. start_row ( ) ;
1240+ builder. add_cell ( "Cell1" . to_string ( ) ) ;
1241+ builder. add_cell ( "Cell2" . to_string ( ) ) ;
1242+ builder. end_row ( ) ;
1243+
1244+ let table = builder. build ( ) ;
1245+
1246+ // Use different styles for header and cells
1247+ let header_style = Style :: default ( ) . fg ( Color :: Cyan ) ;
1248+ let cell_style = Style :: default ( ) . fg ( Color :: White ) ;
1249+
1250+ let lines = render_table_simple ( & table, header_style, cell_style, 80 ) ;
1251+
1252+ // Header row should have header_style
1253+ assert ! ( !lines. is_empty( ) ) ;
1254+ let header_line = & lines[ 0 ] ;
1255+ // Check that header spans have the cyan color
1256+ for span in & header_line. spans {
1257+ if span. content . contains ( "Header" ) {
1258+ assert_eq ! ( span. style. fg, Some ( Color :: Cyan ) ) ;
1259+ }
1260+ }
1261+
1262+ // Data row should have cell_style
1263+ let data_line = & lines[ 2 ] ; // After header and separator
1264+ for span in & data_line. spans {
1265+ if span. content . contains ( "Cell" ) {
1266+ assert_eq ! ( span. style. fg, Some ( Color :: White ) ) ;
1267+ }
1268+ }
1269+ }
12191270}
0 commit comments