Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Make terminal::Table more accepting
Slack Coder committed 3 years ago
commit 83f2f2b5a5d3169b6b5f340fd7c7dd9a4ea7405b
parent c0590a100dac4383fafc55f7571890f44c727983
2 files changed +16 -18
modified radicle-cli/src/commands/self.rs
@@ -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();
modified radicle-cli/src/terminal/table.rs
@@ -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));
        }