improvements, cursor got scuffed in form.rs

This commit is contained in:
filipriec
2025-02-16 22:40:58 +01:00
parent 0fb67d7f58
commit 3df860f3fd
2 changed files with 26 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ use crate::client::colors::Theme;
pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme) {
let prompt = if active {
": (w = save, q = quit)"
":"
} else {
"Press ':' for commands (w = save, q = quit)"
};

View File

@@ -3,7 +3,7 @@ use ratatui::{
widgets::{Paragraph, Block, Borders},
layout::{Layout, Constraint, Direction, Rect, Margin},
style::Style,
text::{Line, Span},
text::{Line, Span, Text},
Frame,
};
use crate::client::colors::Theme;
@@ -52,15 +52,33 @@ pub fn render_form(
let label = Paragraph::new(Line::from(Span::styled(
field.to_string(),
Style::default().fg(theme.fg),
))); // Fixed: Added the missing closing parenthesis
)));
f.render_widget(label, row_chunks[0]);
// Render the input on the right
let input_paragraph = Paragraph::new(input.as_str()).style(if is_active {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.fg)
});
let input_block = Block::default()
.borders(if is_active {
Borders::ALL // Add a border around the active field
} else {
Borders::NONE
})
.border_style(Style::default().fg(theme.accent)); // Use the accent color for the border
let input_paragraph = Paragraph::new(input.as_str())
.block(input_block)
.style(if is_active {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.fg)
});
f.render_widget(input_paragraph, row_chunks[1]);
// Render the cursor in the active field
if is_active {
let cursor_x = row_chunks[1].x + input.len() as u16 + 1; // Calculate cursor position
let cursor_y = row_chunks[1].y;
f.set_cursor(cursor_x, cursor_y); // Set the cursor position
}
}
}