mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 08:00:08 +01:00
refactor: refactor
This commit is contained in:
parent
37f22b67af
commit
905bd2862c
7 changed files with 1200 additions and 884 deletions
46
src/error.rs
46
src/error.rs
|
|
@ -2,17 +2,45 @@ use std::fmt;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum ParseError {
|
||||
ExpectedSurroundingPair,
|
||||
UnknownAlphabet,
|
||||
UnknownColor,
|
||||
ExpectedSurroundingPair,
|
||||
UnknownAlphabet,
|
||||
UnknownColor,
|
||||
ExpectedPaneIdMarker,
|
||||
ExpectedInt(std::num::ParseIntError),
|
||||
ExpectedBool(std::str::ParseBoolError),
|
||||
ProcessFailure(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
ParseError::ExpectedSurroundingPair => write!(f, "Expected 2 chars"),
|
||||
ParseError::UnknownAlphabet => write!(f, "Expected a known alphabet"),
|
||||
ParseError::UnknownColor => write!(f, "Expected ANSI color name (magenta, cyan, black, ...)"),
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
ParseError::ExpectedSurroundingPair => write!(f, "Expected 2 chars"),
|
||||
ParseError::UnknownAlphabet => write!(f, "Expected a known alphabet"),
|
||||
ParseError::UnknownColor => {
|
||||
write!(f, "Expected ANSI color name (magenta, cyan, black, ...)")
|
||||
}
|
||||
ParseError::ExpectedPaneIdMarker => write!(f, "Expected pane id marker"),
|
||||
ParseError::ExpectedInt(msg) => write!(f, "Expected an int: {}", msg),
|
||||
ParseError::ExpectedBool(msg) => write!(f, "Expected a bool: {}", msg),
|
||||
ParseError::ProcessFailure(msg) => write!(f, "{}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::num::ParseIntError> for ParseError {
|
||||
fn from(error: std::num::ParseIntError) -> Self {
|
||||
ParseError::ExpectedInt(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::str::ParseBoolError> for ParseError {
|
||||
fn from(error: std::str::ParseBoolError) -> Self {
|
||||
ParseError::ExpectedBool(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ParseError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
ParseError::ProcessFailure(error.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue