From 3df860f3fd2d472d3343e0fb6a70a31a1b1e16bd Mon Sep 17 00:00:00 2001 From: filipriec Date: Sun, 16 Feb 2025 22:40:58 +0100 Subject: [PATCH] improvements, cursor got scuffed in form.rs --- src/client/components/command_line.rs | 2 +- src/client/components/form.rs | 32 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/client/components/command_line.rs b/src/client/components/command_line.rs index 38f3cc6..297a3a2 100644 --- a/src/client/components/command_line.rs +++ b/src/client/components/command_line.rs @@ -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)" }; diff --git a/src/client/components/form.rs b/src/client/components/form.rs index c82d0e6..ce27f50 100644 --- a/src/client/components/form.rs +++ b/src/client/components/form.rs @@ -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 + } } }