mirror of
https://github.com/starship/starship.git
synced 2026-06-22 02:02:12 +07:00
feat: implement timer module (#118)
Implement a timer module that takes a commandline argument, the number of seconds the last job took to complete, and displays it if appropriate. Alters shell initialization files to compute this number using date +%s where needed. Adds a config section to configure minimum amount of time before timer is shown (default is 2s)
This commit is contained in:
committed by
Matan Kushner
parent
b2303d5d8e
commit
3daf3ddf26
@@ -0,0 +1,80 @@
|
||||
use ansi_term::Color;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::common::{self, TestCommand};
|
||||
|
||||
#[test]
|
||||
fn config_blank_duration_1s() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.arg("--cmd-duration=1")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_blank_duration_5s() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.arg("--cmd-duration=5")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("{} ", Color::Yellow.bold().paint("took 5s"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_5s_duration_3s() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.use_config(toml::toml! {
|
||||
[cmd_duration]
|
||||
min_time = 5
|
||||
})
|
||||
.arg("--cmd-duration=3")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_5s_duration_10s() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.use_config(toml::toml! {
|
||||
[cmd_duration]
|
||||
min_time = 5
|
||||
})
|
||||
.arg("--cmd-duration=10")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = format!("{} ", Color::Yellow.bold().paint("took 10s"));
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_disabled() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.use_config(toml::toml! {
|
||||
[cmd_duration]
|
||||
disabled = true
|
||||
min_time = 5
|
||||
})
|
||||
.arg("--cmd-duration=10")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod character;
|
||||
mod cmd_duration;
|
||||
mod common;
|
||||
mod configuration;
|
||||
mod directory;
|
||||
|
||||
Reference in New Issue
Block a user