Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa
Introduce `-Zterminal-urls` to use OSC8 for error codes Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `<a href="URL">` does in HTML. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
This commit is contained in:
commit
780beae7bd
16 changed files with 99 additions and 9 deletions
|
@ -4,7 +4,7 @@ use crate::early_error;
|
|||
use crate::lint;
|
||||
use crate::search_paths::SearchPath;
|
||||
use crate::utils::NativeLib;
|
||||
use rustc_errors::LanguageIdentifier;
|
||||
use rustc_errors::{LanguageIdentifier, TerminalUrl};
|
||||
use rustc_target::spec::{CodeModel, LinkerFlavorCli, MergeFunctions, PanicStrategy, SanitizerSet};
|
||||
use rustc_target::spec::{
|
||||
RelocModel, RelroLevel, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
|
||||
|
@ -402,6 +402,8 @@ mod desc {
|
|||
pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
|
||||
pub const parse_tls_model: &str = "one of supported TLS models (`rustc --print tls-models`)";
|
||||
pub const parse_target_feature: &str = parse_string;
|
||||
pub const parse_terminal_url: &str =
|
||||
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto`";
|
||||
pub const parse_wasi_exec_model: &str = "either `command` or `reactor`";
|
||||
pub const parse_split_debuginfo: &str =
|
||||
"one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
|
||||
|
@ -1044,6 +1046,16 @@ mod parse {
|
|||
true
|
||||
}
|
||||
|
||||
pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool {
|
||||
*slot = match v {
|
||||
Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes,
|
||||
Some("off" | "no" | "n") => TerminalUrl::No,
|
||||
Some("auto") => TerminalUrl::Auto,
|
||||
_ => return false,
|
||||
};
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn parse_symbol_mangling_version(
|
||||
slot: &mut Option<SymbolManglingVersion>,
|
||||
v: Option<&str>,
|
||||
|
@ -1675,6 +1687,8 @@ options! {
|
|||
"show extended diagnostic help (default: no)"),
|
||||
temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
|
||||
"the directory the intermediate files are written to"),
|
||||
terminal_urls: TerminalUrl = (TerminalUrl::No, parse_terminal_url, [UNTRACKED],
|
||||
"use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output"),
|
||||
#[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
|
||||
thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||
"enable ThinLTO when possible"),
|
||||
|
|
|
@ -24,6 +24,7 @@ use rustc_errors::registry::Registry;
|
|||
use rustc_errors::{
|
||||
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
||||
ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan, Noted,
|
||||
TerminalUrl,
|
||||
};
|
||||
use rustc_macros::HashStable_Generic;
|
||||
pub use rustc_span::def_id::StableCrateId;
|
||||
|
@ -1273,6 +1274,19 @@ fn default_emitter(
|
|||
) -> Box<dyn Emitter + sync::Send> {
|
||||
let macro_backtrace = sopts.unstable_opts.macro_backtrace;
|
||||
let track_diagnostics = sopts.unstable_opts.track_diagnostics;
|
||||
let terminal_url = match sopts.unstable_opts.terminal_urls {
|
||||
TerminalUrl::Auto => {
|
||||
match (std::env::var("COLORTERM").as_deref(), std::env::var("TERM").as_deref()) {
|
||||
(Ok("truecolor"), Ok("xterm-256color"))
|
||||
if sopts.unstable_features.is_nightly_build() =>
|
||||
{
|
||||
TerminalUrl::Yes
|
||||
}
|
||||
_ => TerminalUrl::No,
|
||||
}
|
||||
}
|
||||
t => t,
|
||||
};
|
||||
match sopts.error_format {
|
||||
config::ErrorOutputType::HumanReadable(kind) => {
|
||||
let (short, color_config) = kind.unzip();
|
||||
|
@ -1297,6 +1311,7 @@ fn default_emitter(
|
|||
sopts.diagnostic_width,
|
||||
macro_backtrace,
|
||||
track_diagnostics,
|
||||
terminal_url,
|
||||
);
|
||||
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
|
||||
}
|
||||
|
@ -1312,6 +1327,7 @@ fn default_emitter(
|
|||
sopts.diagnostic_width,
|
||||
macro_backtrace,
|
||||
track_diagnostics,
|
||||
terminal_url,
|
||||
)
|
||||
.ui_testing(sopts.unstable_opts.ui_testing),
|
||||
),
|
||||
|
@ -1628,6 +1644,7 @@ fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler
|
|||
None,
|
||||
false,
|
||||
false,
|
||||
TerminalUrl::No,
|
||||
))
|
||||
}
|
||||
config::ErrorOutputType::Json { pretty, json_rendered } => Box::new(JsonEmitter::basic(
|
||||
|
@ -1638,6 +1655,7 @@ fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler
|
|||
None,
|
||||
false,
|
||||
false,
|
||||
TerminalUrl::No,
|
||||
)),
|
||||
};
|
||||
rustc_errors::Handler::with_emitter(true, None, emitter)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue