From d1ea7eb2c008c3ad38736db8a016ae308f95dc59 Mon Sep 17 00:00:00 2001 From: clizia Date: Wed, 14 May 2025 17:57:05 +0200 Subject: [PATCH] textarea shows but doesnt update --- src/ui.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 824ce41..495f16d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -77,12 +77,11 @@ impl Widget for Popup<'_> { async fn handle_key_event(mut client: &mut Client<'_>, key_event: KeyEvent) { match &client.popup_user_input { true => { - match key_event.code { - KeyCode::Esc => client.popup_user_input = false, - KeyCode::Char(c) => { - todo!() + match key_event.into() { + Input {key: Key::Esc, ..} => client.popup_user_input = false, + input => { + client.textarea.input(input); }, - _ => (), } }, false => { @@ -151,10 +150,10 @@ async fn handle_key_event(mut client: &mut Client<'_>, key_event: KeyEvent) { } } -pub async fn handle_events(client: &mut Client<'_>) -> anyhow::Result<()> { +pub async fn handle_events(app: &mut Client<'_>) -> anyhow::Result<()> { match event::read()? { Event::Key(key) if key.kind == KeyEventKind::Press => { - handle_key_event(client, key).await + handle_key_event(app, key).await } _ => () } @@ -243,6 +242,27 @@ pub fn ui(frame: &mut Frame, app: &mut Client) { frame.render_widget(popup, popup_area); } + + let mut textarea = TextArea::default(); + textarea.set_block( + Block::default() + .borders(Borders::ALL) + .border_style(Style::default().fg(Color::LightBlue)) + .title("Crossterm Popup Example"), + ); + + let area = Rect { + width: 40, + height: 5, + x: 5, + y: 5, + }; + + textarea.set_style(Style::default().fg(Color::Yellow)); + textarea.set_placeholder_style(Style::default()); + app.textarea = textarea; + if app.popup_user_input == true { + frame.render_widget(&app.textarea, area); } }