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