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()
|
Text::new(info).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_key_bindings(&self, bindings: &mut KeyBindingsList) {
|
pub async fn list_normal_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 => {
|
|
||||||
bindings.binding("esc", "leave room");
|
bindings.binding("esc", "leave room");
|
||||||
|
|
||||||
let can_compose = if let Some(room) = &self.room {
|
let can_compose = if let Some(room) = &self.room {
|
||||||
|
|
@ -296,27 +287,13 @@ impl EuphRoom {
|
||||||
bindings.empty();
|
bindings.empty();
|
||||||
self.chat.list_key_bindings(bindings, can_compose).await;
|
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,
|
&mut self,
|
||||||
terminal: &mut Terminal,
|
terminal: &mut Terminal,
|
||||||
crossterm_lock: &Arc<FairMutex<()>>,
|
crossterm_lock: &Arc<FairMutex<()>>,
|
||||||
event: &InputEvent,
|
event: &InputEvent,
|
||||||
) -> bool {
|
) -> 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 {
|
if let Some(room) = &self.room {
|
||||||
let status = room.status().await;
|
let status = room.status().await;
|
||||||
let can_compose = matches!(status, Ok(Some(Status::Joined(_))));
|
let can_compose = matches!(status, Ok(Some(Status::Joined(_))));
|
||||||
|
|
@ -359,6 +336,41 @@ impl EuphRoom {
|
||||||
.handled()
|
.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) => {
|
State::Auth(editor) => {
|
||||||
match auth::handle_input_event(terminal, crossterm_lock, event, &self.room, editor)
|
match auth::handle_input_event(terminal, crossterm_lock, event, &self.room, editor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue