mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-26 02:04:49 +01:00
feat: add prefers_reduced_motion flag (#1645)
* feat: add prefers_reduced_motion flag * use NO_MOTION, and ensure type is bool * update default config --------- Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
This commit is contained in:
parent
286f6eb5b3
commit
744f0059c2
@ -148,6 +148,10 @@ enter_accept = true
|
|||||||
## Timeout (in seconds) for acquiring a local database connection (sqlite)
|
## Timeout (in seconds) for acquiring a local database connection (sqlite)
|
||||||
# local_timeout = 5
|
# local_timeout = 5
|
||||||
|
|
||||||
|
## Set this to true and Atuin will minimize motion in the UI - timers will not update live, etc.
|
||||||
|
## Alternatively, set env NO_MOTION=true
|
||||||
|
# prefers_reduced_motion = false
|
||||||
|
|
||||||
#[stats]
|
#[stats]
|
||||||
# Set commands where we should consider the subcommand for statistics. Eg, kubectl get vs just kubectl
|
# Set commands where we should consider the subcommand for statistics. Eg, kubectl get vs just kubectl
|
||||||
#common_subcommands = [
|
#common_subcommands = [
|
||||||
|
@ -278,6 +278,7 @@ pub struct Settings {
|
|||||||
pub word_chars: String,
|
pub word_chars: String,
|
||||||
pub scroll_context_lines: usize,
|
pub scroll_context_lines: usize,
|
||||||
pub history_format: String,
|
pub history_format: String,
|
||||||
|
pub prefers_reduced_motion: bool,
|
||||||
|
|
||||||
#[serde(with = "serde_regex", default = "RegexSet::empty")]
|
#[serde(with = "serde_regex", default = "RegexSet::empty")]
|
||||||
pub history_filter: RegexSet,
|
pub history_filter: RegexSet,
|
||||||
@ -524,6 +525,13 @@ impl Settings {
|
|||||||
.set_default("keymap_mode", "emacs")?
|
.set_default("keymap_mode", "emacs")?
|
||||||
.set_default("keymap_mode_shell", "auto")?
|
.set_default("keymap_mode_shell", "auto")?
|
||||||
.set_default("keymap_cursor", HashMap::<String, String>::new())?
|
.set_default("keymap_cursor", HashMap::<String, String>::new())?
|
||||||
|
.set_default(
|
||||||
|
"prefers_reduced_motion",
|
||||||
|
std::env::var("NO_MOTION")
|
||||||
|
.ok()
|
||||||
|
.map(|_| config::Value::new(None, config::ValueKind::Boolean(true)))
|
||||||
|
.unwrap_or_else(|| config::Value::new(None, config::ValueKind::Boolean(false))),
|
||||||
|
)?
|
||||||
.add_source(
|
.add_source(
|
||||||
Environment::with_prefix("atuin")
|
Environment::with_prefix("atuin")
|
||||||
.prefix_separator("_")
|
.prefix_separator("_")
|
||||||
|
@ -18,6 +18,7 @@ pub struct HistoryList<'a> {
|
|||||||
inverted: bool,
|
inverted: bool,
|
||||||
/// Apply an alternative highlighting to the selected row
|
/// Apply an alternative highlighting to the selected row
|
||||||
alternate_highlight: bool,
|
alternate_highlight: bool,
|
||||||
|
now: &'a dyn Fn() -> OffsetDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -68,6 +69,7 @@ impl<'a> StatefulWidget for HistoryList<'a> {
|
|||||||
state,
|
state,
|
||||||
inverted: self.inverted,
|
inverted: self.inverted,
|
||||||
alternate_highlight: self.alternate_highlight,
|
alternate_highlight: self.alternate_highlight,
|
||||||
|
now: &self.now,
|
||||||
};
|
};
|
||||||
|
|
||||||
for item in self.history.iter().skip(state.offset).take(end - start) {
|
for item in self.history.iter().skip(state.offset).take(end - start) {
|
||||||
@ -84,12 +86,18 @@ impl<'a> StatefulWidget for HistoryList<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> HistoryList<'a> {
|
impl<'a> HistoryList<'a> {
|
||||||
pub fn new(history: &'a [History], inverted: bool, alternate_highlight: bool) -> Self {
|
pub fn new(
|
||||||
|
history: &'a [History],
|
||||||
|
inverted: bool,
|
||||||
|
alternate_highlight: bool,
|
||||||
|
now: &'a dyn Fn() -> OffsetDateTime,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
history,
|
history,
|
||||||
block: None,
|
block: None,
|
||||||
inverted,
|
inverted,
|
||||||
alternate_highlight,
|
alternate_highlight,
|
||||||
|
now,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +129,7 @@ struct DrawState<'a> {
|
|||||||
state: &'a ListState,
|
state: &'a ListState,
|
||||||
inverted: bool,
|
inverted: bool,
|
||||||
alternate_highlight: bool,
|
alternate_highlight: bool,
|
||||||
|
now: &'a dyn Fn() -> OffsetDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
// longest line prefix I could come up with
|
// longest line prefix I could come up with
|
||||||
@ -160,7 +169,7 @@ impl DrawState<'_> {
|
|||||||
// would fail.
|
// would fail.
|
||||||
// If the timestamp would otherwise be in the future, display
|
// If the timestamp would otherwise be in the future, display
|
||||||
// the time since as 0.
|
// the time since as 0.
|
||||||
let since = OffsetDateTime::now_utc() - h.timestamp;
|
let since = (self.now)() - h.timestamp;
|
||||||
let time = format_duration(since.try_into().unwrap_or_default());
|
let time = format_duration(since.try_into().unwrap_or_default());
|
||||||
|
|
||||||
// pad the time a little bit before we write. this aligns things nicely
|
// pad the time a little bit before we write. this aligns things nicely
|
||||||
|
@ -16,6 +16,7 @@ use crossterm::{
|
|||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
|
use time::OffsetDateTime;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use atuin_client::{
|
use atuin_client::{
|
||||||
@ -69,6 +70,7 @@ pub struct State {
|
|||||||
|
|
||||||
search: SearchState,
|
search: SearchState,
|
||||||
engine: Box<dyn SearchEngine>,
|
engine: Box<dyn SearchEngine>,
|
||||||
|
now: Box<dyn Fn() -> OffsetDateTime + Send>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
@ -550,7 +552,8 @@ impl State {
|
|||||||
|
|
||||||
match self.tab_index {
|
match self.tab_index {
|
||||||
0 => {
|
0 => {
|
||||||
let results_list = Self::build_results_list(style, results, self.keymap_mode);
|
let results_list =
|
||||||
|
Self::build_results_list(style, results, self.keymap_mode, &self.now);
|
||||||
f.render_stateful_widget(results_list, results_list_chunk, &mut self.results_state);
|
f.render_stateful_widget(results_list, results_list_chunk, &mut self.results_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,13 +655,18 @@ impl State {
|
|||||||
stats
|
stats
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_results_list(
|
fn build_results_list<'a>(
|
||||||
style: StyleState,
|
style: StyleState,
|
||||||
results: &[History],
|
results: &'a [History],
|
||||||
keymap_mode: KeymapMode,
|
keymap_mode: KeymapMode,
|
||||||
) -> HistoryList<'_> {
|
now: &'a dyn Fn() -> OffsetDateTime,
|
||||||
let results_list =
|
) -> HistoryList<'a> {
|
||||||
HistoryList::new(results, style.invert, keymap_mode == KeymapMode::VimNormal);
|
let results_list = HistoryList::new(
|
||||||
|
results,
|
||||||
|
style.invert,
|
||||||
|
keymap_mode == KeymapMode::VimNormal,
|
||||||
|
now,
|
||||||
|
);
|
||||||
|
|
||||||
if style.compact {
|
if style.compact {
|
||||||
results_list
|
results_list
|
||||||
@ -882,6 +890,12 @@ pub async fn history(
|
|||||||
value => value,
|
value => value,
|
||||||
},
|
},
|
||||||
current_cursor: None,
|
current_cursor: None,
|
||||||
|
now: if settings.prefers_reduced_motion {
|
||||||
|
let now = OffsetDateTime::now_utc();
|
||||||
|
Box::new(move || now)
|
||||||
|
} else {
|
||||||
|
Box::new(OffsetDateTime::now_utc)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
app.initialize_keymap_cursor(settings);
|
app.initialize_keymap_cursor(settings);
|
||||||
|
Loading…
Reference in New Issue
Block a user