working cursor perfectly well, lets polish it
This commit is contained in:
@@ -8,3 +8,7 @@ enter_edit_mode = ["i", "ctrl+e"]
|
||||
exit_edit_mode = ["esc", "ctrl+e"]
|
||||
previous_position = ["Left", "9"]
|
||||
next_position = ["Right", "8"]
|
||||
move_left = ["h", "Left"]
|
||||
move_right = ["l", "Right"]
|
||||
move_up = ["k", "Up"]
|
||||
move_down = ["j", "Down"]
|
||||
|
||||
@@ -126,5 +126,18 @@ pub fn render_form(
|
||||
let cursor_y = input_rows[i].y;
|
||||
f.set_cursor(cursor_x, cursor_y);
|
||||
}
|
||||
if is_active {
|
||||
if is_edit_mode {
|
||||
// Edit mode: vertical line at end of input
|
||||
let cursor_x = input_rows[i].x + input.len() as u16;
|
||||
let cursor_y = input_rows[i].y;
|
||||
f.set_cursor(cursor_x, cursor_y);
|
||||
} else {
|
||||
// Read-only mode: block at start of field
|
||||
let cursor_x = input_rows[i].x;
|
||||
let cursor_y = input_rows[i].y;
|
||||
f.set_cursor(cursor_x, cursor_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use crossterm::{
|
||||
execute,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use crossterm::cursor::{SetCursorStyle, EnableBlinking};
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use std::io::{self, stdout};
|
||||
use tonic::transport::Channel;
|
||||
@@ -20,10 +21,23 @@ pub struct AppTerminal {
|
||||
}
|
||||
|
||||
impl AppTerminal {
|
||||
pub fn set_cursor_style(&mut self, style: SetCursorStyle) -> Result<(), Box<dyn std::error::Error>> {
|
||||
execute!(
|
||||
self.terminal.backend_mut(),
|
||||
style,
|
||||
EnableBlinking,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = stdout();
|
||||
execute!(stdout, EnterAlternateScreen)?;
|
||||
execute!(
|
||||
stdout,
|
||||
EnterAlternateScreen,
|
||||
SetCursorStyle::SteadyBlock
|
||||
)?;
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let terminal = Terminal::new(backend)?;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// src/client/ui/handlers/event.rs
|
||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
||||
use crossterm::cursor::{SetCursorStyle};
|
||||
use crate::client::terminal::AppTerminal;
|
||||
use crate::client::config::Config;
|
||||
use crate::proto::multieko2::{PostAdresarRequest, PutAdresarRequest};
|
||||
@@ -39,6 +40,7 @@ impl EventHandler {
|
||||
self.is_edit_mode = true;
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Edit mode".to_string();
|
||||
app_terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?; // Add this line
|
||||
return Ok((false, self.command_message.clone()));
|
||||
} else if self.is_edit_mode && config.is_exit_edit_mode(key.code, key.modifiers) {
|
||||
// Prevent exiting edit mode if there are unsaved changes
|
||||
@@ -49,6 +51,7 @@ impl EventHandler {
|
||||
self.is_edit_mode = false;
|
||||
self.edit_mode_cooldown = true;
|
||||
self.command_message = "Read-only mode".to_string();
|
||||
app_terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; // Add this line
|
||||
return Ok((false, self.command_message.clone()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user