Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
fixup! cli: use a pager on list commands
Matthias Beyer committed 8 months ago
commit 944dffa33285838050ebf8fa12d1529ebd3edabb
parent 8ab3e770b97ef8a52d31fbe02e60df9973332206
10 files changed +15 -19
modified crates/radicle-cli/src/commands/issue.rs
@@ -824,7 +824,7 @@ where
        ]);
    }

-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;

    Ok(())
}
modified crates/radicle-cli/src/commands/ls.rs
@@ -1,6 +1,7 @@
use std::ffi::OsString;

use radicle::storage::{ReadStorage, RepositoryInfo};
+
use radicle_term::Element as _;

use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
@@ -155,7 +156,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        ]);
        table.divider();
        table.extend(rows);
-
        term::print_with_pager(table)?;
+
        table.print_with_pager()?;
    }

    Ok(())
modified crates/radicle-cli/src/commands/node.rs
@@ -11,6 +11,7 @@ use radicle::node::routing::Store;
use radicle::node::Handle as _;
use radicle::node::{Address, Node, NodeId, PeerAddr};
use radicle::prelude::RepoId;
+
use radicle_term::Element as _;

use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
@@ -310,7 +311,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        Operation::Sessions => {
            let sessions = control::sessions(&node)?;
            if let Some(table) = sessions {
-
                term::print_with_pager(table)?;
+
                table.print_with_pager()?;
            }
        }
        Operation::Events { timeout, count } => {
modified crates/radicle-cli/src/commands/node/control.rs
@@ -304,7 +304,7 @@ pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
    let sessions = sessions(node)?;
    if let Some(table) = sessions {
        term::blank();
-
        term::print_with_pager(table)?;
+
        table.print_with_pager()?;
    }

    if profile.hints() {
modified crates/radicle-cli/src/commands/patch/list.rs
@@ -7,6 +7,7 @@ use radicle::prelude::*;
use radicle::profile::Profile;
use radicle::storage::git::Repository;

+
use radicle_term::Element as _;
use term::format::Author;
use term::table::{Table, TableOptions};

@@ -85,7 +86,7 @@ pub fn run(
            Err(e) => errors.push((patch.title(), id, e.to_string())),
        }
    }
-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;

    if !errors.is_empty() {
        for (title, id, error) in errors {
modified crates/radicle-cli/src/commands/remote/list.rs
@@ -5,7 +5,7 @@ use radicle::identity::{Did, RepoId};
use radicle::node::{Alias, AliasStore as _, NodeId};
use radicle::storage::ReadStorage as _;
use radicle::Profile;
-
use radicle_term::Table;
+
use radicle_term::{Element as _, Table};

use crate::git;
use crate::terminal as term;
@@ -101,7 +101,7 @@ pub fn print_tracked<'a>(tracked: impl Iterator<Item = &'a Tracked>) -> anyhow::
            term::format::parens(term::format::secondary(dir.to_owned())),
        ]);
    }
-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;
    Ok(())
}

@@ -116,6 +116,6 @@ pub fn print_untracked<'a>(untracked: impl Iterator<Item = &'a Untracked>) -> an
            term::format::highlight(Did::from(remote).to_string()),
        ])
    }
-
    term::print_with_pager(t)?;
+
    t.print_with_pager()?;
    Ok(())
}
modified crates/radicle-cli/src/commands/self.rs
@@ -4,6 +4,7 @@ use radicle::crypto::ssh;
use radicle::node::Handle as _;
use radicle::node::Node;
use radicle::profile::Profile;
+
use radicle_term::Element as _;

use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
@@ -210,7 +211,7 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
        term::format::tertiary(profile.home.node().display()).into(),
    ]);

-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;

    Ok(())
}
modified crates/radicle-cli/src/commands/sync.rs
@@ -404,7 +404,7 @@ fn sync_status(
            time.dim().italic().into(),
        ]);
    }
-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;

    if profile.hints() {
        const COLUMN_WIDTH: usize = 16;
modified crates/radicle-cli/src/terminal.rs
@@ -161,11 +161,3 @@ pub fn fail(_name: &str, error: &anyhow::Error) {
        io::hint(hint);
    }
}
-

-
/// Print an element with automatic paging when there are too many lines.
-
/// This function automatically detects if the content is too long for the terminal
-
/// and uses a pager if necessary.
-
pub fn print_with_pager(elem: impl Element) -> anyhow::Result<()> {
-
    elem.print_with_pager()?;
-
    Ok(())
-
}
modified crates/radicle-cli/src/terminal/patch.rs
@@ -317,7 +317,7 @@ pub fn list_commits(commits: &[git::raw::Commit]) -> anyhow::Result<()> {
            term::format::italic(String::from_utf8_lossy(message).to_string()),
        ]);
    }
-
    term::print_with_pager(table)?;
+
    table.print_with_pager()?;

    Ok(())
}