Skip to content

Commit

Permalink
feat: add atuin wrapped (#2493)
Browse files Browse the repository at this point in the history
* wip

* wip

* final

* fix clippy

* do not hard code the year

* support tz properly, allow specifying the year
  • Loading branch information
ellie authored Dec 27, 2024
1 parent cb57053 commit aa5c7e7
Show file tree
Hide file tree
Showing 5 changed files with 368 additions and 58 deletions.
80 changes: 40 additions & 40 deletions crates/atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,46 @@ impl Database for Sqlite {
}
}

trait SqlBuilderExt {
fn fuzzy_condition<S: ToString, T: ToString>(
&mut self,
field: S,
mask: T,
inverse: bool,
glob: bool,
is_or: bool,
) -> &mut Self;
}

impl SqlBuilderExt for SqlBuilder {
/// adapted from the sql-builder *like functions
fn fuzzy_condition<S: ToString, T: ToString>(
&mut self,
field: S,
mask: T,
inverse: bool,
glob: bool,
is_or: bool,
) -> &mut Self {
let mut cond = field.to_string();
if inverse {
cond.push_str(" NOT");
}
if glob {
cond.push_str(" GLOB '");
} else {
cond.push_str(" LIKE '");
}
cond.push_str(&esc(mask.to_string()));
cond.push('\'');
if is_or {
self.or_where(cond)
} else {
self.and_where(cond)
}
}
}

#[cfg(test)]
mod test {
use crate::settings::test_local_timeout;
Expand Down Expand Up @@ -1105,43 +1145,3 @@ mod test {
assert!(duration < Duration::from_secs(15));
}
}

trait SqlBuilderExt {
fn fuzzy_condition<S: ToString, T: ToString>(
&mut self,
field: S,
mask: T,
inverse: bool,
glob: bool,
is_or: bool,
) -> &mut Self;
}

impl SqlBuilderExt for SqlBuilder {
/// adapted from the sql-builder *like functions
fn fuzzy_condition<S: ToString, T: ToString>(
&mut self,
field: S,
mask: T,
inverse: bool,
glob: bool,
is_or: bool,
) -> &mut Self {
let mut cond = field.to_string();
if inverse {
cond.push_str(" NOT");
}
if glob {
cond.push_str(" GLOB '");
} else {
cond.push_str(" LIKE '");
}
cond.push_str(&esc(mask.to_string()));
cond.push('\'');
if is_or {
self.or_where(cond)
} else {
self.and_where(cond)
}
}
}
2 changes: 1 addition & 1 deletion crates/atuin-history/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use unicode_segmentation::UnicodeSegmentation;

use atuin_client::{history::History, settings::Settings, theme::Meaning, theme::Theme};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Stats {
pub total_commands: usize,
pub unique_commands: usize,
Expand Down
6 changes: 6 additions & 0 deletions crates/atuin/src/command/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod kv;
mod search;
mod stats;
mod store;
mod wrapped;

#[derive(Subcommand, Debug)]
#[command(infer_subcommands = true)]
Expand Down Expand Up @@ -78,6 +79,9 @@ pub enum Cmd {
#[command()]
Doctor,

#[command()]
Wrapped { year: Option<i32> },

/// *Experimental* Start the background daemon
#[cfg(feature = "daemon")]
#[command()]
Expand Down Expand Up @@ -166,6 +170,8 @@ impl Cmd {
Ok(())
}

Self::Wrapped { year } => wrapped::run(year, &db, &settings, theme).await,

#[cfg(feature = "daemon")]
Self::Daemon => daemon::run(settings, sqlite_store, db).await,

Expand Down
34 changes: 17 additions & 17 deletions crates/atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ mod tests {
let no_preview = State::calc_preview_height(
&settings_preview_auto,
&results,
0 as usize,
0 as usize,
0_usize,
0_usize,
false,
1,
80,
Expand All @@ -1314,8 +1314,8 @@ mod tests {
let preview_h2 = State::calc_preview_height(
&settings_preview_auto,
&results,
1 as usize,
0 as usize,
1_usize,
0_usize,
false,
1,
80,
Expand All @@ -1324,8 +1324,8 @@ mod tests {
let preview_h3 = State::calc_preview_height(
&settings_preview_auto,
&results,
2 as usize,
0 as usize,
2_usize,
0_usize,
false,
1,
80,
Expand All @@ -1334,8 +1334,8 @@ mod tests {
let preview_one_line = State::calc_preview_height(
&settings_preview_auto,
&results,
0 as usize,
0 as usize,
0_usize,
0_usize,
false,
1,
66,
Expand All @@ -1344,8 +1344,8 @@ mod tests {
let preview_limit_at_2 = State::calc_preview_height(
&settings_preview_auto_h2,
&results,
2 as usize,
0 as usize,
2_usize,
0_usize,
false,
1,
80,
Expand All @@ -1354,8 +1354,8 @@ mod tests {
let preview_static_h3 = State::calc_preview_height(
&settings_preview_h4,
&results,
1 as usize,
0 as usize,
1_usize,
0_usize,
false,
1,
80,
Expand All @@ -1364,8 +1364,8 @@ mod tests {
let preview_static_limit_at_4 = State::calc_preview_height(
&settings_preview_h4,
&results,
1 as usize,
0 as usize,
1_usize,
0_usize,
false,
1,
20,
Expand All @@ -1374,16 +1374,16 @@ mod tests {
let settings_preview_fixed = State::calc_preview_height(
&settings_preview_fixed,
&results,
1 as usize,
0 as usize,
1_usize,
0_usize,
false,
1,
20,
);

assert_eq!(no_preview, 1);
// 1 * 2 is the space for the border
let border_space = 1 * 2;
let border_space = 2;
assert_eq!(preview_h2, 2 + border_space);
assert_eq!(preview_h3, 3 + border_space);
assert_eq!(preview_one_line, 1 + border_space);
Expand Down
Loading

0 comments on commit aa5c7e7

Please sign in to comment.