mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-23 21:54:45 +02:00
printer: deduplicate hyperlink alias names
This exports a new `HyperlinkAlias` type in the `grep-printer` crate. This includes a "display priority" with each alias and a function for getting all supported aliases from the crate. This should hopefully make it possible for downstream users of this crate to include a list of supported aliases in the documentation. Closes #3103
This commit is contained in:
committed by
Andrew Gallant
parent
fdfda9ae73
commit
66aa4a63bb
@@ -17,7 +17,7 @@ ripgrep. For example, `-E`, `--encoding` and `--no-encoding` all manipulate the
|
||||
same encoding state in ripgrep.
|
||||
*/
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, sync::LazyLock};
|
||||
|
||||
use {anyhow::Context as AnyhowContext, bstr::ByteVec};
|
||||
|
||||
@@ -2897,7 +2897,10 @@ impl Flag for HyperlinkFormat {
|
||||
r"Set the format of hyperlinks."
|
||||
}
|
||||
fn doc_long(&self) -> &'static str {
|
||||
r#"
|
||||
static DOC: LazyLock<String> = LazyLock::new(|| {
|
||||
let mut doc = String::new();
|
||||
doc.push_str(
|
||||
r#"
|
||||
Set the format of hyperlinks to use when printing results. Hyperlinks make
|
||||
certain elements of ripgrep's output, such as file paths, clickable. This
|
||||
generally only works in terminal emulators that support OSC-8 hyperlinks. For
|
||||
@@ -2905,10 +2908,23 @@ example, the format \fBfile://{host}{path}\fP will emit an RFC 8089 hyperlink.
|
||||
To see the format that ripgrep is using, pass the \flag{debug} flag.
|
||||
.sp
|
||||
Alternatively, a format string may correspond to one of the following aliases:
|
||||
\fBdefault\fP, \fBnone\fP, \fBfile\fP, \fBgrep+\fP, \fBkitty\fP, \fBmacvim\fP,
|
||||
\fBtextmate\fP, \fBvscode\fP, \fBvscode-insiders\fP, \fBvscodium\fP. The
|
||||
alias will be replaced with a format string that is intended to work for the
|
||||
corresponding application.
|
||||
"#,
|
||||
);
|
||||
|
||||
let mut aliases = grep::printer::hyperlink_aliases();
|
||||
aliases.sort_by_key(|alias| {
|
||||
alias.display_priority().unwrap_or(i16::MAX)
|
||||
});
|
||||
for (i, alias) in aliases.iter().enumerate() {
|
||||
doc.push_str(r"\fB");
|
||||
doc.push_str(alias.name());
|
||||
doc.push_str(r"\fP");
|
||||
doc.push_str(if i < aliases.len() - 1 { ", " } else { "." });
|
||||
}
|
||||
doc.push_str(
|
||||
r#"
|
||||
The alias will be replaced with a format string that is intended to work for
|
||||
the corresponding application.
|
||||
.sp
|
||||
The following variables are available in the format string:
|
||||
.sp
|
||||
@@ -2985,7 +3001,11 @@ in the output. To make the path appear, and thus also a hyperlink, use the
|
||||
.sp
|
||||
For more information on hyperlinks in terminal emulators, see:
|
||||
https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
||||
"#
|
||||
"#,
|
||||
);
|
||||
doc
|
||||
});
|
||||
&DOC
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user