Files
ghostty-rs/crates/ghostty-input/src/link.rs
T
ddidderr e03432241b feat(input): port keyboard, keybinding and mouse input handling
Ports ZIG/src/input (except macOS keymaps) into ghostty-input:
- key, key_mods (incl. RemapSet), the physical keycode table
- key_encode: legacy, modifyOtherKeys and kitty keyboard protocol
  encoders, function key tables
- Binding: all keybinding actions with their user-visible docs (for
  +list-actions), triggers, sets with sequences, chains, leader keys and
  key tables, and formatting back to config strings
- command palette defaults, mouse, paste safety checks, kitty helpers,
  links, helpgen action docs

Deviations (docs/rewrite/notes/ghostty-input.md): Mods.super is named
super_; case folding uses char::to_lowercase plus Ghostty's special
cases instead of uucode tables; chain parents are trigger paths instead
of pointers; a Zig bug where chained leaves inside sequences corrupted the
shared prefix when formatting is fixed (covered by a test).

Integration left: building encode/paste Options from terminal modes,
and implementing the EntryFormatter trait in ghostty-config.

Test Plan:
- cargo test -p ghostty-input (220 tests; 8 macOS-only skipped)
- cargo clippy -p ghostty-input --all-targets -- -D warnings
2026-10-11 21:56:07 +02:00

64 lines
2.1 KiB
Rust

//! A link is a clickable element that can be used to trigger some action.
//! A link is NOT just a URL that opens in a browser. A link is any generic
//! regular expression match over terminal text that can trigger various
//! action types. (ZIG/src/input/Link.zig)
use crate::key_mods::Mods;
/// The action that will be triggered when the link is clicked.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Action {
/// Open the full matched value using the default open program.
/// For example, on macOS this is "open" and on Linux this is "xdg-open".
Open,
/// Open the OSC8 hyperlink under the mouse position. _-prefixed means
/// this can't be user-specified, it's only used internally.
_OpenOsc8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Highlight {
/// Always highlight the link.
Always,
/// Only highlight the link when the mouse is hovering over it.
Hover,
/// Highlight anytime the given mods are pressed, either when
/// hovering or always. For always, all links will be highlighted
/// when the mods are pressed regardless of if the mouse is hovering
/// over them.
///
/// Note that if "shift" is specified here, this will NEVER match in
/// TUI programs that capture mouse events. "Shift" with mouse capture
/// escapes the mouse capture but strips the "shift" so it can't be
/// detected.
AlwaysMods(Mods),
HoverMods(Mods),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Link {
/// The regular expression that will be used to match the link.
pub regex: String,
/// The action that will be triggered when the link is clicked.
pub action: Action,
/// The situations in which the link will be highlighted. A link is only
/// clickable by the mouse when it is highlighted, so this also controls
/// when the link is clickable.
pub highlight: Highlight,
}
// TODO(integration): `oni_regex` (Zig `oniRegex`) builds an Oniguruma regex;
// the regex engine choice is made by the consumer crate (config/core).
impl Link {
/// Check if two links are equal.
pub fn equal(&self, other: &Link) -> bool {
self == other
}
}