diff --git a/Cargo.lock b/Cargo.lock index 2e7eff1..a8ecd60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,6 +103,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "anyhow" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + [[package]] name = "autocfg" version = "1.4.0" @@ -381,33 +387,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "color-eyre" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - [[package]] name = "colorchoice" version = "1.0.3" @@ -709,16 +688,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - [[package]] name = "fastrand" version = "2.3.0" @@ -888,12 +857,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - [[package]] name = "indexmap" version = "2.7.1" @@ -1272,12 +1235,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" - [[package]] name = "parking_lot" version = "0.12.3" @@ -1846,10 +1803,10 @@ dependencies = [ name = "television" version = "0.9.4" dependencies = [ + "anyhow", "bat", "better-panic", "clap", - "color-eyre", "copypasta", "criterion", "crossterm", @@ -2070,16 +2027,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-error" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" -dependencies = [ - "tracing", - "tracing-subscriber", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -2101,7 +2048,6 @@ dependencies = [ "nu-ansi-term 0.46.0", "once_cell", "regex", - "serde", "sharded-slab", "smallvec", "thread_local", diff --git a/Cargo.toml b/Cargo.toml index 8211801..27c7daa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,13 +30,13 @@ path = "television/lib.rs" [dependencies] television-derive = { path = "television-derive", version = "0.0.23" } +anyhow = "1.0" directories = "5.0" devicons = "0.6" -color-eyre = { version = "0.6" } lazy_static = "1.5" tokio = { version = "1.43", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter", "serde"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } rustc-hash = "2.1" syntect = { version = "5.2", default-features = false } unicode-width = "0.2" @@ -69,7 +69,7 @@ toml = "0.8" winapi-util = "0.1.9" [dev-dependencies] -criterion = "0.5.1" +criterion = "0.5" [features] simd = ["dep:simdutf8"] diff --git a/television/app.rs b/television/app.rs index 8acbf22..30329b0 100644 --- a/television/app.rs +++ b/television/app.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashSet; use std::sync::Arc; use crate::screen::mode::Mode; -use color_eyre::Result; +use anyhow::Result; use tokio::sync::{mpsc, Mutex}; use tracing::{debug, info}; diff --git a/television/cable.rs b/television/cable.rs index 8ee9466..ac84b2b 100644 --- a/television/cable.rs +++ b/television/cable.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use rustc_hash::FxHashMap; use crate::channels::cable::{CableChannelPrototype, CableChannels}; -use color_eyre::Result; +use anyhow::Result; use tracing::{debug, error}; use crate::config::get_config_dir; diff --git a/television/channels/cable.rs b/television/channels/cable.rs index 22189f7..660742f 100644 --- a/television/channels/cable.rs +++ b/television/channels/cable.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; use std::io::{BufRead, BufReader}; use std::process::Stdio; -use color_eyre::Result; +use anyhow::Result; use lazy_static::lazy_static; use regex::Regex; use rustc_hash::{FxBuildHasher, FxHashSet}; diff --git a/television/channels/mod.rs b/television/channels/mod.rs index c259aac..0579ebf 100644 --- a/television/channels/mod.rs +++ b/television/channels/mod.rs @@ -1,5 +1,5 @@ use crate::channels::entry::Entry; -use color_eyre::Result; +use anyhow::Result; use rustc_hash::FxHashSet; use television_derive::{Broadcast, ToCliChannel, ToUnitChannel}; diff --git a/television/channels/remote_control.rs b/television/channels/remote_control.rs index a6b6767..f2530a2 100644 --- a/television/channels/remote_control.rs +++ b/television/channels/remote_control.rs @@ -5,8 +5,8 @@ use crate::channels::cable::{CableChannelPrototype, CableChannels}; use crate::channels::entry::{Entry, PreviewType}; use crate::channels::{CliTvChannel, OnAir, TelevisionChannel, UnitChannel}; use crate::matcher::{config::Config, Matcher}; +use anyhow::Result; use clap::ValueEnum; -use color_eyre::Result; use devicons::FileIcon; use rustc_hash::{FxBuildHasher, FxHashSet}; @@ -83,7 +83,7 @@ impl RemoteControl { } None => match UnitChannel::try_from(channel_name) { Ok(channel) => Ok(channel.into()), - Err(_) => Err(color_eyre::eyre::eyre!( + Err(_) => Err(anyhow::anyhow!( "No channel or cable channel prototype found for {}", channel_name )), diff --git a/television/cli.rs b/television/cli.rs index 66d6e2d..9cc1fbc 100644 --- a/television/cli.rs +++ b/television/cli.rs @@ -1,8 +1,8 @@ use rustc_hash::FxHashMap; use std::path::Path; +use anyhow::{anyhow, Result}; use clap::{Parser, Subcommand, ValueEnum}; -use color_eyre::{eyre::eyre, Result}; use tracing::debug; use crate::channels::{ @@ -186,7 +186,7 @@ fn parse_channel(channel: &str) -> Result { // try to parse the channel as a builtin channel CliTvChannel::try_from(channel) .map(ParsedCliChannel::Builtin) - .map_err(|_| eyre!("Unknown channel: {}", channel)) + .map_err(|_| anyhow!("Unknown channel: {}", channel)) }, |(_, v)| Ok(ParsedCliChannel::Cable(v.clone())), ) @@ -251,7 +251,7 @@ pub fn guess_channel_from_prompt( if prompt.trim().is_empty() { return match command_mapping.get("") { Some(channel) => parse_channel(channel), - None => Err(eyre!("No channel found for prompt: {}", prompt)), + None => Err(anyhow!("No channel found for prompt: {}", prompt)), }; } let rev_prompt_words = prompt.split_whitespace().rev(); @@ -280,7 +280,7 @@ pub fn guess_channel_from_prompt( // reset the stack stack.clear(); } - Err(eyre!("No channel found for prompt: {}", prompt)) + Err(anyhow!("No channel found for prompt: {}", prompt)) } #[allow(clippy::unnecessary_wraps)] diff --git a/television/config/keybindings.rs b/television/config/keybindings.rs index 282a560..140eb3d 100644 --- a/television/config/keybindings.rs +++ b/television/config/keybindings.rs @@ -77,7 +77,7 @@ pub enum SerializedBinding { } impl<'de> Deserialize<'de> for KeyBindings { - fn deserialize(deserializer: D) -> color_eyre::Result + fn deserialize(deserializer: D) -> anyhow::Result where D: Deserializer<'de>, { @@ -123,7 +123,7 @@ impl<'de> Deserialize<'de> for KeyBindings { } } -pub fn parse_key_event(raw: &str) -> color_eyre::Result { +pub fn parse_key_event(raw: &str) -> anyhow::Result { let raw_lower = raw.to_ascii_lowercase(); let (remaining, modifiers) = extract_modifiers(&raw_lower); parse_key_code_with_modifiers(remaining, modifiers) @@ -157,7 +157,7 @@ fn extract_modifiers(raw: &str) -> (&str, KeyModifiers) { fn parse_key_code_with_modifiers( raw: &str, mut modifiers: KeyModifiers, -) -> color_eyre::Result { +) -> anyhow::Result { let c = match raw { "esc" => KeyCode::Esc, "enter" => KeyCode::Enter, @@ -267,7 +267,7 @@ pub fn key_event_to_string(key_event: &KeyEvent) -> String { key } -pub fn parse_key(raw: &str) -> color_eyre::Result { +pub fn parse_key(raw: &str) -> anyhow::Result { if raw.chars().filter(|c| *c == '>').count() != raw.chars().filter(|c| *c == '<').count() { diff --git a/television/config/mod.rs b/television/config/mod.rs index c5dcedb..d8bc1c8 100644 --- a/television/config/mod.rs +++ b/television/config/mod.rs @@ -1,7 +1,7 @@ #![allow(clippy::module_name_repetitions)] use std::{env, path::PathBuf}; -use color_eyre::{eyre::Context, Result}; +use anyhow::Result; use directories::ProjectDirs; use keybindings::merge_keybindings; pub use keybindings::{parse_key, Binding, KeyBindings}; @@ -82,7 +82,7 @@ impl Config { pub fn new() -> Result { // Load the default_config values as base defaults let default_config: Config = toml::from_str(DEFAULT_CONFIG) - .wrap_err("Error parsing default config")?; + .expect("Error parsing default config"); // initialize the config builder let data_dir = get_data_dir(); @@ -99,8 +99,12 @@ impl Config { let path = config_dir.join(CONFIG_FILE_NAME); let contents = std::fs::read_to_string(&path)?; - let cfg: Config = toml::from_str(&contents) - .wrap_err(format!("error parsing config: {path:?}"))?; + let cfg: Config = toml::from_str(&contents).unwrap_or_else(|_| { + warn!( + "Error parsing config file, using default configuration" + ); + default_config.clone() + }); // merge keybindings with default keybindings let keybindings = merge_keybindings( diff --git a/television/config/themes.rs b/television/config/themes.rs index 01c9ddf..2708278 100644 --- a/television/config/themes.rs +++ b/television/config/themes.rs @@ -1,4 +1,4 @@ -use color_eyre::Result; +use anyhow::Result; use std::path::PathBuf; use crate::screen::colors::{ diff --git a/television/errors.rs b/television/errors.rs index 818064c..9de663c 100644 --- a/television/errors.rs +++ b/television/errors.rs @@ -1,43 +1,31 @@ -use std::env; +use std::panic; -use color_eyre::Result; +use anyhow::Result; use tracing::error; pub fn init() -> Result<()> { - let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() - .panic_section(format!( - "This is a bug. Consider reporting it at {}", - env!("CARGO_PKG_REPOSITORY") - )) - .capture_span_trace_by_default(false) - .display_location_section(false) - .display_env_section(false) - .into_hooks(); - eyre_hook.install()?; - std::panic::set_hook(Box::new(move |panic_info| { + panic::set_hook(Box::new(move |panic_info| { + // Clean up the terminal if let Ok(mut t) = crate::tui::Tui::new(std::io::stderr()) { - if let Err(r) = t.exit() { - error!("Unable to exit Terminal: {:?}", r); + if let Err(err) = t.exit() { + error!("Unable to exit terminal: {:?}", err); } } + // In release builds, use human-panic to generate a friendly crash report: #[cfg(not(debug_assertions))] { use human_panic::{handle_dump, metadata, print_msg}; - let metadata = metadata!(); - let file_path = handle_dump(&metadata, panic_info); - // prints human-panic message - print_msg(file_path, &metadata).expect( + let meta = metadata!(); + let file_path = handle_dump(&meta, panic_info); + print_msg(file_path, &meta).expect( "human-panic: printing error message to console failed", ); - eprintln!("{}", panic_hook.panic_report(panic_info)); // prints color-eyre stack trace to stderr } - let msg = format!("{}", panic_hook.panic_report(panic_info)); - error!("Error: {}", msg); + // In debug builds, use better-panic for a more detailed dev stacktrace: #[cfg(debug_assertions)] { - // Better Panic stacktrace that is only enabled when debugging. better_panic::Settings::auto() .most_recent_first(false) .lineno_suffix(true) @@ -47,31 +35,6 @@ pub fn init() -> Result<()> { std::process::exit(1); })); + Ok(()) } - -/// Similar to the `std::dbg!` macro, but generates `tracing` events rather -/// than printing to stdout. -/// -/// By default, the verbosity level for the generated events is `DEBUG`, but -/// this can be customized. -#[macro_export] -macro_rules! trace_dbg { - (target: $target:expr, level: $level:expr, $ex:expr) => {{ - match $ex { - value => { - tracing::event!(target: $target, $level, ?value, stringify!($ex)); - value - } - } - }}; - (level: $level:expr, $ex:expr) => { - trace_dbg!(target: module_path!(), level: $level, $ex) - }; - (target: $target:expr, $ex:expr) => { - trace_dbg!(target: $target, level: tracing::Level::DEBUG, $ex) - }; - ($ex:expr) => { - trace_dbg!(level: tracing::Level::DEBUG, $ex) - }; -} diff --git a/television/keymap.rs b/television/keymap.rs index 2090fb7..d660dd1 100644 --- a/television/keymap.rs +++ b/television/keymap.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use std::ops::Deref; use crate::screen::mode::Mode; -use color_eyre::Result; +use anyhow::Result; use crate::action::Action; use crate::config::{Binding, KeyBindings}; @@ -47,9 +47,10 @@ impl Keymap { mode: Mode, mappings: Vec<(Key, Action)>, ) -> Result { - let mode_keymap = self.0.get_mut(&mode).ok_or_else(|| { - color_eyre::eyre::eyre!("Mode {:?} not found", mode) - })?; + let mode_keymap = self + .0 + .get_mut(&mode) + .ok_or_else(|| anyhow::anyhow!("Mode {:?} not found", mode))?; for (key, action) in mappings { mode_keymap.insert(key, action); } diff --git a/television/logging.rs b/television/logging.rs index 9436d3c..8913fcc 100644 --- a/television/logging.rs +++ b/television/logging.rs @@ -1,4 +1,4 @@ -use color_eyre::Result; +use anyhow::Result; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use crate::config::get_data_dir; diff --git a/television/main.rs b/television/main.rs index 9119582..0bec8f2 100644 --- a/television/main.rs +++ b/television/main.rs @@ -3,8 +3,8 @@ use std::io::{stdout, BufWriter, IsTerminal, Write}; use std::path::Path; use std::process::exit; +use anyhow::Result; use clap::Parser; -use color_eyre::Result; use tracing::{debug, error, info}; use television::app::App; diff --git a/television/render.rs b/television/render.rs index f13b95b..2bf21d9 100644 --- a/television/render.rs +++ b/television/render.rs @@ -1,4 +1,4 @@ -use color_eyre::Result; +use anyhow::Result; use ratatui::layout::Rect; use std::{ io::{stderr, stdout, LineWriter}, diff --git a/television/screen/input.rs b/television/screen/input.rs index 11dbb9f..b7db944 100644 --- a/television/screen/input.rs +++ b/television/screen/input.rs @@ -1,5 +1,5 @@ use crate::utils::input::Input; -use color_eyre::Result; +use anyhow::Result; use ratatui::{ layout::{ Alignment, Constraint, Direction, Layout as RatatuiLayout, Rect, diff --git a/television/screen/preview.rs b/television/screen/preview.rs index 53a87f8..8005337 100644 --- a/television/screen/preview.rs +++ b/television/screen/preview.rs @@ -11,7 +11,7 @@ use crate::utils::strings::{ replace_non_printable, shrink_with_ellipsis, ReplaceNonPrintableConfig, EMPTY_STRING, }; -use color_eyre::eyre::Result; +use anyhow::Result; use devicons::FileIcon; use ratatui::widgets::{Block, BorderType, Borders, Padding, Paragraph, Wrap}; use ratatui::Frame; diff --git a/television/screen/remote_control.rs b/television/screen/remote_control.rs index b84d285..905ddaf 100644 --- a/television/screen/remote_control.rs +++ b/television/screen/remote_control.rs @@ -7,7 +7,7 @@ use crate::screen::mode::{mode_color, Mode}; use crate::screen::results::build_results_list; use crate::utils::input::Input; -use color_eyre::eyre::Result; +use anyhow::Result; use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; use ratatui::prelude::Style; use ratatui::style::{Color, Stylize}; diff --git a/television/screen/results.rs b/television/screen/results.rs index dfc40cb..f20b26e 100644 --- a/television/screen/results.rs +++ b/television/screen/results.rs @@ -5,7 +5,7 @@ use crate::utils::strings::{ make_matched_string_printable, next_char_boundary, slice_at_char_boundaries, }; -use color_eyre::eyre::Result; +use anyhow::Result; use ratatui::layout::{Alignment, Rect}; use ratatui::prelude::{Color, Line, Span, Style}; use ratatui::style::Stylize; diff --git a/television/television.rs b/television/television.rs index 1a447a8..3ab0806 100644 --- a/television/television.rs +++ b/television/television.rs @@ -24,7 +24,7 @@ use crate::screen::spinner::{Spinner, SpinnerState}; use crate::utils::metadata::AppMetadata; use crate::utils::strings::EMPTY_STRING; use crate::{cable::load_cable_channels, keymap::Keymap}; -use color_eyre::Result; +use anyhow::Result; use copypasta::{ClipboardContext, ClipboardProvider}; use ratatui::{layout::Rect, style::Color, Frame}; use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; diff --git a/television/tui.rs b/television/tui.rs index 2d40ba9..2281781 100644 --- a/television/tui.rs +++ b/television/tui.rs @@ -3,7 +3,7 @@ use std::{ ops::{Deref, DerefMut}, }; -use color_eyre::Result; +use anyhow::Result; use crossterm::{ cursor, execute, terminal::{ diff --git a/television/utils/shell.rs b/television/utils/shell.rs index 3d9d0bb..5b546e1 100644 --- a/television/utils/shell.rs +++ b/television/utils/shell.rs @@ -1,4 +1,4 @@ -use color_eyre::Result; +use anyhow::Result; #[derive(Debug, Clone, Copy, PartialEq)] pub enum Shell { @@ -18,9 +18,6 @@ pub fn completion_script(shell: Shell) -> Result<&'static str> { Shell::Bash => Ok(COMPLETION_BASH), Shell::Zsh => Ok(COMPLETION_ZSH), Shell::Fish => Ok(COMPLETION_FISH), - _ => color_eyre::eyre::bail!( - "This shell is not yet supported: {:?}", - shell - ), + _ => anyhow::bail!("This shell is not yet supported: {:?}", shell), } } diff --git a/television/utils/syntax.rs b/television/utils/syntax.rs index f18e1b3..35acff9 100644 --- a/television/utils/syntax.rs +++ b/television/utils/syntax.rs @@ -1,5 +1,5 @@ +use anyhow::Result; use bat::assets::HighlightingAssets; -use color_eyre::Result; use gag::Gag; use std::path::{Path, PathBuf}; use syntect::easy::HighlightLines;