diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs index 6610b988..c7bf6111 100644 --- a/atuin-client/src/history.rs +++ b/atuin-client/src/history.rs @@ -45,4 +45,8 @@ impl History { hostname, } } + + pub fn success(&self) -> bool { + self.exit == 0 || self.duration == -1 + } } diff --git a/src/command/client/history.rs b/src/command/client/history.rs index 6bc99dda..7cbe27f3 100644 --- a/src/command/client/history.rs +++ b/src/command/client/history.rs @@ -81,11 +81,12 @@ pub fn print_human_list(w: &mut StdoutLock, h: &[History]) { let time = h.timestamp.format("%Y-%m-%d %H:%M:%S"); let cmd = h.command.trim(); - let duration = if h.exit == 0 { - duration.color(owo_colors::AnsiColors::Green) + let exit_color = if h.success() { + owo_colors::AnsiColors::Green } else { - duration.color(owo_colors::AnsiColors::Red) + owo_colors::AnsiColors::Red }; + let duration = duration.color(exit_color); writeln!(w, "{time} ยท {duration}\t{cmd}").expect("failed to write history"); } diff --git a/src/command/client/search.rs b/src/command/client/search.rs index a913e161..5f51a664 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -196,7 +196,7 @@ impl State { let duration = Span::styled( duration, - Style::default().fg(if m.exit == 0 || m.duration == -1 { + Style::default().fg(if m.success() { Color::Green } else { Color::Red