use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Failed to initialize terminal: {0}")]
InitializationError(String),
#[error("Window operation failed: {0}")]
WindowError(String),
#[error("Position ({x}, {y}) is outside window bounds of ({width}, {height})")]
OutOfBoundsError {
x: u16,
y: u16,
width: u16,
height: u16,
},
#[error(
"Box position (x1: {x1}, y1: {y1}) - (x2: {x2}, y2: {y2}) is outside window bounds of ({width}, {height})"
)]
BoxOutOfBoundsError {
x1: u16,
y1: u16,
x2: u16,
y2: u16,
width: u16,
height: u16,
},
#[error("Line at y: {y} out of bounds for window height of {height}")]
LineOutOfBoundsError {
y: u16,
height: u16,
},
#[error("Buffer operation failed: {0}")]
BufferError(String),
#[error("Attempt to write at ({x},{y}) exceeds buffer size {width}x{height}")]
BufferSizeError {
x: u16,
y: u16,
width: u16,
height: u16,
},
#[error("Widget error: {0}")]
WidgetError(String),
#[error("Widget validation failed: {message}")]
WidgetValidationError {
message: String,
},
#[error("Input error: {0}")]
InputError(String),
#[error("Color error: {0}")]
ColorError(String),
#[error("Render error: {0}")]
RenderError(String),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
}
impl Error {
pub fn widget_validation(message: impl Into<String>) -> Self {
Self::WidgetValidationError {
message: message.into(),
}
}
pub fn render(message: impl Into<String>) -> Self {
Self::RenderError(message.into())
}
pub fn buffer(message: impl Into<String>) -> Self {
Self::BufferError(message.into())
}
}
pub type Result<T> = std::result::Result<T, Error>;