@@ -10,6 +10,21 @@ use ratatui::{
1010} ;
1111use unicode_width:: UnicodeWidthStr ;
1212
13+ // UI Style Constants
14+ const SELECTED_BG : Color = Color :: DarkGray ;
15+ const EXPANDED_BG : Color = Color :: Rgb ( 30 , 30 , 40 ) ;
16+ const LINE_PREFIX_WIDTH : usize = 9 ; // "{:6} | " = 9 characters
17+
18+ /// Apply selection styling to a span (dark bg, bold, adjust dark foreground colors)
19+ fn apply_selection_style ( style : Style ) -> Style {
20+ // Adjust foreground if it's too dark to see against DarkGray background
21+ let adjusted = match style. fg {
22+ Some ( Color :: Gray ) | Some ( Color :: DarkGray ) | Some ( Color :: Black ) => style. fg ( Color :: White ) ,
23+ _ => style,
24+ } ;
25+ adjusted. bg ( SELECTED_BG ) . add_modifier ( Modifier :: BOLD )
26+ }
27+
1328/// Expand tabs to spaces for proper rendering
1429fn expand_tabs ( line : & str ) -> String {
1530 if !line. contains ( '\t' ) {
@@ -204,10 +219,7 @@ fn render_log_view(f: &mut Frame, area: Rect, app: &mut App) -> Result<()> {
204219
205220 // Calculate available width for content (accounting for borders and line prefix)
206221 let available_width = area. width . saturating_sub ( 2 ) as usize ; // Account for borders
207- let prefix_width = 9 ; // "{:6} | " = 9 characters
208-
209- // Background color for expanded (non-selected) entries
210- let expanded_bg = Color :: Rgb ( 30 , 30 , 40 ) ;
222+ let prefix_width = LINE_PREFIX_WIDTH ;
211223
212224 // Get reader access and collect expanded_lines snapshot
213225 let mut reader_guard = tab. reader . lock ( ) . unwrap ( ) ;
@@ -228,7 +240,7 @@ fn render_log_view(f: &mut Frame, area: Rect, app: &mut App) -> Result<()> {
228240 if is_expanded && available_width > prefix_width {
229241 // Expanded: wrap content across multiple lines
230242 let content_width = available_width. saturating_sub ( prefix_width) ;
231- let wrapped_lines = wrap_content ( & line_text, content_width, prefix_width ) ;
243+ let wrapped_lines = wrap_content ( & line_text, content_width) ;
232244
233245 let mut item_lines: Vec < Line < ' static > > = Vec :: new ( ) ;
234246
@@ -246,17 +258,10 @@ fn render_log_view(f: &mut Frame, area: Rect, app: &mut App) -> Result<()> {
246258 // Apply styling based on selection/expansion state
247259 for span in & mut wrapped_line. spans {
248260 if is_selected {
249- // Selected: dark gray background + bold
250- let new_style = match span. style . fg {
251- Some ( Color :: Gray ) | Some ( Color :: DarkGray ) | Some ( Color :: Black ) => {
252- span. style . fg ( Color :: White )
253- }
254- _ => span. style ,
255- } ;
256- span. style = new_style. bg ( Color :: DarkGray ) . add_modifier ( Modifier :: BOLD ) ;
261+ span. style = apply_selection_style ( span. style ) ;
257262 } else {
258263 // Expanded but not selected: subtle dark background
259- span. style = span. style . bg ( expanded_bg ) ;
264+ span. style = span. style . bg ( EXPANDED_BG ) ;
260265 }
261266 }
262267
@@ -283,13 +288,7 @@ fn render_log_view(f: &mut Frame, area: Rect, app: &mut App) -> Result<()> {
283288 // Apply selection background if this is the selected line
284289 if is_selected {
285290 for span in & mut final_line. spans {
286- let new_style = match span. style . fg {
287- Some ( Color :: Gray ) | Some ( Color :: DarkGray ) | Some ( Color :: Black ) => {
288- span. style . fg ( Color :: White )
289- }
290- _ => span. style ,
291- } ;
292- span. style = new_style. bg ( Color :: DarkGray ) . add_modifier ( Modifier :: BOLD ) ;
291+ span. style = apply_selection_style ( span. style ) ;
293292 }
294293 }
295294
@@ -427,8 +426,7 @@ fn render_line_jump_prompt(f: &mut Frame, area: Rect, app: &App) {
427426/// # Arguments
428427/// * `content` - The raw content string (may contain ANSI codes)
429428/// * `available_width` - The width in columns to wrap to
430- /// * `prefix_width` - The width of the line number prefix (for continuation indent)
431- fn wrap_content ( content : & str , available_width : usize , prefix_width : usize ) -> Vec < Line < ' static > > {
429+ fn wrap_content ( content : & str , available_width : usize ) -> Vec < Line < ' static > > {
432430 if available_width == 0 {
433431 return vec ! [ Line :: default ( ) ] ;
434432 }
@@ -456,10 +454,10 @@ fn wrap_content(content: &str, available_width: usize, prefix_width: usize) -> V
456454 }
457455
458456 // Word wrap the spans
457+ // Note: We don't add continuation indent here - the caller (render_log_view) handles prefixes
459458 let mut result_lines: Vec < Line < ' static > > = Vec :: new ( ) ;
460459 let mut current_line_spans: Vec < Span < ' static > > = Vec :: new ( ) ;
461460 let mut current_line_width = 0 ;
462- let continuation_indent = " " . repeat ( prefix_width) ;
463461
464462 for span in spans {
465463 let span_text = span. content . to_string ( ) ;
@@ -518,9 +516,8 @@ fn wrap_content(content: &str, available_width: usize, prefix_width: usize) -> V
518516 // Commit current line and start new one
519517 if !current_line_spans. is_empty ( ) {
520518 result_lines. push ( Line :: from ( current_line_spans) ) ;
521- // Add continuation indent for wrapped lines
522- current_line_spans = vec ! [ Span :: raw( continuation_indent. clone( ) ) ] ;
523- current_line_width = prefix_width;
519+ current_line_spans = Vec :: new ( ) ;
520+ current_line_width = 0 ;
524521 }
525522 }
526523 }
0 commit comments