diff options
| author | Mroik <mroik@delayed.space> | 2025-01-30 03:16:50 +0100 |
|---|---|---|
| committer | Mroik <mroik@delayed.space> | 2025-02-01 19:34:41 +0100 |
| commit | 20dad637b5485f706f905a777232c11a5cc2efc6 (patch) | |
| tree | 2761f939fbd7aee91489b0d16a133667746a7aaf /src/error.rs | |
| parent | 4e6e1c21d5bd0776d79b437700373cc7e4c010ae (diff) | |
Give better feedback if program errors
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs index 0da2cf7..9474203 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use std::{error::Error, fmt::Display}; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct WordTooLongError { word: String, } @@ -14,10 +14,37 @@ impl WordTooLongError { impl Display for WordTooLongError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!( - "The word \"{}\" is too long for the current terminal size", + "The word \"{}\" is too long for the current terminal size or longer than 80 characters.", self.word )) } } impl Error for WordTooLongError {} + +#[derive(Debug)] +pub struct TerminalTooSmallError; + +impl Display for TerminalTooSmallError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str( + "The terminal size is too small. Min column count is 65 and minimum row count is 15.", + ) + } +} + +#[derive(Debug)] +pub enum TyperError { + TerminalTooSmallError(TerminalTooSmallError), + WordTooLongError(WordTooLongError), +} + +impl Display for TyperError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let text = match self { + TyperError::TerminalTooSmallError(e) => e.to_string(), + TyperError::WordTooLongError(e) => e.to_string(), + }; + f.write_str(&text) + } +} |
