Skip to content

Commit b81dd6a

Browse files
author
tlipinski
committed
refactor: replace Box<dyn Error> with anyhow::Result
1 parent 72a0732 commit b81dd6a

6 files changed

Lines changed: 14 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ crossterm = { version = "0.29.0" }
2121
unicode-width = "0.2.2"
2222
itertools = "0.14.0"
2323
regex = "1.12.3"
24+
anyhow = "1.0.102"
2425

2526
[target.'cfg(target_os = "macos")'.dependencies]
2627
crossterm = { version = "0.29.0", features = ["use-dev-tty"] }

src/app.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::rura_widget::RuraWidget;
1010
use crate::theme::Theme;
1111
use crate::uicmd::{KeyBindings, UiCmd, to_ui_command};
1212
use KeyCode::{Enter, Esc, F};
13+
use anyhow::Result;
1314
use crossterm::event::KeyCode::Char;
1415
use crossterm::event::{KeyCode, KeyModifiers};
1516
use crossterm::tty::IsTty;
@@ -25,7 +26,6 @@ use ratatui::text::{Line, Text};
2526
use ratatui::widgets::{Block, BorderType, Paragraph, Widget};
2627
use ratatui::{DefaultTerminal, Frame};
2728
use serde::{Deserialize, Serialize};
28-
use std::error::Error;
2929
use std::io::{Read, Write, stdin};
3030
use std::process::{Command, Stdio};
3131
use std::sync::mpsc::{Receiver, Sender};
@@ -133,7 +133,7 @@ impl App {
133133
}
134134
}
135135

136-
pub fn run(mut self, terminal: &mut DefaultTerminal) -> Result<String, Box<dyn Error>> {
136+
pub fn run(mut self, terminal: &mut DefaultTerminal) -> Result<String> {
137137
while !self.exit {
138138
terminal.draw(|frame| self.render(frame, frame.area()))?;
139139

@@ -550,7 +550,7 @@ impl App {
550550
fn handle_command_task(
551551
command_rx: Receiver<(String, String)>,
552552
action_tx: Sender<Action>,
553-
) -> Result<(), Box<dyn Error>> {
553+
) -> Result<()> {
554554
loop {
555555
if let Ok((command, stdin)) = command_rx.recv() {
556556
info!("executing command: '{command}'");
@@ -598,7 +598,7 @@ fn handle_command_task(
598598
}
599599
}
600600

601-
fn handle_input_task(tx: Sender<Action>) -> Result<(), Box<dyn Error>> {
601+
fn handle_input_task(tx: Sender<Action>) -> Result<()> {
602602
loop {
603603
if let Ok(event) = event::read() {
604604
debug!("event: {:?}", event);
@@ -607,7 +607,7 @@ fn handle_input_task(tx: Sender<Action>) -> Result<(), Box<dyn Error>> {
607607
}
608608
}
609609

610-
fn read_stdin_task(file_opt: Option<String>, tx: Sender<Action>) -> Result<(), Box<dyn Error>> {
610+
fn read_stdin_task(file_opt: Option<String>, tx: Sender<Action>) -> Result<()> {
611611
if let Some(file) = file_opt {
612612
info!("reading file {file}");
613613
let file_content = std::fs::read_to_string(file);
@@ -641,11 +641,7 @@ fn read_stdin_task(file_opt: Option<String>, tx: Sender<Action>) -> Result<(), B
641641
}
642642
}
643643

644-
fn reset_highlight_task(
645-
rx: Receiver<()>,
646-
tx: Sender<Action>,
647-
duration_ms: u64,
648-
) -> Result<(), Box<dyn Error>> {
644+
fn reset_highlight_task(rx: Receiver<()>, tx: Sender<Action>, duration_ms: u64) -> Result<()> {
649645
loop {
650646
if let Ok(_) = rx.recv() {
651647
thread::sleep(Duration::from_millis(duration_ms));

src/debouncer.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1+
use anyhow::Result;
12
use log::{debug, error};
2-
use std::error::Error;
33
use std::sync::mpsc::{Receiver, TryRecvError};
44
use std::thread::sleep;
55
use std::time::Duration;
66

7-
pub fn debouncer_task<F>(
8-
rx: Receiver<()>,
9-
duration: Duration,
10-
on_debounce: F,
11-
) -> Result<(), Box<dyn Error + Send + Sync>>
7+
pub fn debouncer_task<F>(rx: Receiver<()>, duration: Duration, on_debounce: F) -> Result<()>
128
where
139
F: Fn() -> () + Send + 'static,
1410
{

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ mod uicmd;
1313
use crate::app::App;
1414
use crate::config::load_config;
1515
use crate::history::History;
16+
use anyhow::Result;
1617
use clap::Parser;
1718
use env_logger::{Builder, Target};
1819
use log::{LevelFilter, error, info};
1920
use props::APP_NAME;
20-
use std::error::Error;
2121
use std::fs;
2222
use std::fs::OpenOptions;
2323
use std::process::exit;
@@ -76,7 +76,7 @@ struct Args {
7676
last: bool,
7777
}
7878

79-
fn run(args: Args, config: config::Config) -> Result<(), Box<dyn Error>> {
79+
fn run(args: Args, config: config::Config) -> Result<()> {
8080
info!("Starting TUI");
8181
let mut terminal = ratatui::init();
8282

src/rura_widget.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ use crate::history::History;
33
use crate::rura::{ExecuteType, Part, Rura};
44
use crate::theme::Theme;
55
use crate::uicmd::{KeyBindings, UiCmd, to_ui_command};
6+
use anyhow::Result;
67
use crossterm::event::Event;
7-
use error::Error;
88
use itertools::Itertools;
99
use log::info;
1010
use ratatui::buffer::Buffer;
1111
use ratatui::layout::{Position, Rect};
1212
use ratatui::prelude::{Line, Style, Widget};
1313
use ratatui::style::Styled;
1414
use ratatui::text::StyledGrapheme;
15-
use std::error;
1615
use std::sync::mpsc::Sender;
1716
use tui_input::backend::crossterm::EventHandler;
1817
use tui_input::{Input, InputRequest};
@@ -183,7 +182,7 @@ impl RuraWidget {
183182
}
184183
}
185184

186-
pub fn execute(&mut self, execute_type: ExecuteType) -> Result<Option<String>, Box<dyn Error>> {
185+
pub fn execute(&mut self, execute_type: ExecuteType) -> Result<Option<String>> {
187186
if self.command_input.value().is_empty() {
188187
return Ok(None);
189188
}

0 commit comments

Comments
 (0)