chore: Remove unneeded ansi escape resets from output
This commit is contained in:
@@ -3408,7 +3408,6 @@ pub(crate) fn emit_to_destination(
|
||||
short_message: bool,
|
||||
) -> io::Result<()> {
|
||||
use crate::lock;
|
||||
const RESET: anstyle::Reset = anstyle::Reset;
|
||||
|
||||
// In order to prevent error message interleaving, where multiple error lines get intermixed
|
||||
// when multiple compiler processes error simultaneously, we emit errors with additional
|
||||
@@ -3426,7 +3425,7 @@ pub(crate) fn emit_to_destination(
|
||||
for (pos, line) in rendered_buffer.iter().enumerate() {
|
||||
for part in line {
|
||||
let style = part.style.anstyle(*lvl);
|
||||
write!(dst, "{RESET}{style}{}{RESET}", part.text)?;
|
||||
write!(dst, "{style}{}{style:#}", part.text)?;
|
||||
}
|
||||
if !short_message && (!lvl.is_failure_note() || pos != rendered_buffer.len() - 1) {
|
||||
writeln!(dst)?;
|
||||
|
||||
@@ -6,7 +6,6 @@ use anstyle::{AnsiColor, Effects, Style};
|
||||
use crate::markdown::{MdStream, MdTree};
|
||||
|
||||
const DEFAULT_COLUMN_WIDTH: usize = 140;
|
||||
const RESET: anstyle::Reset = anstyle::Reset;
|
||||
|
||||
thread_local! {
|
||||
/// Track the position of viewable characters in our buffer
|
||||
@@ -31,53 +30,52 @@ fn write_stream(
|
||||
default: Option<Style>,
|
||||
indent: usize,
|
||||
) -> io::Result<()> {
|
||||
match default {
|
||||
Some(c) => write!(buf, "{c:#}{c}")?,
|
||||
None => write!(buf, "{RESET}")?,
|
||||
}
|
||||
|
||||
for tt in stream {
|
||||
write_tt(tt, buf, default, indent)?;
|
||||
if let Some(c) = default {
|
||||
write!(buf, "{c:#}{c}")?;
|
||||
}
|
||||
}
|
||||
reset_opt_style(buf, default)?;
|
||||
|
||||
write!(buf, "{RESET}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_tt(
|
||||
tt: &MdTree<'_>,
|
||||
buf: &mut Vec<u8>,
|
||||
_default: Option<Style>,
|
||||
default: Option<Style>,
|
||||
indent: usize,
|
||||
) -> io::Result<()> {
|
||||
match tt {
|
||||
MdTree::CodeBlock { txt, lang: _ } => {
|
||||
write!(buf, "{RESET}")?;
|
||||
reset_opt_style(buf, default)?;
|
||||
let style = Style::new().effects(Effects::DIMMED);
|
||||
write!(buf, "{style}{txt}")?;
|
||||
write!(buf, "{style}{txt}{style:#}")?;
|
||||
render_opt_style(buf, default)?;
|
||||
}
|
||||
MdTree::CodeInline(txt) => {
|
||||
write!(buf, "{RESET}")?;
|
||||
let style = Style::new().effects(Effects::DIMMED);
|
||||
write_wrapping(buf, txt, indent, None, Some(style))?;
|
||||
reset_opt_style(buf, default)?;
|
||||
write_wrapping(buf, txt, indent, None, Some(Style::new().effects(Effects::DIMMED)))?;
|
||||
render_opt_style(buf, default)?;
|
||||
}
|
||||
MdTree::Strong(txt) => {
|
||||
write!(buf, "{RESET}")?;
|
||||
let style = Style::new().effects(Effects::BOLD);
|
||||
write_wrapping(buf, txt, indent, None, Some(style))?;
|
||||
reset_opt_style(buf, default)?;
|
||||
write_wrapping(buf, txt, indent, None, Some(Style::new().effects(Effects::BOLD)))?;
|
||||
render_opt_style(buf, default)?;
|
||||
}
|
||||
MdTree::Emphasis(txt) => {
|
||||
write!(buf, "{RESET}")?;
|
||||
let style = Style::new().effects(Effects::ITALIC);
|
||||
write_wrapping(buf, txt, indent, None, Some(style))?;
|
||||
reset_opt_style(buf, default)?;
|
||||
write_wrapping(buf, txt, indent, None, Some(Style::new().effects(Effects::ITALIC)))?;
|
||||
render_opt_style(buf, default)?;
|
||||
}
|
||||
MdTree::Strikethrough(txt) => {
|
||||
write!(buf, "{RESET}")?;
|
||||
let style = Style::new().effects(Effects::STRIKETHROUGH);
|
||||
write_wrapping(buf, txt, indent, None, Some(style))?;
|
||||
reset_opt_style(buf, default)?;
|
||||
write_wrapping(
|
||||
buf,
|
||||
txt,
|
||||
indent,
|
||||
None,
|
||||
Some(Style::new().effects(Effects::STRIKETHROUGH)),
|
||||
)?;
|
||||
render_opt_style(buf, default)?;
|
||||
}
|
||||
MdTree::PlainText(txt) => {
|
||||
write_wrapping(buf, txt, indent, None, None)?;
|
||||
@@ -105,7 +103,11 @@ fn write_tt(
|
||||
4.. => AnsiColor::Cyan.on_default().effects(Effects::UNDERLINE | Effects::ITALIC),
|
||||
0 => unreachable!(),
|
||||
};
|
||||
reset_opt_style(buf, default)?;
|
||||
write!(buf, "{cs}")?;
|
||||
write_stream(stream, buf, Some(cs), 0)?;
|
||||
write!(buf, "{cs:#}")?;
|
||||
render_opt_style(buf, default)?;
|
||||
buf.write_all(b"\n")?;
|
||||
}
|
||||
MdTree::OrderedListItem(n, stream) => {
|
||||
@@ -122,8 +124,20 @@ fn write_tt(
|
||||
MdTree::Comment(_) | MdTree::LinkDef { .. } | MdTree::RefLink { .. } => unreachable!(),
|
||||
}
|
||||
|
||||
write!(buf, "{RESET}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_opt_style(buf: &mut Vec<u8>, style: Option<Style>) -> io::Result<()> {
|
||||
if let Some(style) = &style {
|
||||
write!(buf, "{style}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reset_opt_style(buf: &mut Vec<u8>, style: Option<Style>) -> io::Result<()> {
|
||||
if let Some(style) = &style {
|
||||
write!(buf, "{style:#}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -141,9 +155,8 @@ fn write_wrapping(
|
||||
link_url: Option<&str>,
|
||||
style: Option<Style>,
|
||||
) -> io::Result<()> {
|
||||
if let Some(style) = &style {
|
||||
write!(buf, "{style}")?;
|
||||
}
|
||||
render_opt_style(buf, style)?;
|
||||
|
||||
let ind_ws = &b" "[..indent];
|
||||
let mut to_write = text;
|
||||
if let Some(url) = link_url {
|
||||
@@ -191,6 +204,7 @@ fn write_wrapping(
|
||||
if link_url.is_some() {
|
||||
buf.write_all(b"\x1b]8;;\x1b\\")?;
|
||||
}
|
||||
reset_opt_style(buf, style)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
[0m[0m[1m[4m[96mH1 Heading [0m[0m[1m[4m[96m]8;;http://docs.rs\with a link]8;;\[0m[0m[1m[4m[96m[0m
|
||||
[0mH1 content: [0m[0m[1msome words in bold[0m and [0m[0m[2mso does inline code[0m
|
||||
[1m[4m[96mH1 Heading ]8;;http://docs.rs\with a link]8;;\[0m[0m
|
||||
H1 content: [1msome words in bold[0m and [2mso does inline code[0m
|
||||
|
||||
[0m[0m[4m[96mH2 Heading[0m[0m[4m[96m[0m
|
||||
[0mH2 content: [0m[0m[3msome words in italic[0m
|
||||
[4m[96mH2 Heading[0m[0m
|
||||
H2 content: [3msome words in italic[0m
|
||||
|
||||
[0m[0m[3m[96mH3 Heading[0m[0m[3m[96m[0m
|
||||
[0mH3 content: [0m[0m[9mstrikethrough[0m text[0m
|
||||
[3m[96mH3 Heading[0m[0m
|
||||
H3 content: [9mstrikethrough[0m text
|
||||
|
||||
[0m[0m[3m[4m[36mH4 Heading[0m[0m[3m[4m[36m[0m
|
||||
[0mH4 content: A [0m]8;;https://docs.rs\simple link]8;;\[0m and a [0m]8;;http://docs.rs\remote-link]8;;\[0m.[0m
|
||||
[0m--------------------------------------------------------------------------------------------------------------------------------------------[0m
|
||||
[0mA section break was above. We can also do paragraph breaks:[0m
|
||||
[3m[4m[36mH4 Heading[0m[0m
|
||||
H4 content: A ]8;;https://docs.rs\simple link]8;;\ and a ]8;;http://docs.rs\remote-link]8;;\.
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
A section break was above. We can also do paragraph breaks:
|
||||
|
||||
[0m(new paragraph) and unordered lists:[0m
|
||||
(new paragraph) and unordered lists:
|
||||
|
||||
[0m* [0mItem 1 in [0m[0m[2mcode[0m[0m[0m
|
||||
[0m* [0mItem 2 in [0m[0m[3mitalics[0m[0m[0m
|
||||
* Item 1 in [2mcode[0m
|
||||
* Item 2 in [3mitalics[0m
|
||||
|
||||
[0mOr ordered:[0m
|
||||
Or ordered:
|
||||
|
||||
[0m1. [0mItem 1 in [0m[0m[1mbold[0m[0m[0m
|
||||
[0m2. [0mItem 2 with some long lines that should wrap: Lorem ipsum dolor sit amet,[0m consectetur adipiscing elit. Aenean ac mattis nunc. Phasellus
|
||||
elit quam,[0m pulvinar ac risus in, dictum vehicula turpis. Vestibulum neque est, accumsan[0m in cursus sit amet, dictum a nunc. Suspendisse
|
||||
aliquet, lorem eu eleifend[0m accumsan, magna neque sodales nisi, a aliquet lectus leo eu sem.[0m[0m[0m
|
||||
[0m--------------------------------------------------------------------------------------------------------------------------------------------[0m
|
||||
[0m[0m[4m[96mCode[0m[0m[4m[96m[0m
|
||||
[0mBoth [0m[0m[2minline code[0m and code blocks are supported:[0m
|
||||
1. Item 1 in [1mbold[0m
|
||||
2. Item 2 with some long lines that should wrap: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac mattis nunc. Phasellus
|
||||
elit quam, pulvinar ac risus in, dictum vehicula turpis. Vestibulum neque est, accumsan in cursus sit amet, dictum a nunc. Suspendisse
|
||||
aliquet, lorem eu eleifend accumsan, magna neque sodales nisi, a aliquet lectus leo eu sem.
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
[4m[96mCode[0m[0m
|
||||
Both [2minline code[0m and code blocks are supported:
|
||||
|
||||
[0m[0m[2m/// A rust enum
|
||||
[2m/// A rust enum
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
enum Foo {
|
||||
/// Start of line
|
||||
Bar
|
||||
}[0m[0m
|
||||
}[0m
|
||||
|
||||
Reference in New Issue
Block a user