diff --git a/src/config/basic.rs b/src/config/basic.rs index 730191f..3a5afb9 100644 --- a/src/config/basic.rs +++ b/src/config/basic.rs @@ -1,7 +1,7 @@ use clap::{ArgEnum, Parser}; use crate::{ - error::ParseError, + error::Error, textbuf::{alphabet, regexes}, ui, Result, }; @@ -80,7 +80,7 @@ pub enum HintStyleArg { /// Try to parse a `&str` into a tuple of `char`s. fn parse_chars(src: &str) -> Result<(char, char)> { if src.chars().count() != 2 { - return Err(ParseError::ExpectedSurroundingPair); + return Err(Error::ExpectedSurroundingPair); } let chars: Vec = src.chars().collect(); diff --git a/src/config/extended.rs b/src/config/extended.rs index 0084048..43245e3 100644 --- a/src/config/extended.rs +++ b/src/config/extended.rs @@ -4,7 +4,7 @@ use std::fmt; use clap::{ArgEnum, Parser}; use super::basic; -use crate::{error::ParseError, textbuf::alphabet, tmux, ui, Result}; +use crate::{error::Error, textbuf::alphabet, tmux, ui, Result}; /// Extended configuration for handling Tmux-specific configuration (options /// and outputs). This is only used by `tmux-copyrat` and parsed from command @@ -66,7 +66,7 @@ impl ConfigExt { "@copyrat-capture-region" => { let case_insensitive = true; config_ext.capture_region = CaptureRegion::from_str(value, case_insensitive) - .map_err(ParseError::ExpectedEnumVariant)? + .map_err(Error::ExpectedEnumVariant)? } "@copyrat-alphabet" => { inner.alphabet = alphabet::parse_alphabet(value)?; @@ -92,13 +92,13 @@ impl ConfigExt { "@copyrat-hint-alignment" => { let case_insensitive = true; inner.hint_alignment = ui::HintAlignment::from_str(value, case_insensitive) - .map_err(ParseError::ExpectedEnumVariant)? + .map_err(Error::ExpectedEnumVariant)? } "@copyrat-hint-style" => { let case_insensitive = true; inner.hint_style = Some( basic::HintStyleArg::from_str(value, case_insensitive) - .map_err(ParseError::ExpectedEnumVariant)?, + .map_err(Error::ExpectedEnumVariant)?, ) } diff --git a/src/error.rs b/src/error.rs index df97842..b05f7ce 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ // use std::fmt; #[derive(thiserror::Error, Debug)] -pub enum ParseError { +pub enum Error { #[error("Expected 2 chars")] ExpectedSurroundingPair, diff --git a/src/lib.rs b/src/lib.rs index 8efa64e..e680588 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub mod textbuf; pub mod tmux; pub mod ui; -pub type Result = std::result::Result; +pub type Result = std::result::Result; /// Run copyrat on an input string `buffer`, configured by `Opt`. /// diff --git a/src/textbuf/alphabet.rs b/src/textbuf/alphabet.rs index afcfd07..ec94d6a 100644 --- a/src/textbuf/alphabet.rs +++ b/src/textbuf/alphabet.rs @@ -1,4 +1,4 @@ -use crate::{error::ParseError, Result}; +use crate::{error::Error, Result}; /// Catalog of available alphabets. /// @@ -49,7 +49,7 @@ pub fn parse_alphabet(src: &str) -> Result { let letters = letters.replace(&['n', 'N', 'y', 'Y'][..], ""); Ok(Alphabet(letters)) } - None => Err(ParseError::UnknownAlphabet), + None => Err(Error::UnknownAlphabet), } } diff --git a/src/textbuf/regexes.rs b/src/textbuf/regexes.rs index 9ed316e..7feb89a 100644 --- a/src/textbuf/regexes.rs +++ b/src/textbuf/regexes.rs @@ -2,7 +2,7 @@ //! //! All patterns must have one capture group. The first group is used. -use crate::{error::ParseError, Result}; +use crate::{error::Error, Result}; pub(super) const EXCLUDE_PATTERNS: [(&str, &str); 1] = [("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; @@ -54,6 +54,6 @@ pub struct NamedPattern(pub String, pub String); pub(crate) fn parse_pattern_name(src: &str) -> Result { match PATTERNS.iter().find(|&(name, _pattern)| name == &src) { Some((name, pattern)) => Ok(NamedPattern(name.to_string(), pattern.to_string())), - None => Err(ParseError::UnknownPatternName), + None => Err(Error::UnknownPatternName), } } diff --git a/src/tmux.rs b/src/tmux.rs index 57edd82..8ca5fb7 100644 --- a/src/tmux.rs +++ b/src/tmux.rs @@ -10,8 +10,10 @@ use std::str::FromStr; use regex::Regex; use crate::config::extended::CaptureRegion; -use crate::{error::ParseError, Result}; +use crate::{error::Error, Result}; +/// Represents a simplified Tmux Pane, only holding the properties needed in +/// this crate. #[derive(Debug, PartialEq)] pub struct Pane { /// Pane identifier, e.g. `%37`. @@ -31,7 +33,7 @@ pub struct Pane { } impl FromStr for Pane { - type Err = ParseError; + type Err = Error; /// Parse a string containing tmux panes status into a new `Pane`. /// @@ -130,13 +132,13 @@ impl Pane { pub struct PaneId(String); impl FromStr for PaneId { - type Err = ParseError; + type Err = Error; /// Parse into PaneId. The `&str` must be start with '%' /// followed by a `u16`. fn from_str(src: &str) -> std::result::Result { if !src.starts_with('%') { - return Err(ParseError::ExpectedPaneIdMarker); + return Err(Error::ExpectedPaneIdMarker); } let id = src[1..].parse::()?; let id = format!("%{}", id); @@ -205,7 +207,7 @@ pub fn get_options(prefix: &str) -> Result> { Ok(args) } -/// Ask tmux to swap the current Pane with the target_pane (uses Tmux format). +/// Asks tmux to swap the current Pane with the target_pane (uses Tmux format). pub fn swap_pane_with(target_pane: &str) -> Result<()> { // -Z: keep the window zoomed if it was zoomed. duct::cmd!("tmux", "swap-pane", "-Z", "-s", target_pane).run()?; diff --git a/src/ui/colors.rs b/src/ui/colors.rs index e5f2c34..f598839 100644 --- a/src/ui/colors.rs +++ b/src/ui/colors.rs @@ -1,7 +1,7 @@ use clap::Parser; use termion::color; -use crate::{error::ParseError, Result}; +use crate::{error::Error, Result}; pub fn parse_color(src: &str) -> Result> { match src { @@ -22,7 +22,7 @@ pub fn parse_color(src: &str) -> Result> { "bright-cyan" | "brightcyan" => Ok(Box::new(color::LightCyan)), "bright-white" | "brightwhite" => Ok(Box::new(color::LightWhite)), "none" => Ok(Box::new(color::Reset)), - _ => Err(ParseError::UnknownColor), + _ => Err(Error::UnknownColor), } }