79 lines
2.7 KiB
Rust
79 lines
2.7 KiB
Rust
use ratatui::{
|
|
style::Style,
|
|
layout::Rect,
|
|
Frame,
|
|
text::{Line, Span},
|
|
widgets::Paragraph,
|
|
};
|
|
use unicode_width::UnicodeWidthStr;
|
|
use crate::config::colors::themes::Theme;
|
|
use std::path::Path;
|
|
|
|
pub fn render_status_line(
|
|
f: &mut Frame,
|
|
area: Rect,
|
|
current_dir: &str,
|
|
theme: &Theme,
|
|
is_edit_mode: bool,
|
|
current_fps: f64,
|
|
) {
|
|
let program_info = format!("multieko2 v{}", env!("CARGO_PKG_VERSION"));
|
|
let mode_text = if is_edit_mode { "[EDIT]" } else { "[READ-ONLY]" };
|
|
|
|
let home_dir = dirs::home_dir().map(|p| p.to_string_lossy().into_owned()).unwrap_or_default();
|
|
let display_dir = if current_dir.starts_with(&home_dir) {
|
|
current_dir.replacen(&home_dir, "~", 1)
|
|
} else {
|
|
current_dir.to_string()
|
|
};
|
|
|
|
let available_width = area.width as usize;
|
|
let mode_width = UnicodeWidthStr::width(mode_text);
|
|
let program_info_width = UnicodeWidthStr::width(program_info.as_str());
|
|
let fps_text = format!("{:.0} FPS", current_fps);
|
|
let fps_width = UnicodeWidthStr::width(fps_text.as_str());
|
|
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;
|
|
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 }
|
|
);
|
|
|
|
let dir_display_text = if UnicodeWidthStr::width(display_dir.as_str()) <= remaining_width_for_dir {
|
|
display_dir
|
|
} else {
|
|
let dir_name = Path::new(current_dir)
|
|
.file_name()
|
|
.and_then(|n| n.to_str())
|
|
.unwrap_or(current_dir);
|
|
if UnicodeWidthStr::width(dir_name) <= remaining_width_for_dir {
|
|
dir_name.to_string()
|
|
} else {
|
|
dir_name.chars().take(remaining_width_for_dir).collect()
|
|
}
|
|
};
|
|
|
|
let mut spans = vec![
|
|
Span::styled(mode_text, Style::default().fg(theme.accent)),
|
|
Span::styled(" | ", Style::default().fg(theme.border)),
|
|
Span::styled(dir_display_text, Style::default().fg(theme.fg)),
|
|
Span::styled(" | ", Style::default().fg(theme.border)),
|
|
Span::styled(program_info, Style::default().fg(theme.secondary)),
|
|
];
|
|
|
|
if show_fps {
|
|
spans.push(Span::styled(" | ", Style::default().fg(theme.border)));
|
|
spans.push(Span::styled(fps_text, Style::default().fg(theme.secondary)));
|
|
}
|
|
|
|
let paragraph = Paragraph::new(Line::from(spans))
|
|
.style(Style::default().bg(theme.bg));
|
|
|
|
f.render_widget(paragraph, area);
|
|
}
|