add ui module

This commit is contained in:
Dr. Matthias Ratajczak
2022-12-02 16:32:08 +01:00
parent 7cd415985d
commit be3e2af1ef
5 changed files with 27 additions and 13 deletions
Generated
+7
View File
@@ -21,6 +21,12 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "anyhow"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@@ -357,6 +363,7 @@ name = "pacdef"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"alpm", "alpm",
"anyhow",
"clap 3.2.20", "clap 3.2.20",
"criterion", "criterion",
] ]
+1
View File
@@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
alpm = "2.2.1" alpm = "2.2.1"
anyhow = "1.0.66"
clap = "3.2.20" clap = "3.2.20"
[profile.release] [profile.release]
+1
View File
@@ -2,6 +2,7 @@ pub mod args;
pub mod db; pub mod db;
pub mod group; pub mod group;
pub mod package; pub mod package;
pub mod ui;
pub use group::Group; pub use group::Group;
pub use package::Package; pub use package::Package;
+4 -13
View File
@@ -1,10 +1,9 @@
use std::io::BufRead;
use std::io::Write;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::exit; use std::process::exit;
use std::{collections::HashSet, process::Command}; use std::{collections::HashSet, process::Command};
use anyhow::Result;
use clap::ArgMatches; use clap::ArgMatches;
use pacdef::args; use pacdef::args;
@@ -13,20 +12,12 @@ use pacdef::group::GROUPS_DIR;
use pacdef::Group; use pacdef::Group;
use pacdef::Package; use pacdef::Package;
fn main() { fn main() -> Result<()> {
let args = args::get_matched_arguments(); let args = args::get_matched_arguments();
let groups = Group::load_from_dir(); let groups = Group::load_from_dir();
let pacdef = Pacdef::new(args, groups); let pacdef = Pacdef::new(args, groups);
pacdef.run_action_from_arg(); pacdef.run_action_from_arg();
} Ok(())
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)
}
} }
fn run_edit_command(files: &[&Path]) { fn run_edit_command(files: &[&Path]) {
@@ -94,7 +85,7 @@ impl Pacdef {
println!(" {p}"); println!(" {p}");
} }
println!(); println!();
get_user_confirmation(); pacdef::ui::get_user_confirmation();
run_install_command(diff); run_install_command(diff);
} }
+14
View File
@@ -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)
}
}