From be3e2af1efc6fd3eef0d6290128f4608980c2768 Mon Sep 17 00:00:00 2001 From: "Dr. Matthias Ratajczak" Date: Fri, 2 Dec 2022 16:32:08 +0100 Subject: [PATCH] add ui module --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/lib.rs | 1 + src/main.rs | 17 ++++------------- src/ui.rs | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/ui.rs diff --git a/Cargo.lock b/Cargo.lock index 7a6c587..c260955 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + [[package]] name = "atty" version = "0.2.14" @@ -357,6 +363,7 @@ name = "pacdef" version = "0.1.0" dependencies = [ "alpm", + "anyhow", "clap 3.2.20", "criterion", ] diff --git a/Cargo.toml b/Cargo.toml index e74b7bc..8bcefa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] alpm = "2.2.1" +anyhow = "1.0.66" clap = "3.2.20" [profile.release] diff --git a/src/lib.rs b/src/lib.rs index 7e905b0..3a0e40f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod args; pub mod db; pub mod group; pub mod package; +pub mod ui; pub use group::Group; pub use package::Package; diff --git a/src/main.rs b/src/main.rs index 3eb82c1..280653d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,9 @@ -use std::io::BufRead; -use std::io::Write; use std::os::unix::process::CommandExt; use std::path::{Path, PathBuf}; use std::process::exit; use std::{collections::HashSet, process::Command}; +use anyhow::Result; use clap::ArgMatches; use pacdef::args; @@ -13,20 +12,12 @@ use pacdef::group::GROUPS_DIR; use pacdef::Group; use pacdef::Package; -fn main() { +fn main() -> Result<()> { let args = args::get_matched_arguments(); let groups = Group::load_from_dir(); let pacdef = Pacdef::new(args, groups); pacdef.run_action_from_arg(); -} - -fn get_user_confirmation() { - print!("Continue? [Y/n] "); - std::io::stdout().flush().unwrap(); - let reply = std::io::stdin().lock().lines().next().unwrap().unwrap(); - if !(reply.is_empty() || reply.to_lowercase().contains('y')) { - exit(0) - } + Ok(()) } fn run_edit_command(files: &[&Path]) { @@ -94,7 +85,7 @@ impl Pacdef { println!(" {p}"); } println!(); - get_user_confirmation(); + pacdef::ui::get_user_confirmation(); run_install_command(diff); } diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 0000000..d3f98d7 --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,14 @@ +use std::process::exit; + +use std::io::Write::std::io; + +use std; + +pub(crate) fn get_user_confirmation() { + print!("Continue? [Y/n] "); + std::io::stdout().flush().unwrap(); + let reply = std::io::stdin().lock().lines().next().unwrap().unwrap(); + if !(reply.is_empty() || reply.to_lowercase().contains('y')) { + exit(0) + } +}