quartz_cli/action/
history.rs1use crate::{history::History, Ctx, QuartzResult};
2
3#[derive(clap::Args, Debug)]
4pub struct Args {
5 #[arg(short = 'n', long, value_name = "N")]
7 max_count: Option<usize>,
8}
9
10pub fn cmd(ctx: &Ctx, args: Args) -> QuartzResult {
11 let history = History::new(ctx)?;
12 let mut count = 0;
13 let max_count = args.max_count.unwrap_or(usize::MAX);
14
15 let mut output = String::new();
16 for entry in history.entries(ctx) {
17 if count >= max_count {
18 break;
19 }
20
21 count += 1;
22 if count != 1 {
23 output.push('\n');
25 }
26
27 output.push_str(&format!("{entry}\n"));
28 }
29
30 ctx.paginate(output.as_bytes())?;
31
32 Ok(())
33}