diff options
author | Orhun Parmaksız <orhunparmaksiz@gmail.com> | 2022-09-29 22:30:49 +0200 |
---|---|---|
committer | Orhun Parmaksız <orhunparmaksiz@gmail.com> | 2022-09-29 22:30:49 +0200 |
commit | 2e212ef71e62b8e00588c2f7bc1420632012363e (patch) | |
tree | b6ae180e6b39f05e08a55422a238559880f803df | |
parent | f38df230b800e7914ace439039130195ed84ba02 (diff) |
chore: Upgrade dependencies
-rw-r--r-- | Cargo.lock | 159 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | src/app.rs | 31 | ||||
-rw-r--r-- | src/kernel/lkm.rs | 11 | ||||
-rw-r--r-- | src/kernel/mod.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 52 | ||||
-rw-r--r-- | src/style.rs | 20 | ||||
-rw-r--r-- | src/util.rs | 67 |
8 files changed, 168 insertions, 185 deletions
@@ -3,15 +3,6 @@ version = 3 [[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - -[[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -23,12 +14,6 @@ dependencies = [ ] [[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - -[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -60,17 +45,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.33.3" +version = "4.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "7f78ad8e84aa8e8aa3e821857be40eb4b925ff232de430d4dd2ae6aa058cbd92" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_lex", "strsim", - "textwrap", - "unicode-width", - "vec_map", + "termcolor", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -97,24 +89,24 @@ dependencies = [ [[package]] name = "colorsys" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dfdf9179d546b55ff3f88c9d93ecfaa3e9760163da5a1080af5243230dbbb70" +checksum = "52c2ad453c82bd637e3969dc52f06676610db0b20c607bf0634c7e9d840789e8" [[package]] name = "enum-iterator" -version = "0.7.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eeac5c5edb79e4e39fe8439ef35207780a11f69c52cbe424ce3dfad4cb78de6" +checksum = "91a4ec26efacf4aeff80887a175a419493cb6f8b5480d26387eb0bd038976187" dependencies = [ "enum-iterator-derive", ] [[package]] name = "enum-iterator-derive" -version = "0.7.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" +checksum = "828de45d0ca18782232dfb8f3ea9cc428e8ced380eb26a520baaacfc70de39ce" dependencies = [ "proc-macro2", "quote", @@ -122,16 +114,6 @@ dependencies = [ ] [[package]] -name = "enum-unitary" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e37680fdbcd5b46ecedf01e04d05e4d7345ff71482950cb05196526631ef12cb" -dependencies = [ - "enum-iterator", - "num-traits", -] - -[[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -149,7 +131,6 @@ dependencies = [ "clipboard", "colorsys", "enum-iterator", - "enum-unitary", "termion", "tui", "unicode-width", @@ -157,15 +138,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.106" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -180,15 +161,6 @@ dependencies = [ ] [[package]] -name = "num-traits" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -dependencies = [ - "autocfg", -] - -[[package]] name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -224,28 +196,34 @@ dependencies = [ ] [[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + +[[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -261,19 +239,28 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.81" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", ] [[package]] @@ -289,19 +276,10 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] name = "tui" -version = "0.16.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c8ce4e27049eed97cfa363a5048b09d995e209994634a0efc26a14ab6c0c23" +checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" dependencies = [ "bitflags", "cassowary", @@ -311,28 +289,22 @@ dependencies = [ ] [[package]] -name = "unicode-segmentation" -version = "1.8.0" +name = "unicode-ident" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-segmentation" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] -name = "vec_map" -version = "0.8.2" +name = "unicode-width" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "winapi" @@ -351,6 +323,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -14,15 +14,14 @@ include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md"] edition = "2021" [dependencies] -clap = "2.33.3" -tui = "0.16.0" +tui = { version = "0.19.0", default-features = false, features = ["termion"] } termion = "1.5.6" bytesize = "1.1.0" -unicode-width = "0.1.9" -enum-unitary = "0.4.3" -enum-iterator = "0.7.0" +unicode-width = "0.1.10" clipboard = "0.5.0" -colorsys = "0.6.5" +colorsys = "0.6.6" +enum-iterator = "1.2.0" +clap = "4.0.4" [profile.dev] opt-level = 0 @@ -7,7 +7,7 @@ use crate::style::{Style, StyledText, Symbol}; use crate::util; use crate::widgets::StatefulList; use clipboard::{ClipboardContext, ClipboardProvider}; -use enum_unitary::{enum_unitary, Bounded, EnumUnitary}; +use enum_iterator::Sequence; use std::error::Error; use std::fmt::{Debug, Display, Formatter}; use std::slice::Iter; @@ -69,14 +69,13 @@ impl ScrollDirection { } /* Main blocks of the terminal */ -enum_unitary! { - #[derive(Copy, Debug, PartialEq, Eq)] - pub enum Block { - UserInput, - ModuleTable, - ModuleInfo, - Activities, - } + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)] +pub enum Block { + UserInput, + ModuleTable, + ModuleInfo, + Activities, } /* Sizes of the terminal blocks */ @@ -98,13 +97,11 @@ impl Default for BlockSize { } /* User input mode */ -enum_unitary! { - #[derive(Copy, Debug, PartialEq, Eq)] - pub enum InputMode { - None, - Search, - Load, - } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Sequence)] +pub enum InputMode { + None, + Search, + Load, } impl InputMode { @@ -123,7 +120,7 @@ impl Display for InputMode { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let mut input_mode = *self; if input_mode.is_none() { - input_mode = match InputMode::min_value().next_variant() { + input_mode = match InputMode::first().and_then(|v| v.next()) { Some(v) => v, None => input_mode, } diff --git a/src/kernel/lkm.rs b/src/kernel/lkm.rs index cc8156f..081ae9d 100644 --- a/src/kernel/lkm.rs +++ b/src/kernel/lkm.rs @@ -47,12 +47,12 @@ impl ListArgs { * @param ArgMatches * @return ListArgs */ - pub fn new(args: &ArgMatches<'_>) -> Self { + pub fn new(args: &ArgMatches) -> Self { let mut sort_type = SortType::None; - if let Some(matches) = args.subcommand_matches("sort") { - if matches.is_present("size") { + if let Some(("sort", matches)) = args.subcommand() { + if matches.get_flag("size") { sort_type = SortType::Size; - } else if matches.is_present("dependent") { + } else if matches.get_flag("dependent") { sort_type = SortType::Dependent; } else { sort_type = SortType::Name; @@ -60,7 +60,8 @@ impl ListArgs { } Self { sort: sort_type, - reverse: args.is_present("reverse"), + reverse: args.try_get_one::<bool>("reverse").ok().flatten() + == Some(&true), } } } diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 034f02c..af358df 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -22,7 +22,7 @@ impl Kernel { * @param ArgMatches * @return Kernel */ - pub fn new(args: &ArgMatches<'_>) -> Self { + pub fn new(args: &ArgMatches) -> Self { Self { logs: KernelLogs::default(), info: KernelInfo::new(), diff --git a/src/main.rs b/src/main.rs index 707d4cc..2ec33a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ mod widgets; mod util; mod style; use app::{App, Block, InputMode, ScrollDirection}; -use enum_unitary::{Bounded, EnumUnitary}; +use enum_iterator::Sequence; use event::{Event, Events}; use kernel::cmd::ModuleCommand; use kernel::Kernel; @@ -202,19 +202,18 @@ where } /* Select the next terminal block. */ Key::Left | Key::Char('h') | Key::Char('H') => { - app.selected_block = - match app.selected_block.prev_variant() { - Some(v) => v, - None => Block::max_value(), - } + app.selected_block = match app.selected_block.previous() + { + Some(v) => v, + None => Block::last().unwrap(), + } } /* Select the previous terminal block. */ Key::Right | Key::Char('l') | Key::Char('L') => { - app.selected_block = - match app.selected_block.next_variant() { - Some(v) => v, - None => Block::min_value(), - } + app.selected_block = match app.selected_block.next() { + Some(v) => v, + None => Block::first().unwrap(), + } } /* Expand the selected block. */ Key::Alt('e') => { @@ -448,22 +447,22 @@ where } /* Switch to the previous input mode. */ Key::Up => { - app.input_mode = match app.input_mode.prev_variant() { + app.input_mode = match app.input_mode.previous() { Some(v) => v, - None => InputMode::max_value(), + None => InputMode::last().unwrap(), }; if app.input_mode.is_none() { - app.input_mode = InputMode::max_value(); + app.input_mode = InputMode::last().unwrap(); } app.input_query = String::new(); } /* Switch to the next input mode. */ Key::Down => { - app.input_mode = match app.input_mode.next_variant() { + app.input_mode = match app.input_mode.next() { Some(v) => v, - None => { - InputMode::min_value().next_variant().unwrap() - } + None => InputMode::first() + .and_then(|v| v.next()) + .unwrap(), }; app.input_query = String::new(); } @@ -484,12 +483,10 @@ where | Key::Left => { /* Select the next eligible block for action. */ app.selected_block = match input { - Key::Left => { - match app.selected_block.prev_variant() { - Some(v) => v, - None => Block::max_value(), - } - } + Key::Left => match app.selected_block.previous() { + Some(v) => v, + None => Block::last().unwrap(), + }, Key::Char('\n') => match app.input_mode { InputMode::Load if !app.input_query.is_empty() => @@ -569,7 +566,10 @@ fn main() -> Result<(), Box<dyn Error>> { let args = util::parse_args(); let kernel = Kernel::new(&args); let events = Events::new( - args.value_of("rate").unwrap().parse::<u64>().unwrap_or(250), + args.get_one::<String>("rate") + .unwrap() + .parse::<u64>() + .unwrap_or(250), &kernel.logs, ); if !cfg!(test) { @@ -631,7 +631,7 @@ mod tests { send_key(&tx, Key::Char('r')); /* Test the switch keys. */ for arrow_key in vec![Key::Right, Key::Left] { - for selected_key in vec![arrow_key; Block::count()] { + for selected_key in vec![arrow_key; Block::CARDINALITY] { send_key(&tx, selected_key); for key in vec![ Key::Up, diff --git a/src/style.rs b/src/style.rs index 380ea52..4f9b9a0 100644 --- a/src/style.rs +++ b/src/style.rs @@ -87,9 +87,9 @@ impl Style { * @param args * @return Style */ - pub fn new(args: &ArgMatches<'_>) -> Self { + pub fn new(args: &ArgMatches) -> Self { let mut default = TuiStyle::reset(); - if args.is_present("accent-color") { + if let Ok(true) = args.try_contains_id("accent-color") { default = default.fg(Self::get_color(args, "accent-color", Color::White)); } @@ -101,7 +101,9 @@ impl Style { "color", Color::DarkGray, )), - unicode: Unicode::new(!args.is_present("unicode")), + unicode: Unicode::new( + args.try_get_one::<bool>("unicode").ok().flatten() == Some(&false), + ), } } @@ -113,11 +115,7 @@ impl Style { * @param default_color * @return Color */ - fn get_color( - args: &ArgMatches<'_>, - arg_name: &str, - default_color: Color, - ) -> Color { + fn get_color(args: &ArgMatches, arg_name: &str, default_color: Color) -> Color { let colors = map![ "black" => Color::Black, "red" => Color::Red, @@ -136,8 +134,8 @@ impl Style { "lightcyan" => Color::LightCyan, "white" => Color::White ]; - match args.value_of(arg_name) { - Some(v) => *colors.get::<str>(&v.to_lowercase()).unwrap_or({ + match args.try_get_one::<String>(arg_name) { + Ok(Some(v)) => *colors.get::<str>(&v.to_lowercase()).unwrap_or({ if let Ok(rgb) = Rgb::from_hex_str(&format!("#{}", v)) { Box::leak(Box::new(Color::Rgb( rgb.red() as u8, @@ -148,7 +146,7 @@ impl Style { &default_color } }), - None => default_color, + _ => default_color, } } } diff --git a/src/util.rs b/src/util.rs index 0c7f29f..57efad3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg, SubCommand}; +use clap::{Arg, ArgAction, ArgMatches, Command as App}; use std::process::Command; /* Macro for concise initialization of hashmap */ @@ -52,76 +52,83 @@ const ASCII_LOGO: &str = " * * @return ArgMatches */ -pub fn parse_args() -> clap::ArgMatches<'static> { +pub fn parse_args() -> ArgMatches { App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .author(env!("CARGO_PKG_AUTHORS")) - .about(&*format!( - "{}\n\n{}", + .about(format!( + "{} {}\n{}\n{}\n\n{}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_AUTHORS"), env!("CARGO_PKG_DESCRIPTION"), "Press '?' while running the terminal UI to see key bindings." )) - .usage("kmon [FLAGS] [OPTIONS] [SUBCOMMANDS]") .before_help(ASCII_LOGO) .arg( - Arg::with_name("accent-color") - .short("a") + Arg::new("accent-color") + .short('a') .long("accent-color") .value_name("COLOR") .default_value("white") .help("Set the accent color using hex or color name") - .takes_value(true), + .num_args(1), ) .arg( - Arg::with_name("color") - .short("c") + Arg::new("color") + .short('c') .long("color") .value_name("COLOR") .default_value("darkgray") .help("Set the main color using hex or color name") - .takes_value(true), + .num_args(1), ) .arg( - Arg::with_name("rate") - .short("t") + Arg::new("rate") + .short('t') .long("tickrate") .value_name("MS") .default_value("250") .help("Set the refresh rate of the terminal") - .takes_value(true), + .num_args(1), ) .arg( - Arg::with_name("reverse") - .short("r") + Arg::new("reverse") + .short('r') .long("reverse") - .help("Reverse the kernel module list"), + .help("Reverse the kernel module list") + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name("unicode") - .short("u") + Arg::new("unicode") + .short('u') .long("unicode") - .help("Show Unicode symbols for the block titles"), + .help("Show Unicode symbols for the block titles") + .action(ArgAction::SetTrue), ) .subcommand( - SubCommand::with_name("sort") + App::new("sort") .about("Sort kernel modules") .arg( - Arg::with_name("size") - .short("s") + Arg::new("size") + .short('s') .long("size") - .help("Sort modules by their sizes"), + .help("Sort modules by their sizes") + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name("name") - .short("n") + Arg::new("name") + .short('n') .long("name") - .help("Sort modules by their names"), + .help("Sort modules by their names") + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name("dependent") - .short("d") + Arg::new("dependent") + .short('d') .long("dependent") - .help("Sort modules by their dependent modules"), + .help("Sort modules by their dependent modules") + .action(ArgAction::SetTrue), ), ) .get_matches() |