cli: Make terminal::Table more accepting
Make the Table type easier to use by having it accept &str over String types as arguments. Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
parent
c0590a100d
commit
83f2f2b5a5
|
|
@ -78,33 +78,30 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
|
|||
let mut table = term::Table::default();
|
||||
|
||||
let node_id = profile.id();
|
||||
table.push([String::from("ID"), term::format::tertiary(node_id)]);
|
||||
table.push(["ID", &term::format::tertiary(node_id)]);
|
||||
|
||||
let ssh_short = ssh::fmt::fingerprint(node_id);
|
||||
table.push([
|
||||
String::from("Key (hash)"),
|
||||
term::format::tertiary(ssh_short),
|
||||
]);
|
||||
table.push(["Key (hash)", &term::format::tertiary(ssh_short)]);
|
||||
|
||||
let ssh_long = ssh::fmt::key(node_id);
|
||||
table.push([String::from("Key (full)"), term::format::tertiary(ssh_long)]);
|
||||
table.push(["Key (full)", &term::format::tertiary(ssh_long)]);
|
||||
|
||||
let storage_path = profile.paths().storage();
|
||||
table.push([
|
||||
String::from("Storage (git)"),
|
||||
term::format::tertiary(storage_path.display()),
|
||||
"Storage (git)",
|
||||
&term::format::tertiary(storage_path.display()),
|
||||
]);
|
||||
|
||||
let keys_path = profile.paths().keys();
|
||||
table.push([
|
||||
String::from("Storage (keys)"),
|
||||
term::format::tertiary(keys_path.display()),
|
||||
"Storage (keys)",
|
||||
&term::format::tertiary(keys_path.display()),
|
||||
]);
|
||||
|
||||
let node_path = profile.paths().node();
|
||||
table.push([
|
||||
String::from("Node (socket)"),
|
||||
term::format::tertiary(node_path.join("radicle.sock").display()),
|
||||
"Node (socket)",
|
||||
&term::format::tertiary(node_path.join("radicle.sock").display()),
|
||||
]);
|
||||
|
||||
table.render();
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
//! use radicle_cli::terminal::table::*;
|
||||
//!
|
||||
//! let mut t = Table::new(TableOptions::default());
|
||||
//! t.push(["pest".to_string(), "biological control".to_string()]);
|
||||
//! t.push(["aphid".to_string(), "lacewing".to_string()]);
|
||||
//! t.push(["spider mite".to_string(), "ladybug".to_string()]);
|
||||
//! t.push(["pest", "biological control"]);
|
||||
//! t.push(["aphid", "lacewing"]);
|
||||
//! t.push(["spider mite", "ladybug"]);
|
||||
//! t.render();
|
||||
//! // pest biological control
|
||||
//! // aphid lacewing
|
||||
//! // spider mite ladybug
|
||||
//! // aphid ladybug
|
||||
//! // spider mite persimilis
|
||||
//! ```
|
||||
|
||||
use std::fmt::Write;
|
||||
|
|
@ -49,7 +49,8 @@ impl<const W: usize> Table<W> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, row: [String; W]) {
|
||||
pub fn push(&mut self, row: [impl ToString; W]) {
|
||||
let row = row.map(|s| s.to_string());
|
||||
for (i, cell) in row.iter().enumerate() {
|
||||
self.widths[i] = self.widths[i].max(console::measure_text_width(cell));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue