From 754ddeaa8d3e3e4f3efc93d5bb22c68c31bb5c36 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 6 May 2024 08:11:47 +0100 Subject: feat(ui): scroll history infinitely (#1999) * wip, history scrolls right! * wip * virtual scroll fucking worksssss * paging works :) * scroll search results now too --- crates/atuin-history/src/stats.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'crates') 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, usize)>, } fn first_non_whitespace(s: &str) -> Option { @@ -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> { +) -> Option { let mut commands = HashSet::<&str>::with_capacity(history.len()); let mut total_unignored = 0; let mut prefixes = HashMap::, 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(), }) } -- cgit v1.3.1