Compare commits
No commits in common. "33948164c4be0b65b9f4a8965b9f6df72d9378d9" and "327450c64ba8fb6a0b4ce0eb3375847025a17b72" have entirely different histories.
33948164c4
...
327450c64b
|
@ -1,8 +0,0 @@
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum Command {
|
|
||||||
// Closes the application
|
|
||||||
Exit,
|
|
||||||
|
|
||||||
// sends a message to the current room
|
|
||||||
RoomMessageSend(String),
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
use crate::app::{command::Command, events::event_types::EventStatus, App};
|
|
||||||
use anyhow::Result;
|
|
||||||
use cli_log::info;
|
|
||||||
|
|
||||||
pub async fn handle(app: &mut App<'_>, command: &Command) -> Result<EventStatus> {
|
|
||||||
info!("Handling command: {:#?}", command);
|
|
||||||
Ok(EventStatus::Ok)
|
|
||||||
}
|
|
|
@ -27,8 +27,6 @@ pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<E
|
||||||
modifiers: KeyModifiers::CONTROL,
|
modifiers: KeyModifiers::CONTROL,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
app.command_execute(crate::app::command::Command::Exit)
|
|
||||||
.await?;
|
|
||||||
app.ui.cli_enable();
|
app.ui.cli_enable();
|
||||||
}
|
}
|
||||||
input => match app.ui.input_position() {
|
input => match app.ui.input_position() {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod command;
|
|
||||||
pub mod main;
|
|
||||||
pub mod matrix;
|
pub mod matrix;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
pub mod main;
|
||||||
|
|
|
@ -3,9 +3,9 @@ mod handlers;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use crossterm::event::Event as CrosstermEvent;
|
use crossterm::event::Event as CrosstermEvent;
|
||||||
|
|
||||||
use crate::app::{command::Command, status::State, App};
|
use crate::app::{status::State, App};
|
||||||
|
|
||||||
use self::handlers::{command, main, matrix, setup};
|
use self::handlers::{main, matrix, setup};
|
||||||
|
|
||||||
use super::EventStatus;
|
use super::EventStatus;
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ use super::EventStatus;
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub(super) input_event: Option<CrosstermEvent>,
|
pub(super) input_event: Option<CrosstermEvent>,
|
||||||
pub(super) matrix_event: Option<matrix_sdk::deserialized_responses::SyncResponse>,
|
pub(super) matrix_event: Option<matrix_sdk::deserialized_responses::SyncResponse>,
|
||||||
pub(super) command_event: Option<Command>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event {
|
impl Event {
|
||||||
|
@ -24,12 +23,6 @@ impl Event {
|
||||||
.with_context(|| format!("Failed to handle matrix event: `{:#?}`", matrix_event));
|
.with_context(|| format!("Failed to handle matrix event: `{:#?}`", matrix_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(command_event) = &self.command_event {
|
|
||||||
return command::handle(app, command_event).await.with_context(|| {
|
|
||||||
format!("Failed to handle command event: `{:#?}`", command_event)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(input_event) = &self.input_event {
|
if let Some(input_event) = &self.input_event {
|
||||||
let status = match app.status.state() {
|
let status = match app.status.state() {
|
||||||
State::None => EventStatus::Ok,
|
State::None => EventStatus::Ok,
|
||||||
|
|
|
@ -9,7 +9,6 @@ impl Default for Event {
|
||||||
Self {
|
Self {
|
||||||
input_event: None,
|
input_event: None,
|
||||||
matrix_event: None,
|
matrix_event: None,
|
||||||
command_event: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,16 +35,10 @@ impl EventBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command_event(&mut self, command_event: crate::app::command::Command) -> &Self {
|
|
||||||
self.event.command_event = Some(command_event);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build(&self) -> Event {
|
pub fn build(&self) -> Event {
|
||||||
Event {
|
Event {
|
||||||
input_event: self.event.input_event.to_owned(),
|
input_event: self.event.input_event.to_owned(),
|
||||||
matrix_event: self.event.matrix_event.to_owned(),
|
matrix_event: self.event.matrix_event.to_owned(),
|
||||||
command_event: self.event.command_event.to_owned(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod command;
|
|
||||||
pub mod command_interface;
|
pub mod command_interface;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
@ -14,10 +13,9 @@ use status::{State, Status};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use crate::app::command::Command;
|
|
||||||
use crate::{accounts, app::command_interface::generate_ci_functions, ui};
|
use crate::{accounts, app::command_interface::generate_ci_functions, ui};
|
||||||
|
|
||||||
use self::events::event_types::{self, EventBuilder};
|
use self::events::event_types;
|
||||||
|
|
||||||
pub struct App<'ui> {
|
pub struct App<'ui> {
|
||||||
ui: ui::UI<'ui>,
|
ui: ui::UI<'ui>,
|
||||||
|
@ -132,9 +130,7 @@ impl App<'_> {
|
||||||
match event.handle(self).await? {
|
match event.handle(self).await? {
|
||||||
event_types::EventStatus::Ok => (),
|
event_types::EventStatus::Ok => (),
|
||||||
event_types::EventStatus::Finished => return Ok(()),
|
event_types::EventStatus::Finished => return Ok(()),
|
||||||
event_types::EventStatus::Terminate => {
|
event_types::EventStatus::Terminate => return Err(Error::msg("Terminated by user")),
|
||||||
return Err(Error::msg("Terminated by user"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,10 +201,4 @@ impl App<'_> {
|
||||||
pub fn client(&self) -> Option<&Client> {
|
pub fn client(&self) -> Option<&Client> {
|
||||||
self.accounts_manager.client()
|
self.accounts_manager.client()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn command_execute(&self, command: Command) -> Result<()> {
|
|
||||||
let event = EventBuilder::default().command_event(command).build();
|
|
||||||
self.channel_tx.send(event).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue