outputting to the status line
This commit is contained in:
@@ -20,16 +20,18 @@ pub fn render_status_line(
|
||||
current_fps: f64,
|
||||
app_state: &AppState,
|
||||
) {
|
||||
// --- START FIX ---
|
||||
// Ensure debug_text is always a &str, which implements UnicodeWidthStr.
|
||||
#[cfg(feature = "ui-debug")]
|
||||
let debug_text = app_state.debug_info.as_str();
|
||||
#[cfg(not(feature = "ui-debug"))]
|
||||
let debug_text = "";
|
||||
// --- END FIX ---
|
||||
|
||||
let debug_width = UnicodeWidthStr::width(debug_text);
|
||||
let debug_separator_width = if !debug_text.is_empty() { UnicodeWidthStr::width(" | ") } else { 0 };
|
||||
{
|
||||
// If ui-debug is enabled, we only show the debug info.
|
||||
let debug_text = &app_state.debug_info;
|
||||
let debug_span = Span::styled(
|
||||
debug_text.as_str(),
|
||||
Style::default().fg(theme.accent).bg(theme.bg),
|
||||
);
|
||||
let paragraph = Paragraph::new(Line::from(vec![debug_span]));
|
||||
f.render_widget(paragraph, area);
|
||||
return; // Early return to skip the normal status line rendering.
|
||||
}
|
||||
|
||||
let program_info = format!("multieko2 v{}", env!("CARGO_PKG_VERSION"));
|
||||
let mode_text = if is_edit_mode { "[EDIT]" } else { "[READ-ONLY]" };
|
||||
@@ -50,16 +52,25 @@ pub fn render_status_line(
|
||||
let separator = " | ";
|
||||
let separator_width = UnicodeWidthStr::width(separator);
|
||||
|
||||
let fixed_width_with_fps = mode_width + separator_width + separator_width +
|
||||
program_info_width + separator_width + fps_width +
|
||||
debug_separator_width + debug_width;
|
||||
let fixed_width_with_fps = mode_width
|
||||
+ separator_width
|
||||
+ separator_width
|
||||
+ program_info_width
|
||||
+ separator_width
|
||||
+ fps_width;
|
||||
|
||||
let show_fps = fixed_width_with_fps <= available_width;
|
||||
|
||||
let remaining_width_for_dir = available_width.saturating_sub(
|
||||
mode_width + separator_width +
|
||||
separator_width + program_info_width +
|
||||
(if show_fps { separator_width + fps_width } else { 0 }) +
|
||||
debug_separator_width + debug_width,
|
||||
mode_width
|
||||
+ separator_width
|
||||
+ separator_width
|
||||
+ program_info_width
|
||||
+ (if show_fps {
|
||||
separator_width + fps_width
|
||||
} else {
|
||||
0
|
||||
}),
|
||||
);
|
||||
|
||||
let dir_display_text_str = if UnicodeWidthStr::width(display_dir.as_str()) <= remaining_width_for_dir {
|
||||
@@ -76,10 +87,11 @@ pub fn render_status_line(
|
||||
}
|
||||
};
|
||||
|
||||
let mut current_content_width = mode_width + separator_width +
|
||||
UnicodeWidthStr::width(dir_display_text_str.as_str()) +
|
||||
separator_width + program_info_width +
|
||||
debug_separator_width + debug_width;
|
||||
let mut current_content_width = mode_width
|
||||
+ separator_width
|
||||
+ UnicodeWidthStr::width(dir_display_text_str.as_str())
|
||||
+ separator_width
|
||||
+ program_info_width;
|
||||
if show_fps {
|
||||
current_content_width += separator_width + fps_width;
|
||||
}
|
||||
@@ -92,15 +104,13 @@ pub fn render_status_line(
|
||||
Span::styled(program_info.as_str(), Style::default().fg(theme.secondary)),
|
||||
];
|
||||
|
||||
if show_fps {
|
||||
line_spans.push(Span::styled(separator, Style::default().fg(theme.border)));
|
||||
line_spans.push(Span::styled(fps_text.as_str(), Style::default().fg(theme.secondary)));
|
||||
}
|
||||
|
||||
#[cfg(feature = "ui-debug")]
|
||||
{
|
||||
line_spans.push(Span::styled(separator, Style::default().fg(theme.border)));
|
||||
line_spans.push(Span::styled(debug_text, Style::default().fg(theme.accent)));
|
||||
if show_fps {
|
||||
line_spans
|
||||
.push(Span::styled(separator, Style::default().fg(theme.border)));
|
||||
line_spans.push(Span::styled(
|
||||
fps_text.as_str(),
|
||||
Style::default().fg(theme.secondary),
|
||||
));
|
||||
}
|
||||
|
||||
let padding_needed = available_width.saturating_sub(current_content_width);
|
||||
@@ -111,8 +121,8 @@ pub fn render_status_line(
|
||||
));
|
||||
}
|
||||
|
||||
let paragraph = Paragraph::new(Line::from(line_spans))
|
||||
.style(Style::default().bg(theme.bg));
|
||||
let paragraph =
|
||||
Paragraph::new(Line::from(line_spans)).style(Style::default().bg(theme.bg));
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user