diff --git a/pulse-ui/src/widget/input.rs b/pulse-ui/src/widget/input.rs index 051763e..8393f7e 100644 --- a/pulse-ui/src/widget/input.rs +++ b/pulse-ui/src/widget/input.rs @@ -22,7 +22,12 @@ pub struct Input<'a>(pub &'a str, pub &'a InputState); impl<'a> Widget for Input<'a> { fn render(&self, scope: &mut crate::render::RenderScope) { let mut text = self.1.text.clone(); - text.insert_str(self.1.cursor, "❘"); + if self.1.cursor == text.len() { + text.insert_str(self.1.cursor, "\x1b[47m \x1b[0m"); + } else { + text.insert_str(self.1.cursor + 1, "\x1b[0m"); + text.insert_str(self.1.cursor, "\x1b[47m\x1b[30m"); + } scope.draw_text(0, format!("{}{text}", self.0)); } } @@ -90,7 +95,25 @@ impl InputState { .. }) => { if self.cursor < self.text.len() { - let prev = self.text[..self.cursor+1] + let prev = self.text[..self.cursor + 1] + .char_indices() + .last() + .map(|(i, _)| i) + .unwrap(); + + self.text.remove(prev); + self.cursor = prev; + } + true + } + + Event::Key(KeyEvent { + code: KeyCode::Char('d'), + modifiers, + .. + }) if modifiers.contains(KeyModifiers::CONTROL) => { + if self.cursor < self.text.len() { + let prev = self.text[..self.cursor + 1] .char_indices() .last() .map(|(i, _)| i) diff --git a/src/main.rs b/src/main.rs index d990a7c..3af7ee3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,7 +147,7 @@ impl App for PulseTradeApp { async fn render(&mut self, layout: pulse_ui::layout::Allocation) { layout.draw_frame(0, Outline); - layout.draw(0, format!(" PULSE TRADER v0.1.0")); + layout.draw(0, format!("  PULSE TRADER v{}", env!("CARGO_PKG_VERSION"))); layout.draw(1, Center("LIVE".to_string())); layout.draw(2, Center(format!("14:32:51 UTC"))); layout.draw_frame(3, VLine);