forked from trinitrix/core
1
0
Fork 0

Feat(Commands): Started actual implementation of commands

List of added commands:
  - Exit
  - CommandLineShow
  - CommandLineHide
  - CyclePlanes
  - CyclePlanesRev
  - RoomMessageSend
This commit is contained in:
antifallobst 2023-07-13 23:17:35 +02:00
parent 33948164c4
commit 529b869e80
Signed by: antifallobst
GPG Key ID: 2B4F402172791BAF
3 changed files with 47 additions and 15 deletions

View File

@ -3,6 +3,12 @@ pub enum Command {
// Closes the application // Closes the application
Exit, Exit,
CommandLineShow,
CommandLineHide,
CyclePlanes,
CyclePlanesRev,
// sends a message to the current room // sends a message to the current room
RoomMessageSend(String), RoomMessageSend(String),
} }

View File

@ -4,5 +4,33 @@ use cli_log::info;
pub async fn handle(app: &mut App<'_>, command: &Command) -> Result<EventStatus> { pub async fn handle(app: &mut App<'_>, command: &Command) -> Result<EventStatus> {
info!("Handling command: {:#?}", command); info!("Handling command: {:#?}", command);
Ok(EventStatus::Ok)
Ok(match command {
Command::Exit => EventStatus::Terminate,
Command::CommandLineShow => {
app.ui.cli_enable();
EventStatus::Ok
}
Command::CommandLineHide => {
app.ui.cli_disable();
EventStatus::Ok
}
Command::CyclePlanes => {
app.ui.cycle_main_input_position();
EventStatus::Ok
}
Command::CyclePlanesRev => {
app.ui.cycle_main_input_position_rev();
EventStatus::Ok
}
Command::RoomMessageSend(msg) => {
if let Some(room) = app.status.room_mut() {
room.send(msg.clone()).await?;
}
EventStatus::Ok
}
})
} }

View File

@ -2,7 +2,7 @@ use anyhow::Result;
use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers}; use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers};
use crate::{ use crate::{
app::{events::event_types::EventStatus, App}, app::{command::Command, events::event_types::EventStatus, App},
ui, ui,
}; };
@ -10,26 +10,26 @@ pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<E
match input_event { match input_event {
CrosstermEvent::Key(KeyEvent { CrosstermEvent::Key(KeyEvent {
code: KeyCode::Esc, .. code: KeyCode::Esc, ..
}) => return Ok(EventStatus::Terminate), }) => {
app.command_execute(Command::Exit).await?;
}
CrosstermEvent::Key(KeyEvent { CrosstermEvent::Key(KeyEvent {
code: KeyCode::Tab, .. code: KeyCode::Tab, ..
}) => { }) => {
app.ui.cycle_main_input_position(); app.command_execute(Command::CyclePlanes).await?;
} }
CrosstermEvent::Key(KeyEvent { CrosstermEvent::Key(KeyEvent {
code: KeyCode::BackTab, code: KeyCode::BackTab,
.. ..
}) => { }) => {
app.ui.cycle_main_input_position_rev(); app.command_execute(Command::CyclePlanesRev).await?;
} }
CrosstermEvent::Key(KeyEvent { CrosstermEvent::Key(KeyEvent {
code: KeyCode::Char('c'), code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL, modifiers: KeyModifiers::CONTROL,
.. ..
}) => { }) => {
app.command_execute(crate::app::command::Command::Exit) app.command_execute(Command::CommandLineShow).await?;
.await?;
app.ui.cli_enable();
} }
input => match app.ui.input_position() { input => match app.ui.input_position() {
ui::MainInputPosition::MessageCompose => { ui::MainInputPosition::MessageCompose => {
@ -39,13 +39,11 @@ pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<E
modifiers: KeyModifiers::ALT, modifiers: KeyModifiers::ALT,
.. ..
}) => { }) => {
match app.status.room_mut() { app.command_execute(Command::RoomMessageSend(
Some(room) => { app.ui.message_compose.lines().join("\n"),
room.send(app.ui.message_compose.lines().join("\n")).await?; ))
app.ui.message_compose_clear(); .await?;
} app.ui.message_compose_clear();
None => (),
};
} }
_ => { _ => {
app.ui app.ui