aboutsummaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-05-06 08:11:47 +0100
committerGitHub <noreply@github.com>2024-05-06 08:11:47 +0100
commit754ddeaa8d3e3e4f3efc93d5bb22c68c31bb5c36 (patch)
treef48fb912c2be2d08855e97ff24b6919a115c3c4f /crates
parentchore(deps): bump serde_with from 3.7.0 to 3.8.1 (#2002) (diff)
downloadatuin-754ddeaa8d3e3e4f3efc93d5bb22c68c31bb5c36.zip
feat(ui): scroll history infinitely (#1999)
* wip, history scrolls right! * wip * virtual scroll fucking worksssss * paging works :) * scroll search results now too
Diffstat (limited to 'crates')
-rw-r--r--crates/atuin-history/src/stats.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/atuin-history/src/stats.rs b/crates/atuin-history/src/stats.rs
index fb6781fe..ab4127df 100644
--- a/crates/atuin-history/src/stats.rs
+++ b/crates/atuin-history/src/stats.rs
@@ -1,14 +1,16 @@
use std::collections::{HashMap, HashSet};
use crossterm::style::{Color, ResetColor, SetAttribute, SetForegroundColor};
+use serde::{Deserialize, Serialize};
+use unicode_segmentation::UnicodeSegmentation;
use atuin_client::{history::History, settings::Settings};
-use unicode_segmentation::UnicodeSegmentation;
-pub struct Stats<'a> {
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Stats {
pub total_commands: usize,
pub unique_commands: usize,
- pub top: Vec<(Vec<&'a str>, usize)>,
+ pub top: Vec<(Vec<String>, usize)>,
}
fn first_non_whitespace(s: &str) -> Option<usize> {
@@ -161,12 +163,12 @@ pub fn pretty_print(stats: Stats, ngram_size: usize) {
println!("Unique commands: {}", stats.unique_commands);
}
-pub fn compute<'a>(
+pub fn compute(
settings: &Settings,
- history: &'a [History],
+ history: &[History],
count: usize,
ngram_size: usize,
-) -> Option<Stats<'a>> {
+) -> Option<Stats> {
let mut commands = HashSet::<&str>::with_capacity(history.len());
let mut total_unignored = 0;
let mut prefixes = HashMap::<Vec<&str>, usize>::with_capacity(history.len());
@@ -212,7 +214,10 @@ pub fn compute<'a>(
Some(Stats {
unique_commands: unique,
total_commands: total_unignored,
- top,
+ top: top
+ .into_iter()
+ .map(|t| (t.0.into_iter().map(|s| s.to_string()).collect(), t.1))
+ .collect(),
})
}