aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar lancebord 2026-03-08 00:22:40 -0500
committerGravatar lancebord 2026-03-08 00:22:40 -0500
commit6a3363d915a3677b701abd077b1082b32f2cd29b (patch)
tree6ab03a0861c0c86be3a9ef88d57e9a7296e9881b
parentmake chat box expand for multi line message (diff)
command line args for config
-rw-r--r--Cargo.lock109
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs54
3 files changed, 142 insertions, 22 deletions
diff --git a/Cargo.lock b/Cargo.lock
index cd4053a..5b9592c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,6 +18,56 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
+name = "anstream"
+version = "0.6.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
+
+[[package]]
+name = "anstyle-parse"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
+dependencies = [
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
+dependencies = [
+ "anstyle",
+ "once_cell_polyfill",
+ "windows-sys 0.61.2",
+]
+
+[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -120,6 +170,52 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
+name = "clap"
+version = "4.5.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.5.60"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.5.55"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "clap_lex"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
+
+[[package]]
+name = "colorchoice"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
+
+[[package]]
name = "compact_str"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -588,6 +684,12 @@ dependencies = [
]
[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+
+[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -830,6 +932,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
+name = "once_cell_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+
+[[package]]
name = "ordered-float"
version = "4.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1338,6 +1446,7 @@ name = "speakez"
version = "0.1.0"
dependencies = [
"bytes",
+ "clap",
"crossterm 0.28.1",
"futures",
"ratatui",
diff --git a/Cargo.toml b/Cargo.toml
index 63a3616..2960a5e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
ratatui = "0.30"
crossterm = "0.28"
unicode-width = "0.2.2"
+clap = { version = "4.5.60", features = ["derive"] }
[dev-dependencies]
tokio-test = "0.4"
diff --git a/src/main.rs b/src/main.rs
index 23a44f8..1f6b972 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,10 @@
+use clap::Parser;
use crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyModifiers},
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use ratatui::{Terminal, backend::CrosstermBackend};
-use std::env;
use std::io;
use std::net::ToSocketAddrs;
use std::time::Duration;
@@ -16,6 +16,25 @@ use tui::app::AppState;
use tui::ui;
mod tui;
+#[derive(Parser, Debug)]
+#[command(version, about, long_about = None)]
+struct Args {
+ #[arg(short, long)]
+ server: String,
+
+ #[arg(short, long, default_value_t = String::new())]
+ nick: String,
+
+ #[arg(short, long, default_value_t = String::from("speakez"))]
+ user: String,
+
+ #[arg(short, long, default_value_t = String::from("speakez"))]
+ realname: String,
+
+ #[arg(short, long, default_value_t = String::new())]
+ pass: String,
+}
+
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
enable_raw_mode()?;
@@ -43,43 +62,37 @@ async fn run(
) -> Result<(), Box<dyn std::error::Error>> {
let mut app = AppState::new();
- let server = match env::args().nth(1) {
- Some(s) => s,
- None => {
- return Err("Usage: speakez <server:port>".into());
- }
- };
-
- if server.to_socket_addrs().is_err() {
+ let args = Args::try_parse()?;
+ if args.server.to_socket_addrs().is_err() {
return Err("Error: could not resolve server".into());
}
+ let password = match args.pass.as_str() {
+ "" => None,
+ _ => Some(args.pass),
+ };
+
// Connect to IRC
let config = Config {
- server,
- nick: "".to_string(),
- user: "speakez".to_string(),
- realname: "speakez".to_string(),
- password: None,
+ server: args.server,
+ nick: args.nick,
+ user: args.user,
+ realname: args.realname,
+ password,
};
let mut client = Client::connect(config).await?;
- // ── Main event loop ───────────────────────────────────────────────────
// We poll both IRC events and keyboard events with short timeouts so
// neither blocks the other.
loop {
- // Draw
terminal.draw(|f| ui::draw(f, &mut app))?;
- // Poll crossterm for keyboard input (non-blocking, 20ms timeout)
if event::poll(Duration::from_millis(20))? {
if let Event::Key(key) = event::read()? {
match (key.modifiers, key.code) {
- // Quit
(KeyModifiers::CONTROL, KeyCode::Char('c')) => break,
- // Send message / command
(_, KeyCode::Enter) => {
let text = app.take_input();
if !text.is_empty() {
@@ -89,7 +102,6 @@ async fn run(
}
}
- // Typing
(KeyModifiers::NONE | KeyModifiers::SHIFT, KeyCode::Char(c)) => {
app.input_insert(c);
}
@@ -105,8 +117,6 @@ async fn run(
}
}
- // Drain IRC events (non-blocking — try_recv drains without waiting)
- // We use a small loop to process a burst without starving the UI
for _ in 0..16 {
match client.next_event_nowait() {
Some(irc_event) => handle_irc_event(irc_event, &mut app),