refactor (events): switched back from tui_textarea input events to raw crossterm events

This commit is contained in:
antifallobst 2023-07-09 22:51:57 +02:00
parent 1fa35adae7
commit 7347d0c4f1
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
1 changed files with 41 additions and 43 deletions

View File

@ -1,5 +1,6 @@
use anyhow::{Error, Result};
use cli_log::{error, info, warn};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use matrix_sdk::{
config::SyncSettings,
room::Room,
@ -116,25 +117,23 @@ impl Event {
async fn handle_main(&self, app: &mut App<'_>) -> Result<EventStatus> {
if self.input_event.is_some() {
match tui_textarea::Input::from(self.input_event.clone().unwrap()) {
tui_textarea::Input {
key: tui_textarea::Key::Esc,
..
} => return Ok(EventStatus::Terminate),
tui_textarea::Input {
key: tui_textarea::Key::Tab,
..
} => {
match self.input_event.clone().unwrap() {
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Esc, ..
}) => return Ok(EventStatus::Terminate),
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Tab, ..
}) => {
app.ui.cycle_main_input_position();
}
input => match app.ui.input_position() {
ui::MainInputPosition::MessageCompose => {
match input {
tui_textarea::Input {
key: tui_textarea::Key::Enter,
alt: true,
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Enter,
modifiers: KeyModifiers::ALT,
..
} => {
}) => {
match app.status.room_mut() {
Some(room) => {
room.send(app.ui.message_compose.lines().join("\n"))
@ -145,16 +144,17 @@ impl Event {
};
}
_ => {
app.ui.message_compose.input(input);
app.ui
.message_compose
.input(tui_textarea::Input::from(input));
}
};
}
ui::MainInputPosition::Rooms => {
match input {
tui_textarea::Input {
key: tui_textarea::Key::Up,
..
} => {
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Up, ..
}) => {
let i = match app.ui.rooms_state.selected() {
Some(cur) => {
if cur > 0 {
@ -168,10 +168,10 @@ impl Event {
app.ui.rooms_state.select(Some(i));
app.status.set_room_by_index(i)?;
}
tui_textarea::Input {
key: tui_textarea::Key::Down,
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Down,
..
} => {
}) => {
let i = match app.ui.rooms_state.selected() {
Some(cur) => {
if cur < app.status.rooms().len() - 1 {
@ -190,10 +190,9 @@ impl Event {
}
ui::MainInputPosition::Messages => {
match input {
tui_textarea::Input {
key: tui_textarea::Key::Up,
..
} => {
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Up, ..
}) => {
match app.status.room_mut() {
Some(room) => {
let len = room.timeline().len();
@ -211,10 +210,10 @@ impl Event {
None => (),
};
}
tui_textarea::Input {
key: tui_textarea::Key::Down,
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Down,
..
} => {
}) => {
match app.status.room_mut() {
Some(room) => {
match room.view_scroll() {
@ -248,21 +247,19 @@ impl Event {
};
if self.input_event.is_some() {
match tui_textarea::Input::from(self.input_event.clone().unwrap()) {
tui_textarea::Input {
key: tui_textarea::Key::Esc,
..
} => return Ok(EventStatus::Terminate),
tui_textarea::Input {
key: tui_textarea::Key::Tab,
..
} => {
match self.input_event.clone().unwrap() {
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Esc, ..
}) => return Ok(EventStatus::Terminate),
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Tab, ..
}) => {
ui.cycle_input_position();
}
tui_textarea::Input {
key: tui_textarea::Key::Enter,
crossterm::event::Event::Key(KeyEvent {
code: KeyCode::Enter,
..
} => {
}) => {
match ui.input_position() {
ui::SetupInputPosition::Ok => {
let homeserver = ui.homeserver.lines()[0].clone();
@ -284,8 +281,9 @@ impl Event {
ui.username.input(input);
}
ui::SetupInputPosition::Password => {
ui.password_data.input(input.clone());
match input.key {
let textarea_input = tui_textarea::Input::from(input);
ui.password_data.input(textarea_input.clone());
match textarea_input.key {
tui_textarea::Key::Char(_) => {
ui.password.input(tui_textarea::Input {
key: tui_textarea::Key::Char('*'),
@ -294,7 +292,7 @@ impl Event {
});
}
_ => {
ui.password.input(input);
ui.password.input(textarea_input);
}
}
}