Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Change signature of `Constraint::from_env`
cloudhead committed 2 years ago
commit bb40347121ee3c231aab84be286495a810326457
parent 6a5753f4bc9845b5482256b6904bb43554ac10ea
3 files changed +7 -8
modified radicle-cli/src/commands/diff.rs
@@ -146,7 +146,7 @@ pub fn run(options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
    let mut hi = Highlighter::default();
    let pretty = diff.pretty(&mut hi, &(), &repo);

-
    pretty.write(Constraint::from_env().maximize());
+
    pretty.write(Constraint::from_env().unwrap_or_default());

    Ok(())
}
modified radicle-cli/src/git/pretty_diff.rs
@@ -372,6 +372,6 @@ mod test {
        let mut hi = Highlighter::default();
        let pretty = diff.pretty(&mut hi, &(), &repo);

-
        pretty.write(Constraint::from_env().maximize());
+
        pretty.write(Constraint::from_env().unwrap_or_default());
    }
}
modified radicle-term/src/element.rs
@@ -60,13 +60,12 @@ impl Constraint {
    }

    /// Create a constraint from the terminal environment.
-
    ///
-
    /// If standard out isn't a terminal, returns an unbounded constraint.
-
    pub fn from_env() -> Self {
+
    /// Returns [`None`] if the output device is not a terminal.
+
    pub fn from_env() -> Option<Self> {
        if io::stdout().is_terminal() {
-
            Self::max(viewport().unwrap_or(Size::MAX))
+
            Some(Self::max(viewport().unwrap_or(Size::MAX)))
        } else {
-
            Self::UNBOUNDED
+
            None
        }
    }
}
@@ -92,7 +91,7 @@ pub trait Element: fmt::Debug {

    /// Print this element to stdout.
    fn print(&self) {
-
        for line in self.render(Constraint::from_env()) {
+
        for line in self.render(Constraint::from_env().unwrap_or_default()) {
            println!("{}", line.to_string().trim_end());
        }
    }