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