From 2882ed796bab2406f505e5db2074d04092087e60 Mon Sep 17 00:00:00 2001 From: Ninjani <48680156+Ninjani@users.noreply.github.com> Date: Tue, 26 Dec 2023 17:00:56 +0100 Subject: [PATCH] Update and fix #152 --- Cargo.toml | 40 ++++++++++++++++++++-------------------- src/errors.rs | 7 +++++-- src/language.rs | 8 +++++--- src/utils.rs | 8 ++++---- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efbd032..4701802 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,58 +17,58 @@ exclude = [ [dependencies] # Argument parsing -clap = { version = "4.2.4", features = ["derive"] } -clap_complete = "4.2.1" +clap = { version = "4.4.11", features = ["derive"] } +clap_complete = "4.4.4" # Configuration management confy = "0.5.1" directories-next = "1.0.2" # Error management -eyre = "0.6.8" +eyre = "0.6.11" color-eyre = { version = "0.6.2", default-features = false } -thiserror = "1.0.40" +thiserror = "1.0.52" # Database related sled = "0.34.7" bincode = "1.3.3" # Serializing -serde = "1.0.160" -serde_json = "1.0.96" -serde_derive = "1.0.160" -serde_yaml = "0.9.21" +serde = "1.0.193" +serde_json = "1.0.108" +serde_derive = "1.0.193" +serde_yaml = "0.9.29" # Parsing and manipulating dates -chrono = { version = "0.4.24", features = ["serde"] } +chrono = { version = "0.4.31", features = ["serde"] } chrono-english = "0.1.7" # Taking user input and showing progress -dialoguer = {version = "0.11.0", features = ["completion", "history", "fuzzy-select"]} -indicatif = "0.17.3" +dialoguer = { version = "0.11.0", features = ["completion", "history", "fuzzy-select"] } +indicatif = "0.17.7" # Fuzzy search skim = "0.10.4" # Terminal syntax highlighting -syntect = { version = "5.0.0", default-features = false, features = ["default-fancy"] } +syntect = { version = "5.1.0", default-features = false, features = ["default-fancy"] } hex = "0.4.3" -grep-cli = "0.1.7" -termcolor = "1.2.0" +grep-cli = "0.1.10" +termcolor = "1.4.0" # Sync to Gist/GitLab -ureq = { version = "2.6.2", features = ["json"] } +ureq = { version = "2.9.1", features = ["json"] } strum = "0.25.0" strum_macros = "0.25.3" # pattern filter and filling shell script variables -regex = "1.8.1" +regex = "1.10.2" [dev-dependencies] -assert_cmd = "2.0.11" -predicates = "3.0.3" -tempfile = "3.5.0" -expectrl = "0.7.0" +assert_cmd = "2.0.12" +predicates = "3.0.4" +tempfile = "3.8.1" +expectrl = "0.7.1" [target.'cfg(target_os = "macos")'.dev-dependencies] clipboard = "0.5.0" diff --git a/src/errors.rs b/src/errors.rs index cc61bc2..8eb56da 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -26,8 +26,11 @@ pub enum LostTheWay { #[error("ThemeError: {theme:?}")] ThemeError { theme: String }, /// Thrown when trying to load a syntax which hasn't been added / doesn't exist - #[error("SyntaxError: {syntax:?}")] - SyntaxError { syntax: String }, + #[error("SyntaxError: {message:?} {syntax_file:?}")] + SyntaxError { + syntax_file: String, + message: String, + }, /// Thrown when there's an error while trying to access system clipboard #[error("ClipboardError: Couldn't copy to clipboard - {message}")] ClipboardError { message: String }, diff --git a/src/language.rs b/src/language.rs index 6a3e870..497a17e 100644 --- a/src/language.rs +++ b/src/language.rs @@ -308,8 +308,9 @@ impl CodeHighlight { true, None, ) - .map_err(|_e| LostTheWay::SyntaxError { - syntax: syntax_file.to_str().unwrap().into(), + .map_err(|e| LostTheWay::SyntaxError { + syntax_file: syntax_file.to_str().unwrap().into(), + message: e.to_string(), }) .suggestion(format!( "Couldn't load a syntax from {}, are you sure this is a valid .sublime-syntax file with a \'name\' key?", @@ -319,7 +320,8 @@ impl CodeHighlight { .file_name() .and_then(std::ffi::OsStr::to_str) .ok_or(LostTheWay::SyntaxError { - syntax: syntax_file.to_str().unwrap().into(), + syntax_file: syntax_file.to_str().unwrap().into(), + message: String::from("Filename is not valid Unicode"), }) .suggestion("Something's fishy with the filename, valid Unicode?")?; // Copy syntax file to syntect dir diff --git a/src/utils.rs b/src/utils.rs index 3425d6d..ec50a59 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ use std::collections::HashSet; -use std::io::Write; +use std::io::{IsTerminal, Write}; use std::process::{Command, Stdio}; use std::str; @@ -140,13 +140,13 @@ pub fn parse_date(date_string: &str) -> color_eyre::Result> { /// Some(date) => date /// None => minimum possible date pub fn date_start(from_date: Option>) -> DateTime { - from_date.unwrap_or_else(|| DateTime::from_utc(NaiveDateTime::MIN, Utc)) + from_date.unwrap_or_else(|| DateTime::from_naive_utc_and_offset(NaiveDateTime::MIN, Utc)) } /// Some(date) => date /// None => maximum possible date pub fn date_end(to_date: Option>) -> DateTime { - to_date.unwrap_or_else(|| DateTime::from_utc(NaiveDateTime::MAX, Utc)) + to_date.unwrap_or_else(|| DateTime::from_naive_utc_and_offset(NaiveDateTime::MAX, Utc)) } /// Gets input from external editor, optionally displays default text in editor @@ -247,7 +247,7 @@ pub fn smart_print( write!( grep_cli::stdout(termcolor::ColorChoice::Auto), "{}", - if !plain & (grep_cli::is_tty_stdout() | colorize) { + if !plain & (std::io::stdout().is_terminal() | colorize) { highlight_strings(inputs, bg) } else { inputs