aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/client
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2022-10-14 10:59:21 +0100
committerGitHub <noreply@github.com>2022-10-14 10:59:21 +0100
commitf03f6e9ad74d8e1cf1fa33dc2c0c7c5dd7ae5c94 (patch)
treeaa03f60230b3bc96485806724383bfd6e4cc6b1d /src/command/client
parentFix ZSH import print (diff)
downloadatuin-f03f6e9ad74d8e1cf1fa33dc2c0c7c5dd7ae5c94.zip
Add automatic update checking (#555)
* Add automatic update checking * Add setting to opt out of update checks * Document options * no * no * also no * Make clippy happy * Update atuin-client/src/settings.rs Co-authored-by: Conrad Ludgate <conradludgate@gmail.com> * fix features Co-authored-by: Conrad Ludgate <conradludgate@gmail.com> Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
Diffstat (limited to '')
-rw-r--r--src/command/client/history.rs1
-rw-r--r--src/command/client/search.rs9
-rw-r--r--src/command/client/search/interactive.rs37
3 files changed, 27 insertions, 20 deletions
diff --git a/src/command/client/history.rs b/src/command/client/history.rs
index fe5bfcbe..07f4b319 100644
--- a/src/command/client/history.rs
+++ b/src/command/client/history.rs
@@ -15,6 +15,7 @@ use atuin_client::{
#[cfg(feature = "sync")]
use atuin_client::sync;
+use log::debug;
use super::search::format_duration;
diff --git a/src/command/client/search.rs b/src/command/client/search.rs
index eda20ac5..1cef1ffc 100644
--- a/src/command/client/search.rs
+++ b/src/command/client/search.rs
@@ -63,14 +63,7 @@ pub struct Cmd {
impl Cmd {
pub async fn run(self, db: &mut impl Database, settings: &Settings) -> Result<()> {
if self.interactive {
- let item = interactive::history(
- &self.query,
- settings.search_mode,
- settings.filter_mode,
- settings.style,
- db,
- )
- .await?;
+ let item = interactive::history(&self.query, settings, db).await?;
eprintln!("{}", item);
} else {
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
diff --git a/src/command/client/search/interactive.rs b/src/command/client/search/interactive.rs
index 069b7f3c..950a971d 100644
--- a/src/command/client/search/interactive.rs
+++ b/src/command/client/search/interactive.rs
@@ -1,6 +1,7 @@
use std::io::stdout;
use eyre::Result;
+use semver::Version;
use termion::{
event::Event as TermEvent, event::Key, event::MouseButton, event::MouseEvent,
input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen,
@@ -20,7 +21,7 @@ use atuin_client::{
database::Context,
database::Database,
history::History,
- settings::{FilterMode, SearchMode},
+ settings::{FilterMode, SearchMode, Settings},
};
use super::{
@@ -36,6 +37,7 @@ struct State {
filter_mode: FilterMode,
results_state: ListState,
context: Context,
+ update_needed: Option<Version>,
}
impl State {
@@ -143,10 +145,19 @@ impl State {
.constraints([Constraint::Length(1); 3])
.split(top_chunks[1]);
- let title = Paragraph::new(Text::from(Span::styled(
- format!(" Atuin v{VERSION}"),
- Style::default().add_modifier(Modifier::BOLD),
- )));
+ let title = if self.update_needed.is_some() {
+ let version = self.update_needed.clone().unwrap();
+
+ Paragraph::new(Text::from(Span::styled(
+ format!(" Atuin v{VERSION} - UPDATE AVAILABLE {version}"),
+ Style::default().add_modifier(Modifier::BOLD).fg(Color::Red),
+ )))
+ } else {
+ Paragraph::new(Text::from(Span::styled(
+ format!(" Atuin v{VERSION}"),
+ Style::default().add_modifier(Modifier::BOLD),
+ )))
+ };
let help = vec![
Span::raw(" Press "),
@@ -277,9 +288,7 @@ impl State {
#[allow(clippy::cast_possible_truncation)]
pub async fn history(
query: &[String],
- search_mode: SearchMode,
- filter_mode: FilterMode,
- style: atuin_client::settings::Style,
+ settings: &Settings,
db: &mut impl Database,
) -> Result<String> {
let stdout = stdout().into_raw_mode()?;
@@ -294,15 +303,19 @@ pub async fn history(
let mut input = Cursor::from(query.join(" "));
// Put the cursor at the end of the query by default
input.end();
+
+ let update_needed = settings.needs_update().await;
+
let mut app = State {
history_count: db.history_count().await?,
input,
results_state: ListState::default(),
context: current_context(),
- filter_mode,
+ filter_mode: settings.filter_mode,
+ update_needed,
};
- let mut results = app.query_results(search_mode, db).await?;
+ let mut results = app.query_results(settings.search_mode, db).await?;
let index = 'render: loop {
let initial_input = app.input.as_str().to_owned();
@@ -323,10 +336,10 @@ pub async fn history(
}
if initial_input != app.input.as_str() || initial_filter_mode != app.filter_mode {
- results = app.query_results(search_mode, db).await?;
+ results = app.query_results(settings.search_mode, db).await?;
}
- let compact = match style {
+ let compact = match settings.style {
atuin_client::settings::Style::Auto => {
terminal.size().map(|size| size.height < 14).unwrap_or(true)
}