Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "rev" detail to default view of keys #246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions src/app/style.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use clap::ValueEnum;
use core::panic;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to import stuff from core.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this, I was using panic for dumb testing. How can I enable tracing logging to STDOUT btw?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUST_LOG=trace cargo r doesn't help as the TUI takes over STDOUT

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a logging widget in the TUI: https://github.com/orhun/gpg-tui?tab=readme-ov-file#show-logs

You can also save logs to a file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!! That's just neat

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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -149,6 +153,116 @@ 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),
) = (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
bsodmike marked this conversation as resolved.
Show resolved Hide resolved
} else if let (Some(first_arrow), Some(second_arrow)) =
(data.rfind('<'), data.rfind('>'))
{
Expand Down
32 changes: 30 additions & 2 deletions src/gpg/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,36 @@ impl GpgKey {
) -> Vec<String> {
let mut key_info = Vec::new();
let subkeys = self.inner.subkeys().collect::<Vec<Subkey>>();
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()
{
Expand Down Expand Up @@ -227,14 +253,16 @@ impl GpgKey {
"│ "
};
user_signatures.push(format!(
" {} {}[{:x}] {} {}",
" {} {}[{:x}] {}, {} {}",
padding,
if i == signatures.len() - 1 {
"└─"
} else {
"├─"
},
sig.cert_class(),
// FIXME??
format!("REV: {}", sig.is_revocation()),
if sig.signer_key_id() == self.inner.id() {
String::from("selfsig")
} else if truncate {
Expand Down
Loading