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
Exit,
CommandLineShow,
CommandLineHide,
CyclePlanes,
CyclePlanesRev,
// sends a message to the current room
RoomMessageSend(String),
}

View File

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