diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index 37b6bf8..7d62e31 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -1,6 +1,8 @@ use std::fmt::{self, Write}; use owo_colors::{OwoColorize, Style, StyledList}; +use textwrap::WordSeparator; +use textwrap::WordSplitter; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use crate::diagnostic_chain::{DiagnosticChain, ErrorKind}; @@ -61,7 +63,7 @@ impl GraphicalReportHandler { tab_width: 4, with_cause_chain: true, wrap_lines: true, - break_words: true, + break_words: false, with_primary_span_start: true, word_separator: None, word_splitter: None, @@ -83,7 +85,7 @@ impl GraphicalReportHandler { wrap_lines: true, with_cause_chain: true, with_primary_span_start: true, - break_words: true, + break_words: false, word_separator: None, word_splitter: None, highlighter: MietteHighlighter::default(), @@ -262,16 +264,16 @@ impl GraphicalReportHandler { if let Some(footer) = &self.footer { writeln!(f)?; let width = self.termwidth.saturating_sub(2); - let mut opts = textwrap::Options::new(width) + let opts = textwrap::Options::new(width) .initial_indent(" ") .subsequent_indent(" ") - .break_words(self.break_words); - 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); - } + .break_words(self.break_words) + .word_separator(self.word_separator.unwrap_or(WordSeparator::AsciiSpace)) + .word_splitter( + self.word_splitter + .clone() + .unwrap_or(WordSplitter::NoHyphenation), + ); writeln!(f, "{}", self.wrap(footer, opts))?; } @@ -340,16 +342,16 @@ impl GraphicalReportHandler { let initial_indent = format!(" {} ", severity_icon.style(severity_style)); let rest_indent = format!(" {} ", self.theme.characters.vbar.style(severity_style)); let width = self.termwidth.saturating_sub(2); - let mut opts = textwrap::Options::new(width) + let opts = textwrap::Options::new(width) .initial_indent(&initial_indent) .subsequent_indent(&rest_indent) - .break_words(self.break_words); - 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); - } + .break_words(self.break_words) + .word_separator(self.word_separator.unwrap_or(WordSeparator::AsciiSpace)) + .word_splitter( + self.word_splitter + .clone() + .unwrap_or(WordSplitter::NoHyphenation), + ); writeln!(f, "{}", self.wrap(&diagnostic.to_string(), opts))?; @@ -386,16 +388,16 @@ impl GraphicalReportHandler { ) .style(severity_style) .to_string(); - let mut opts = textwrap::Options::new(width) + let opts = textwrap::Options::new(width) .initial_indent(&initial_indent) .subsequent_indent(&rest_indent) - .break_words(self.break_words); - 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); - } + .break_words(self.break_words) + .word_separator(self.word_separator.unwrap_or(WordSeparator::AsciiSpace)) + .word_splitter( + self.word_splitter + .clone() + .unwrap_or(WordSplitter::NoHyphenation), + ); match error { ErrorKind::Diagnostic(diag) => { @@ -428,17 +430,16 @@ impl GraphicalReportHandler { if let Some(help) = diagnostic.help() { let width = self.termwidth.saturating_sub(2); let initial_indent = " help: ".style(self.theme.styles.help).to_string(); - let mut opts = textwrap::Options::new(width) + let opts = textwrap::Options::new(width) .initial_indent(&initial_indent) .subsequent_indent(" ") - .break_words(self.break_words); - 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); - } - + .break_words(self.break_words) + .word_separator(self.word_separator.unwrap_or(WordSeparator::AsciiSpace)) + .word_splitter( + self.word_splitter + .clone() + .unwrap_or(WordSplitter::NoHyphenation), + ); writeln!(f, "{}", self.wrap(&help.to_string(), opts))?; } Ok(()) @@ -489,16 +490,16 @@ impl GraphicalReportHandler { .style(severity_style) .to_string(); - let mut opts = textwrap::Options::new(width) + let opts = textwrap::Options::new(width) .initial_indent(&initial_indent) .subsequent_indent(&rest_indent) - .break_words(self.break_words); - 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); - } + .break_words(self.break_words) + .word_separator(self.word_separator.unwrap_or(WordSeparator::AsciiSpace)) + .word_splitter( + self.word_splitter + .clone() + .unwrap_or(WordSplitter::NoHyphenation), + ); let mut inner = String::new();