Refactor room key binding code a bit
This commit is contained in:
parent
235fd9acc5
commit
10ea7d13fd
1 changed files with 77 additions and 65 deletions
|
|
@ -263,16 +263,7 @@ impl EuphRoom {
|
|||
Text::new(info).into()
|
||||
}
|
||||
|
||||
pub async fn list_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
||||
bindings.heading("Room");
|
||||
|
||||
if !self.popups.is_empty() {
|
||||
bindings.binding("esc", "close popup");
|
||||
return;
|
||||
}
|
||||
|
||||
match &self.state {
|
||||
State::Normal => {
|
||||
pub async fn list_normal_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
||||
bindings.binding("esc", "leave room");
|
||||
|
||||
let can_compose = if let Some(room) = &self.room {
|
||||
|
|
@ -296,27 +287,13 @@ impl EuphRoom {
|
|||
bindings.empty();
|
||||
self.chat.list_key_bindings(bindings, can_compose).await;
|
||||
}
|
||||
State::Auth(_) => auth::list_key_bindings(bindings),
|
||||
State::Nick(_) => nick::list_key_bindings(bindings),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_input_event(
|
||||
async fn handle_normal_input_event(
|
||||
&mut self,
|
||||
terminal: &mut Terminal,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
event: &InputEvent,
|
||||
) -> bool {
|
||||
if !self.popups.is_empty() {
|
||||
if matches!(event, key!(Esc)) {
|
||||
self.popups.pop_back();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
match &self.state {
|
||||
State::Normal => {
|
||||
if let Some(room) = &self.room {
|
||||
let status = room.status().await;
|
||||
let can_compose = matches!(status, Ok(Some(Status::Joined(_))));
|
||||
|
|
@ -359,6 +336,41 @@ impl EuphRoom {
|
|||
.handled()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn list_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
||||
bindings.heading("Room");
|
||||
|
||||
if !self.popups.is_empty() {
|
||||
bindings.binding("esc", "close popup");
|
||||
return;
|
||||
}
|
||||
|
||||
match &self.state {
|
||||
State::Normal => self.list_normal_key_bindings(bindings).await,
|
||||
State::Auth(_) => auth::list_key_bindings(bindings),
|
||||
State::Nick(_) => nick::list_key_bindings(bindings),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_input_event(
|
||||
&mut self,
|
||||
terminal: &mut Terminal,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
event: &InputEvent,
|
||||
) -> bool {
|
||||
if !self.popups.is_empty() {
|
||||
if matches!(event, key!(Esc)) {
|
||||
self.popups.pop_back();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
match &self.state {
|
||||
State::Normal => {
|
||||
self.handle_normal_input_event(terminal, crossterm_lock, event)
|
||||
.await
|
||||
}
|
||||
State::Auth(editor) => {
|
||||
match auth::handle_input_event(terminal, crossterm_lock, event, &self.room, editor)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue