From 2830a0ba1a32da059b1a2ab93bf648b5b614adef Mon Sep 17 00:00:00 2001 From: Michael de Silva Date: Sun, 7 Jul 2024 14:49:00 +0530 Subject: [PATCH 1/4] WIP --- src/app/style.rs | 112 +++++++++++++++++++++++++++++++++++++++++++++++ src/gpg/key.rs | 32 +++++++++++++- 2 files changed, 142 insertions(+), 2 deletions(-) diff --git a/src/app/style.rs b/src/app/style.rs index a839dbd..6e21d68 100644 --- a/src/app/style.rs +++ b/src/app/style.rs @@ -1,8 +1,11 @@ use clap::ValueEnum; +use core::panic; use ratatui::style::{Color, Style as TuiStyle}; use ratatui::text::{Line, Span, Text}; use std::fmt::{Display, Formatter, Result as FmtResult}; +use crate::gpg::key; + /// Application style. #[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)] pub enum Style { @@ -62,6 +65,7 @@ pub fn get_colored_table_row<'a>( line.find('[').unwrap_or_default(), line.find(']').unwrap_or_default(), ); + row.push( // Colorize inside the brackets to start. if second_bracket > first_bracket + 1 { @@ -149,6 +153,114 @@ pub fn get_colored_table_row<'a>( highlight_style, )); // Colorize inside the arrows. + } else if let ( + Some(first_parenthesis), + Some(second_parenthesis), + ) = (data.rfind('('), data.rfind(')')) + { + let inner = line[first_parenthesis..].to_string(); + + log::trace!(target: "style", "inner: {inner:?}"); + + // panic!("{:?}", data); + + let expected = [ + // expired + String::from("exp"), + // revoked + String::from("rev"), + // disabled + String::from("d"), + // invalid + String::from("i"), + ]; + + let matched: Vec<_> = data.match_indices("(").collect(); + // panic!("{:?}", matched); + + // let s = String::from("foo rev bar"); + // let matched: Vec<_> = s.match_indices("(").collect(); + + // panic!( + // "Data: {:?}, Inner: {:?}, Contains? {:?}", + // &s, + // &inner, + // s.contains(&inner) + // ); + + if let Some((opening_parenthesis, char)) = + data.match_indices("(").next() + { + let inner = data[(opening_parenthesis + 1) + ..(opening_parenthesis + 4)] + .to_string(); + + // THIS WORKS + // panic!( + // "Data: {:?}, Inner: {:?}, Contains? {:?}", + // &data, + // &inner, + // expected.contains(&inner) + // ); + + if [ + // expired + String::from("exp"), + // revoked + String::from("rev"), + // disabled + String::from("d"), + // invalid + String::from("i"), + ] + .contains(&inner) + { + colored_line.push(Span::styled( + data[..first_parenthesis].to_string(), + highlight_style, + )); + colored_line.push(Span::styled( + "(", + TuiStyle::default().fg(Color::DarkGray), + )); + colored_line.push(Span::styled( + data[first_parenthesis + 1..second_parenthesis] + .to_string(), + TuiStyle::default().fg(Color::Red), + )); + colored_line.push(Span::styled( + ")", + TuiStyle::default().fg(Color::DarkGray), + )); + colored_line.push(Span::styled( + data[second_parenthesis + 1..].to_string(), + highlight_style, + )); + } + } + + // colored_line.push(Span::styled( + // data[..first_parenthesis].to_string(), + // highlight_style, + // )); + // colored_line.push(Span::styled( + // "{", + // TuiStyle::default().fg(Color::DarkGray), + // )); + // colored_line.push(Span::styled( + // data[first_parenthesis + 1..second_parenthesis] + // .to_string(), + // TuiStyle::default().fg(Color::Cyan), + // )); + // colored_line.push(Span::styled( + // "}", + // TuiStyle::default().fg(Color::DarkGray), + // )); + // colored_line.push(Span::styled( + // data[second_parenthesis + 1..].to_string(), + // highlight_style, + // )); + // FIXME } else if let (Some(first_arrow), Some(second_arrow)) = (data.rfind('<'), data.rfind('>')) { diff --git a/src/gpg/key.rs b/src/gpg/key.rs index 8574987..3b6ba27 100644 --- a/src/gpg/key.rs +++ b/src/gpg/key.rs @@ -127,10 +127,36 @@ impl GpgKey { ) -> Vec { let mut key_info = Vec::new(); let subkeys = self.inner.subkeys().collect::>(); + let blank = String::from(""); for (i, subkey) in subkeys.iter().enumerate() { key_info.push(format!( - "[{}]{}{}/{}", + "[{}] {} {}{}/{}", handler::get_subkey_flags(*subkey), + format!( + "{}", + if i != subkeys.len() - 1 { + let last = subkeys.last(); + if let Some(key) = last { + if key.is_expired() { + String::from("(exp)") + } else if key.is_revoked() { + String::from("(rev)") + } else if key.is_disabled() { + String::from("(d)") + } else if key.is_invalid() { + String::from("(i)") + } else if key.is_qualified() { + String::from("(q)") + } else { + blank.to_string() + } + } else { + blank.to_string() + } + } else { + blank.to_string() + } + ), if default_key.map(|v| v.trim_start_matches("0x")) == subkey.id().ok() { @@ -227,7 +253,7 @@ impl GpgKey { "│ " }; user_signatures.push(format!( - " {} {}[{:x}] {} {}", + " {} {}[{:x}] {}, {} {}", padding, if i == signatures.len() - 1 { "└─" @@ -235,6 +261,8 @@ impl GpgKey { "├─" }, sig.cert_class(), + // FIXME?? + format!("REV: {}", sig.is_revocation()), if sig.signer_key_id() == self.inner.id() { String::from("selfsig") } else if truncate { From 93f9bac5c0c1a0712e191cad52147fe3d533a13f Mon Sep 17 00:00:00 2001 From: Michael de Silva Date: Sun, 28 Jul 2024 17:38:30 +0530 Subject: [PATCH 2/4] FIXME tests need updating --- src/app/style.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/style.rs b/src/app/style.rs index 6e21d68..373ee62 100644 --- a/src/app/style.rs +++ b/src/app/style.rs @@ -153,6 +153,8 @@ pub fn get_colored_table_row<'a>( highlight_style, )); // Colorize inside the arrows. + + // FIXME: These need updating for breakage } else if let ( Some(first_parenthesis), Some(second_parenthesis), From bf40fcb529fda79d876372895f7b92ad71789f69 Mon Sep 17 00:00:00 2001 From: Michael de Silva Date: Mon, 29 Jul 2024 10:29:25 +0530 Subject: [PATCH 3/4] Quick cleanup --- src/app/style.rs | 63 ++---------------------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/src/app/style.rs b/src/app/style.rs index 373ee62..87adbca 100644 --- a/src/app/style.rs +++ b/src/app/style.rs @@ -1,11 +1,8 @@ use clap::ValueEnum; -use core::panic; use ratatui::style::{Color, Style as TuiStyle}; use ratatui::text::{Line, Span, Text}; use std::fmt::{Display, Formatter, Result as FmtResult}; -use crate::gpg::key; - /// Application style. #[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)] pub enum Style { @@ -176,47 +173,14 @@ pub fn get_colored_table_row<'a>( // invalid String::from("i"), ]; - - let matched: Vec<_> = data.match_indices("(").collect(); - // panic!("{:?}", matched); - - // let s = String::from("foo rev bar"); - // let matched: Vec<_> = s.match_indices("(").collect(); - - // panic!( - // "Data: {:?}, Inner: {:?}, Contains? {:?}", - // &s, - // &inner, - // s.contains(&inner) - // ); - - if let Some((opening_parenthesis, char)) = + if let Some((opening_parenthesis, _)) = data.match_indices("(").next() { let inner = data[(opening_parenthesis + 1) ..(opening_parenthesis + 4)] .to_string(); - // THIS WORKS - // panic!( - // "Data: {:?}, Inner: {:?}, Contains? {:?}", - // &data, - // &inner, - // expected.contains(&inner) - // ); - - if [ - // expired - String::from("exp"), - // revoked - String::from("rev"), - // disabled - String::from("d"), - // invalid - String::from("i"), - ] - .contains(&inner) - { + if expected.contains(&inner) { colored_line.push(Span::styled( data[..first_parenthesis].to_string(), highlight_style, @@ -240,29 +204,6 @@ pub fn get_colored_table_row<'a>( )); } } - - // colored_line.push(Span::styled( - // data[..first_parenthesis].to_string(), - // highlight_style, - // )); - // colored_line.push(Span::styled( - // "{", - // TuiStyle::default().fg(Color::DarkGray), - // )); - // colored_line.push(Span::styled( - // data[first_parenthesis + 1..second_parenthesis] - // .to_string(), - // TuiStyle::default().fg(Color::Cyan), - // )); - // colored_line.push(Span::styled( - // "}", - // TuiStyle::default().fg(Color::DarkGray), - // )); - // colored_line.push(Span::styled( - // data[second_parenthesis + 1..].to_string(), - // highlight_style, - // )); - // FIXME } else if let (Some(first_arrow), Some(second_arrow)) = (data.rfind('<'), data.rfind('>')) { From 7548065a9f054c0519af7af33d4a193e63555157 Mon Sep 17 00:00:00 2001 From: Michael de Silva Date: Mon, 29 Jul 2024 11:55:39 +0530 Subject: [PATCH 4/4] Further cleanup, remove FIXME references --- src/app/style.rs | 5 ----- src/gpg/key.rs | 1 - 2 files changed, 6 deletions(-) diff --git a/src/app/style.rs b/src/app/style.rs index 87adbca..dab736c 100644 --- a/src/app/style.rs +++ b/src/app/style.rs @@ -150,8 +150,6 @@ pub fn get_colored_table_row<'a>( highlight_style, )); // Colorize inside the arrows. - - // FIXME: These need updating for breakage } else if let ( Some(first_parenthesis), Some(second_parenthesis), @@ -160,9 +158,6 @@ pub fn get_colored_table_row<'a>( let inner = line[first_parenthesis..].to_string(); log::trace!(target: "style", "inner: {inner:?}"); - - // panic!("{:?}", data); - let expected = [ // expired String::from("exp"), diff --git a/src/gpg/key.rs b/src/gpg/key.rs index 3b6ba27..3125cf5 100644 --- a/src/gpg/key.rs +++ b/src/gpg/key.rs @@ -261,7 +261,6 @@ impl GpgKey { "├─" }, sig.cert_class(), - // FIXME?? format!("REV: {}", sig.is_revocation()), if sig.signer_key_id() == self.inner.id() { String::from("selfsig")