diff --git a/src/handler.rs b/src/handler.rs index 7a4ff41..e32f3ef 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -57,6 +57,7 @@ pub struct MietteHandlerOpts { pub(crate) with_cause_chain: Option, pub(crate) break_words: Option, pub(crate) word_separator: Option, + pub(crate) word_splitter: Option, } impl MietteHandlerOpts { @@ -104,6 +105,11 @@ impl MietteHandlerOpts { self } + /// Sets the `textwrap::WordSplitter` to use when determining wrap points. + pub fn word_splitter(mut self, word_splitter: textwrap::WordSplitter) -> Self { + self.word_splitter = Some(word_splitter); + self + } /// Include the cause chain of the top-level error in the report. pub fn with_cause_chain(mut self) -> Self { self.with_cause_chain = Some(true); @@ -257,6 +263,9 @@ impl MietteHandlerOpts { if let Some(s) = self.word_separator { handler = handler.with_word_separator(s) } + if let Some(s) = self.word_splitter { + handler = handler.with_word_splitter(s) + } MietteHandler { inner: Box::new(handler), diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index 81a0de7..35e9c79 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -32,6 +32,7 @@ pub struct GraphicalReportHandler { pub(crate) with_cause_chain: bool, pub(crate) break_words: bool, pub(crate) word_separator: Option, + pub(crate) word_splitter: Option, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -55,6 +56,7 @@ impl GraphicalReportHandler { with_cause_chain: true, break_words: true, word_separator: None, + word_splitter: None, } } @@ -70,6 +72,7 @@ impl GraphicalReportHandler { with_cause_chain: true, break_words: true, word_separator: None, + word_splitter: None, } } @@ -134,12 +137,18 @@ impl GraphicalReportHandler { self } - /// Sets the word separator when wrapping. + /// Sets the word separator to use when wrapping. pub fn with_word_separator(mut self, word_separator: textwrap::WordSeparator) -> Self { self.word_separator = Some(word_separator); self } + /// Sets the word splitter to usewhen wrapping. + pub fn with_word_splitter(mut self, word_splitter: textwrap::WordSplitter) -> Self { + self.word_splitter = Some(word_splitter); + self + } + /// Sets the 'global' footer for this handler. pub fn with_footer(mut self, footer: String) -> Self { self.footer = Some(footer); @@ -184,6 +193,9 @@ impl GraphicalReportHandler { if let Some(word_separator) = self.word_separator { opts = opts.word_separator(word_separator); } + if let Some(word_splitter) = self.word_splitter.clone() { + opts = opts.word_splitter(word_splitter); + } writeln!(f, "{}", textwrap::fill(footer, opts))?; } @@ -242,6 +254,9 @@ impl GraphicalReportHandler { if let Some(word_separator) = self.word_separator { opts = opts.word_separator(word_separator); } + if let Some(word_splitter) = self.word_splitter.clone() { + opts = opts.word_splitter(word_splitter); + } writeln!(f, "{}", textwrap::fill(&diagnostic.to_string(), opts))?; @@ -285,6 +300,9 @@ impl GraphicalReportHandler { if let Some(word_separator) = self.word_separator { opts = opts.word_separator(word_separator); } + if let Some(word_splitter) = self.word_splitter.clone() { + opts = opts.word_splitter(word_splitter); + } match error { ErrorKind::Diagnostic(diag) => { @@ -319,6 +337,9 @@ impl GraphicalReportHandler { if let Some(word_separator) = self.word_separator { opts = opts.word_separator(word_separator); } + if let Some(word_splitter) = self.word_splitter.clone() { + opts = opts.word_splitter(word_splitter); + } writeln!(f, "{}", textwrap::fill(&help.to_string(), opts))?; }