diff options
| -rw-r--r-- | src/app.rs | 6 | ||||
| -rw-r--r-- | src/error.rs | 22 |
2 files changed, 18 insertions, 10 deletions
@@ -27,8 +27,8 @@ use crate::{ }; pub const TICK_RATE: u64 = 1000 / 20; -const MIN_TERM_COL: u16 = 40; -const MIN_TERM_ROW: u16 = 10; +pub const MIN_TERM_COL: u16 = 40; +pub const MIN_TERM_ROW: u16 = 10; const MAX_QUOTE_LINE: u16 = 80; const MIN_MARGIN: u16 = 4; @@ -80,7 +80,7 @@ impl App<'_> { for w in quote.split_whitespace().filter(|s| !s.is_empty()) { let w_len = w.chars().count(); if w_len > max as usize { - return Err(WordTooLongError::new(w)); + return Err(WordTooLongError::new(w, max)); } if w_len + counter > max as usize { diff --git a/src/error.rs b/src/error.rs index 9474203..4d4f4ab 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,21 +1,28 @@ use std::{error::Error, fmt::Display}; +use crate::app::{MIN_TERM_COL, MIN_TERM_ROW}; + #[derive(Debug, Clone)] pub struct WordTooLongError { word: String, + max_length: u16, } impl WordTooLongError { - pub fn new(word: impl Into<String>) -> WordTooLongError { - WordTooLongError { word: word.into() } + pub fn new(word: impl Into<String>, max_length: u16) -> WordTooLongError { + WordTooLongError { + word: word.into(), + max_length, + } } } 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 or longer than 80 characters.", - self.word + "The word \"{}\" is too long for the current terminal size or longer than {} characters.", + self.word, + self.max_length, )) } } @@ -27,9 +34,10 @@ 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.", - ) + f.write_fmt(format_args!( + "The terminal size is too small. Min column count is {} and minimum row count is {}.", + MIN_TERM_COL, MIN_TERM_ROW + )) } } |
