Refactor(treewide): Remove the repl, reuse of e. handling is hard

The event handling is deeply ingrained in the ui code, the commands are
focused around the ui code, in short splitting of the event handling and
command system from the ui is intentionally hard and in my opinion not
really worth it right now.
This commit is contained in:
Benedikt Peetz 2023-07-24 23:38:16 +02:00
parent d88cf810a4
commit b67dbf8e31
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
5 changed files with 9 additions and 76 deletions

View File

@ -7,10 +7,7 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
default = ["cli"] default = ["tui"]
full = ["cli", "tui"]
cli = ["tokio/io-std"]
tui = ["dep:tui", "dep:tui-textarea", "dep:crossterm", "dep:tokio-util", "dep:serde", "dep:indexmap"] tui = ["dep:tui", "dep:tui-textarea", "dep:crossterm", "dep:tokio-util", "dep:serde", "dep:indexmap"]
[dependencies] [dependencies]
@ -18,7 +15,7 @@ clap = { version = "4.3.19", features = ["derive"] }
cli-log = "2.0" cli-log = "2.0"
anyhow = "1.0" anyhow = "1.0"
matrix-sdk = "0.6" matrix-sdk = "0.6"
tokio = { version = "1.29", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.29", features = ["macros", "rt-multi-thread", "io-std"] }
# lua stuff # lua stuff
lua_macros = { path = "./lua_macros" } lua_macros = { path = "./lua_macros" }

View File

@ -11,13 +11,7 @@ pub struct Args {
} }
#[derive(Subcommand, Debug)] #[derive(Subcommand, Debug)]
pub enum Command { pub enum Command {
/// Starts a repl, for the lua interface
#[cfg(feature = "cli")]
#[clap(value_parser)]
Repl {},
/// Starts the main tui client /// Starts the main tui client
#[cfg(feature = "tui")]
#[clap(value_parser)] #[clap(value_parser)]
Start {}, Start {},
} }

View File

@ -1,17 +1,12 @@
//mod app;
//mod ui;
//mod accounts;
mod cli; mod cli;
pub mod event_handler;
#[cfg(feature = "tui")]
mod tui_app; mod tui_app;
#[cfg(feature = "cli")]
mod repl;
use clap::Parser; use clap::Parser;
use crate::cli::{Args, Command}; use crate::cli::{Args, Command};
#[cfg(feature = "tui")]
pub use tui_app::*; pub use tui_app::*;
#[tokio::main] #[tokio::main]
@ -19,20 +14,8 @@ async fn main() -> anyhow::Result<()> {
cli_log::init_cli_log!(); cli_log::init_cli_log!();
let args = Args::parse(); let args = Args::parse();
let command = args.subcommand.unwrap_or( let command = args.subcommand.unwrap_or(Command::Start {});
#[cfg(all(feature = "tui", not(feature = "cli")))]
Command::Start {},
#[cfg(all(feature = "cli", not(feature = "tui")))]
Command::Repl {},
#[cfg(all(feature = "cli", feature = "tui"))]
Command::Start {},
);
match command { match command {
#[cfg(feature = "cli")]
Command::Repl {} => {
repl::run().await?;
}
#[cfg(feature = "tui")]
Command::Start {} => { Command::Start {} => {
let mut app = app::App::new()?; let mut app = app::App::new()?;
app.run().await?; app.run().await?;

View File

@ -1,41 +0,0 @@
use std::io::ErrorKind;
use anyhow::{Context, Result};
use cli_log::{info, warn};
use tokio::io::{stdin, stdout, AsyncReadExt, AsyncWriteExt};
pub async fn run() -> Result<()> {
let mut stdin = stdin();
let mut stdout = stdout();
let mut buffer = [0; 1];
let mut new_command = vec![];
loop {
stdout
.write("trinitrix:> ".as_bytes())
.await
.context("Failed to write prompt")?;
stdout.flush().await.context("Failed to flush prompt")?;
new_command.clear();
loop {
if let Err(err) = stdin.read_exact(&mut buffer).await {
if err.kind() == ErrorKind::UnexpectedEof {
warn!("Unexpected EOF, we assume the user quit.");
return Ok(());
} else {
Err(err).context("Failed to read next character")?;
}
}
if buffer == "\n".as_bytes() {
break;
} else {
new_command.append(&mut buffer.to_vec());
}
}
info!(
"Got user repl input: {}",
String::from_utf8(new_command.clone())
.context("Failed to convert user input to utf8 string")?
)
}
}

View File

@ -2,6 +2,6 @@ pub mod app;
pub mod ui; pub mod ui;
pub mod accounts; pub mod accounts;
pub use app::*; //pub use app::*;
pub use ui::*; //pub use ui::*;
pub use accounts::*; //pub use accounts::*;