This commit is contained in:
Conrad Ludgate 2022-04-24 21:17:42 +01:00
parent ceb2e017ce
commit 6851b386d1
3 changed files with 9 additions and 4 deletions

View File

@ -45,4 +45,8 @@ impl History {
hostname,
}
}
pub fn success(&self) -> bool {
self.exit == 0 || self.duration == -1
}
}

View File

@ -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");
}

View File

@ -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