diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2022-07-10 20:11:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-10 20:11:28 +0300 |
commit | 694a52bcffeffdc9e163818c3b2ac5c39e26f1ef (patch) | |
tree | a774babc1869b4c700d7df1478dbbfe5b2c3bcda /alacritty_terminal/src/ansi.rs | |
parent | 8451b75689b44f11ec1707af7e26d915772c3972 (diff) | |
download | alacritty-694a52bcffeffdc9e163818c3b2ac5c39e26f1ef.tar.gz alacritty-694a52bcffeffdc9e163818c3b2ac5c39e26f1ef.zip |
Add support for hyperlink escape sequence
This commit adds support for hyperlink escape sequence
`OSC 8 ; params ; URI ST`. The configuration option responsible for
those is `hints.enabled.hyperlinks`.
Fixes #922.
Diffstat (limited to 'alacritty_terminal/src/ansi.rs')
-rw-r--r-- | alacritty_terminal/src/ansi.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/alacritty_terminal/src/ansi.rs b/alacritty_terminal/src/ansi.rs index 393f6a8c..e30ed0f5 100644 --- a/alacritty_terminal/src/ansi.rs +++ b/alacritty_terminal/src/ansi.rs @@ -12,6 +12,7 @@ use vte::{Params, ParamsIter}; use alacritty_config_derive::ConfigDeserialize; use crate::index::{Column, Line}; +use crate::term::cell::Hyperlink; use crate::term::color::Rgb; /// Maximum time before a synchronized update is aborted. @@ -457,6 +458,9 @@ pub trait Handler { /// Report text area size in characters. fn text_area_size_chars(&mut self) {} + + /// Set hyperlink. + fn set_hyperlink(&mut self, _: Option<Hyperlink>) {} } /// Terminal cursor configuration. @@ -1007,6 +1011,27 @@ where } }, + // Hyperlink. + b"8" if params.len() > 2 => { + let link_params = params[1]; + let uri = str::from_utf8(params[2]).unwrap_or_default(); + + // The OSC 8 escape sequence must be stopped when getting an empty `uri`. + if uri.is_empty() { + self.handler.set_hyperlink(None); + return; + } + + // Link parameters are in format of `key1=value1:key2=value2`. Currently only key + // `id` is defined. + let id = link_params + .split(|&b| b == b':') + .find_map(|kv| kv.strip_prefix(b"id=")) + .and_then(|kv| str::from_utf8(kv).ok()); + + self.handler.set_hyperlink(Some(Hyperlink::new(id, uri))); + }, + // Get/set Foreground, Background, Cursor colors. b"10" | b"11" | b"12" => { if params.len() >= 2 { |