diff --git a/Cargo.toml b/Cargo.toml index cdb424b..51d8ce6 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "contego" -description = "CLI tool for file transfer" +description = "CLI tool for quick file transfers" version = "0.3.0" edition = "2021" diff --git a/docs/contego-dark.png b/docs/contego-dark.png deleted file mode 100644 index d53b3f3..0000000 Binary files a/docs/contego-dark.png and /dev/null differ diff --git a/docs/contego-light.png b/docs/contego-light.png deleted file mode 100644 index db88af9..0000000 Binary files a/docs/contego-light.png and /dev/null differ diff --git a/src/main.rs b/src/main.rs index f654ec4..8d455bf 100755 --- a/src/main.rs +++ b/src/main.rs @@ -6,11 +6,11 @@ use contego::{ client::Client, parser::{addr_parser, dirpath_parser, filepath_parser}, server::Server, - util::{filepaths, handle_exit, metadata, Ip}, + util::{ascii, filepaths, metadata, Ip}, }; use env_logger::Env; -use log::error; -use tokio::sync::mpsc; +use log::{error, info}; +use tokio::{signal, sync::mpsc}; #[derive(Debug, Parser)] #[command(about, version)] @@ -60,6 +60,8 @@ enum Commands { #[tokio::main] async fn main() -> Result<(), Box> { + ascii(); + env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); let cli = Cli::parse(); @@ -92,7 +94,13 @@ async fn main() -> Result<(), Box> { }; }); - handle_exit(tx).await?; + match signal::ctrl_c().await { + Ok(_) => { + tx.send(()).await?; + info!("Captured Ctrl+C, shutting down"); + } + Err(_) => error!("Failed to listen for a Ctrl+C event"), + }; } Commands::Connect { addr, out, key } => { let client = Client::new(addr, key, out); diff --git a/src/util.rs b/src/util.rs index d847247..062e2a8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,15 +1,7 @@ -use std::{ - collections::HashMap, - env, - error::Error, - fs, - io::{stdin, Read}, - net::SocketAddr, - path::PathBuf, -}; +use std::{collections::HashMap, env, error::Error, fs, net::SocketAddr, path::PathBuf}; use log::{debug, info}; -use tokio::{fs::File, io::BufWriter, sync::mpsc::Sender}; +use tokio::{fs::File, io::BufWriter}; use crate::crypto; @@ -127,20 +119,12 @@ pub async fn new_file( Ok((BufWriter::new(handle), path)) } -pub async fn handle_exit(tx: Sender<()>) -> Result<(), Box> { - let mut stdin = stdin().lock().bytes(); - - loop { - let k = match stdin.next() { - None => continue, - Some(k) => k?, - }; - - if k == b'q' { - tx.send(()).await?; - break; - } - } - - Ok(()) +pub fn ascii() { + let ascii = " __ + _________ ____ / /____ ____ _____ + / ___/ __ \\/ __ \\/ __/ _ \\/ __ `/ __ \\ +/ /__/ /_/ / / / / /_/ __/ /_/ / /_/ / +\\___/\\____/_/ /_/\\__/\\___/\\__, /\\____/ + /____/ "; + println!("{}\n", ascii); }