feat: add build_digest_table based on build_compression_table

This commit is contained in:
Andrew Phillips (aider)
2025-05-13 16:56:19 -03:00
parent d26218617a
commit 75e131d0e3

View File

@@ -107,6 +107,64 @@ fn build_compression_table() -> Table {
compression_table compression_table
} }
fn build_digest_table() -> Table {
use crate::digest_engine;
use crate::digest_engine::program::DigestEngineProgram;
use crate::digest_engine::DigestType;
use crate::digest_engine::DIGEST_PROGRAMS;
let mut digest_table = Table::new();
if std::io::stdout().is_terminal() {
digest_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR);
} else {
digest_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
}
digest_table.set_titles(row!(
b->"Type",
b->"Found",
b->"Default",
b->"Binary",
b->"Args"));
let default_type = digest_engine::default_digest_type();
for digest_type in DigestType::iter() {
let digest_program: DigestEngineProgram =
match &DIGEST_PROGRAMS[digest_type.clone()] {
Some(digest_program) => digest_program.clone(),
None => DigestEngineProgram {
program: "".to_string(),
args: Vec::new(),
supported: true,
},
};
let is_default = digest_type == default_type;
digest_table.add_row(Row::new(vec![
Cell::new(&digest_type.to_string()),
match digest_program.supported {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)),
},
match is_default {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No"),
},
match digest_program.program.is_empty() {
true => {
Cell::new("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
}
false => Cell::new(&digest_program.program),
},
Cell::new(&digest_program.args.join(" ")),
]));
}
digest_table
}
pub fn mode_status( pub fn mode_status(
_cmd: &mut Command, _cmd: &mut Command,
_args: crate::Args, _args: crate::Args,
@@ -120,5 +178,9 @@ pub fn mode_status(
println!("COMPRESSION:"); println!("COMPRESSION:");
build_compression_table() build_compression_table()
.printstd(); .printstd();
println!();
println!("DIGEST:");
build_digest_table()
.printstd();
Ok(()) Ok(())
} }