This commit is contained in:
Rebecca Turner 2026-06-03 13:58:11 +09:00 committed by GitHub
commit 25e1c0d5ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 47 deletions

View File

@ -262,17 +262,7 @@ impl GraphicalReportHandler {
if let Some(footer) = &self.footer {
writeln!(f)?;
let width = self.termwidth.saturating_sub(2);
let mut 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);
}
let opts = self.textwrap_options(width);
writeln!(f, "{}", self.wrap(footer, opts))?;
}
Ok(())
@ -340,16 +330,10 @@ 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 = self
.textwrap_options(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);
}
.subsequent_indent(&rest_indent);
writeln!(f, "{}", self.wrap(&diagnostic.to_string(), opts))?;
@ -386,16 +370,10 @@ impl GraphicalReportHandler {
)
.style(severity_style)
.to_string();
let mut opts = textwrap::Options::new(width)
let opts = self
.textwrap_options(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);
}
.subsequent_indent(&rest_indent);
match error {
ErrorKind::Diagnostic(diag) => {
@ -428,16 +406,10 @@ 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 = self
.textwrap_options(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);
}
.subsequent_indent(" ");
writeln!(f, "{}", self.wrap(&help.to_string(), opts))?;
}
@ -489,16 +461,10 @@ impl GraphicalReportHandler {
.style(severity_style)
.to_string();
let mut opts = textwrap::Options::new(width)
let opts = self
.textwrap_options(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);
}
.subsequent_indent(&rest_indent);
let mut inner = String::new();
@ -1358,6 +1324,23 @@ impl GraphicalReportHandler {
}
Ok((context_data, lines))
}
fn textwrap_options(&self, width: usize) -> textwrap::Options<'static> {
textwrap::Options::new(width)
.initial_indent(" ")
.subsequent_indent(" ")
.word_separator(
self.word_separator
.clone()
.unwrap_or(textwrap::WordSeparator::AsciiSpace),
)
.word_splitter(
self.word_splitter
.clone()
.unwrap_or(textwrap::WordSplitter::NoHyphenation),
)
.break_words(self.break_words)
}
}
impl ReportHandler for GraphicalReportHandler {