basic/
basic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use shrs::prelude::{StyledBuf, *};
use shrs_command_timer::{CommandTimerPlugin, CommandTimerState};

fn prompt_left() -> StyledBuf {
    styled_buf!("> ")
}

fn prompt_right(state: State<CommandTimerState>) -> StyledBuf {
    let time_str = state
        .command_time()
        .map(|x| format!("{x:?}"))
        .unwrap_or(String::new());
    styled_buf!(time_str.reset())
}

fn main() {
    let prompt = Prompt::from_sides(prompt_left, prompt_right);

    let myshell = ShellBuilder::default()
        .with_plugin(CommandTimerPlugin)
        .with_prompt(prompt)
        .build()
        .unwrap();

    myshell.run().expect("Shell Failed");
}