mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor(shell): Use alternate to close links
This commit is contained in:
parent
6b27055c45
commit
af9f1346a2
@ -830,9 +830,7 @@ impl<'gctx> DrainState<'gctx> {
|
||||
"https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles",
|
||||
);
|
||||
let message = format!(
|
||||
"{}`{profile_name}` profile [{opt_type}]{} target(s) in {time_elapsed}",
|
||||
profile_link.open(),
|
||||
profile_link.close()
|
||||
"{profile_link}`{profile_name}` profile [{opt_type}]{profile_link:#} target(s) in {time_elapsed}",
|
||||
);
|
||||
if !build_runner.bcx.build_config.build_plan {
|
||||
// It doesn't really matter if this fails.
|
||||
|
@ -350,12 +350,7 @@ impl<'gctx> Timings<'gctx> {
|
||||
let mut shell = self.gctx.shell();
|
||||
let timing_path = std::env::current_dir().unwrap_or_default().join(&filename);
|
||||
let link = shell.err_file_hyperlink(&timing_path);
|
||||
let msg = format!(
|
||||
"report saved to {}{}{}",
|
||||
link.open(),
|
||||
timing_path.display(),
|
||||
link.close()
|
||||
);
|
||||
let msg = format!("report saved to {link}{}{link:#}", timing_path.display(),);
|
||||
shell.status_with_color("Timing", msg, &style::NOTE)?;
|
||||
|
||||
Ok(())
|
||||
|
@ -539,20 +539,15 @@ impl<D: fmt::Display> Default for Hyperlink<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: fmt::Display> Hyperlink<D> {
|
||||
pub fn open(&self) -> impl fmt::Display {
|
||||
if let Some(url) = self.url.as_ref() {
|
||||
format!("\x1B]8;;{url}\x1B\\")
|
||||
impl<D: fmt::Display> fmt::Display for Hyperlink<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let Some(url) = self.url.as_ref() else {
|
||||
return Ok(());
|
||||
};
|
||||
if f.alternate() {
|
||||
write!(f, "\x1B]8;;\x1B\\")
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(&self) -> impl fmt::Display {
|
||||
if self.url.is_some() {
|
||||
"\x1B]8;;\x1B\\"
|
||||
} else {
|
||||
""
|
||||
write!(f, "\x1B]8;;{url}\x1B\\")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
|
||||
};
|
||||
let mut shell = ws.gctx().shell();
|
||||
let link = shell.err_file_hyperlink(&path);
|
||||
shell.status(
|
||||
"Opening",
|
||||
format!("{}{}{}", link.open(), path.display(), link.close()),
|
||||
)?;
|
||||
shell.status("Opening", format!("{link}{}{link:#}", path.display()))?;
|
||||
open_docs(&path, &mut shell, config_browser, ws.gctx())?;
|
||||
}
|
||||
} else if ws.gctx().shell().verbosity() == Verbosity::Verbose {
|
||||
@ -85,10 +82,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
|
||||
if path.exists() {
|
||||
let mut shell = ws.gctx().shell();
|
||||
let link = shell.err_file_hyperlink(&path);
|
||||
shell.status(
|
||||
"Generated",
|
||||
format!("{}{}{}", link.open(), path.display(), link.close()),
|
||||
)?;
|
||||
shell.status("Generated", format!("{link}{}{link:#}", path.display()))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,12 +108,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
|
||||
let link = shell.err_file_hyperlink(&first_path);
|
||||
shell.status(
|
||||
"Generated",
|
||||
format!(
|
||||
"{}{}{}{remaining}",
|
||||
link.open(),
|
||||
first_path.display(),
|
||||
link.close()
|
||||
),
|
||||
format!("{link}{}{link:#}{remaining}", first_path.display(),),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user