From 067acf34185c7651a6220bc03a1058f65534e9f6 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Wed, 11 Jun 2025 13:05:33 +0200 Subject: pkgs/tskm/inputs/tags: Init This makes it possible to see the already used tabs. --- pkgs/by-name/ts/tskm/src/cli.rs | 3 +++ pkgs/by-name/ts/tskm/src/interface/input/handle.rs | 31 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs index ac5f472b..90d6023b 100644 --- a/pkgs/by-name/ts/tskm/src/cli.rs +++ b/pkgs/by-name/ts/tskm/src/cli.rs @@ -196,6 +196,9 @@ pub enum InputCommand { #[arg(add = ArgValueCompleter::new(complete_tag))] tags: Vec, }, + + /// Show all the available tags. + Tags {}, } fn complete_task_id(current: &OsStr) -> Vec { diff --git a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs index 839e122f..11304633 100644 --- a/pkgs/by-name/ts/tskm/src/interface/input/handle.rs +++ b/pkgs/by-name/ts/tskm/src/interface/input/handle.rs @@ -111,6 +111,37 @@ pub fn handle(command: InputCommand, state: &mut State) -> Result<()> { println!("{url}"); } } + InputCommand::Tags {} => { + let mut without_tags = 0; + let mut tag_set: HashMap = HashMap::new(); + + for input in Input::all()? { + if input.tags.is_empty() { + without_tags += 1; + } + + for tag in input.tags { + if let Some(number) = tag_set.get_mut(&tag) { + *number += 1; + } else { + tag_set.insert(tag, 1); + } + } + } + + let mut tags: Vec<(Tag, u64)> = tag_set.into_iter().collect(); + tags.sort_by_key(|(_, number)| *number); + tags.reverse(); + + for (tag, number) in tags { + println!("{tag} {number}"); + } + + if without_tags != 0 { + println!(); + println!("Witohut tags: {without_tags}"); + } + } } Ok(()) } -- cgit 1.4.1