mirror of https://github.com/zkat/miette.git
Add `word_splitter` support
This commit is contained in:
parent
c7db906e64
commit
69fc5c0ba9
|
|
@ -57,6 +57,7 @@ pub struct MietteHandlerOpts {
|
|||
pub(crate) with_cause_chain: Option<bool>,
|
||||
pub(crate) break_words: Option<bool>,
|
||||
pub(crate) word_separator: Option<textwrap::WordSeparator>,
|
||||
pub(crate) word_splitter: Option<textwrap::WordSplitter>,
|
||||
}
|
||||
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ pub struct GraphicalReportHandler {
|
|||
pub(crate) with_cause_chain: bool,
|
||||
pub(crate) break_words: bool,
|
||||
pub(crate) word_separator: Option<textwrap::WordSeparator>,
|
||||
pub(crate) word_splitter: Option<textwrap::WordSplitter>,
|
||||
}
|
||||
|
||||
#[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))?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue