overriding overflows by using empty spaces as letters
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// src/client/components/command_line.rs
|
||||
// src/components/common/command_line.rs
|
||||
|
||||
use ratatui::{
|
||||
widgets::{Block, Paragraph},
|
||||
style::Style,
|
||||
@@ -6,6 +7,8 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
use unicode_width::UnicodeWidthStr; // Import for width calculation
|
||||
|
||||
pub fn render_command_line(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
@@ -13,33 +16,54 @@ pub fn render_command_line(
|
||||
active: bool, // This is event_handler.command_mode
|
||||
theme: &Theme,
|
||||
message: &str, // This is event_handler.command_message
|
||||
// Palette-specific parameters are removed
|
||||
) {
|
||||
// This function now only renders the normal command line.
|
||||
// The find_file_palette_active check in render_ui ensures this is called appropriately.
|
||||
|
||||
if !active { // If not in normal command mode, render minimally or nothing
|
||||
let paragraph = Paragraph::new("")
|
||||
.block(Block::default().style(Style::default().bg(theme.bg)));
|
||||
f.render_widget(paragraph, area);
|
||||
return;
|
||||
}
|
||||
|
||||
let prompt = ":";
|
||||
let display_text = if message.is_empty() || message == ":" {
|
||||
format!("{}{}", prompt, input)
|
||||
} else {
|
||||
if input.is_empty() { // If command was just executed, input is cleared, show message
|
||||
// Original logic for determining display_text
|
||||
let display_text = if !active {
|
||||
// If not in normal command mode, but there's a message (e.g. from Find File palette closing)
|
||||
// Or if command mode is off and message is empty (render minimally)
|
||||
if message.is_empty() {
|
||||
"".to_string() // Render an empty string, background will cover
|
||||
} else {
|
||||
message.to_string()
|
||||
} else { // Show input and message
|
||||
format!("{}{} | {}", prompt, input, message)
|
||||
}
|
||||
} else { // active is true (normal command mode)
|
||||
let prompt = ":";
|
||||
if message.is_empty() || message == ":" {
|
||||
format!("{}{}", prompt, input)
|
||||
} else {
|
||||
if input.is_empty() { // If command was just executed, input is cleared, show message
|
||||
message.to_string()
|
||||
} else { // Show input and message
|
||||
format!("{}{} | {}", prompt, input, message)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let style = Style::default().fg(theme.accent); // Style for active command line
|
||||
let paragraph = Paragraph::new(display_text)
|
||||
.block(Block::default().style(Style::default().bg(theme.bg)))
|
||||
.style(style);
|
||||
let content_width = UnicodeWidthStr::width(display_text.as_str());
|
||||
let available_width = area.width as usize;
|
||||
let padding_needed = available_width.saturating_sub(content_width);
|
||||
|
||||
let display_text_padded = if padding_needed > 0 {
|
||||
format!("{}{}", display_text, " ".repeat(padding_needed))
|
||||
} else {
|
||||
// If text is too long, ratatui's Paragraph will handle truncation.
|
||||
// We could also truncate here if specific behavior is needed:
|
||||
// display_text.chars().take(available_width).collect::<String>()
|
||||
display_text
|
||||
};
|
||||
|
||||
// Determine style based on active state, but apply to the whole paragraph
|
||||
let text_style = if active {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
// If not active, but there's a message, use default foreground.
|
||||
// If message is also empty, this style won't matter much for empty text.
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
|
||||
let paragraph = Paragraph::new(display_text_padded)
|
||||
.block(Block::default().style(Style::default().bg(theme.bg))) // Block ensures bg for whole area
|
||||
.style(text_style); // Style for the text itself
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// src/components/common/status_line.rs
|
||||
use ratatui::{
|
||||
style::Style,
|
||||
layout::Rect,
|
||||
@@ -35,43 +36,62 @@ pub fn render_status_line(
|
||||
let separator = " | ";
|
||||
let separator_width = UnicodeWidthStr::width(separator);
|
||||
|
||||
let fixed_width_with_fps = mode_width + separator_width + separator_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 show_fps = fixed_width_with_fps <= available_width; // Use <= to show if it fits exactly
|
||||
|
||||
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 }
|
||||
mode_width + separator_width + // after mode
|
||||
separator_width + program_info_width + // after program_info
|
||||
if show_fps { separator_width + fps_width } else { 0 } // after fps
|
||||
);
|
||||
|
||||
let dir_display_text = if UnicodeWidthStr::width(display_dir.as_str()) <= remaining_width_for_dir {
|
||||
display_dir
|
||||
// Original directory display logic
|
||||
let dir_display_text_str = if UnicodeWidthStr::width(display_dir.as_str()) <= remaining_width_for_dir {
|
||||
display_dir // display_dir is already a String here
|
||||
} else {
|
||||
let dir_name = Path::new(current_dir)
|
||||
let dir_name = Path::new(current_dir) // Use original current_dir for path logic
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or(current_dir);
|
||||
.unwrap_or(current_dir); // Fallback to current_dir if no filename
|
||||
if UnicodeWidthStr::width(dir_name) <= remaining_width_for_dir {
|
||||
dir_name.to_string()
|
||||
} else {
|
||||
dir_name.chars().take(remaining_width_for_dir).collect()
|
||||
dir_name.chars().take(remaining_width_for_dir).collect::<String>()
|
||||
}
|
||||
};
|
||||
|
||||
let mut spans = vec![
|
||||
// Calculate current content width based on what will be displayed
|
||||
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;
|
||||
}
|
||||
|
||||
let mut line_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)),
|
||||
Span::styled(separator, Style::default().fg(theme.border)),
|
||||
Span::styled(dir_display_text_str.as_str(), Style::default().fg(theme.fg)),
|
||||
Span::styled(separator, Style::default().fg(theme.border)),
|
||||
Span::styled(program_info.as_str(), 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)));
|
||||
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 paragraph = Paragraph::new(Line::from(spans))
|
||||
// Calculate padding
|
||||
let padding_needed = available_width.saturating_sub(current_content_width);
|
||||
if padding_needed > 0 {
|
||||
line_spans.push(Span::styled(
|
||||
" ".repeat(padding_needed),
|
||||
Style::default().bg(theme.bg), // Ensure padding uses background color
|
||||
));
|
||||
}
|
||||
|
||||
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