aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/display/hint.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-04-03 23:52:44 +0000
committerGitHub <noreply@github.com>2021-04-03 23:52:44 +0000
commitcbcc12944006603131119b73c2ad72ebccf4562d (patch)
tree3f323703c8ce47d1bf89c2e13f2c129b3e750683 /alacritty/src/display/hint.rs
parent531e494cf9a90de91dbbb84cb6cfc3158b78f1f2 (diff)
downloadr-alacritty-cbcc12944006603131119b73c2ad72ebccf4562d.tar.gz
r-alacritty-cbcc12944006603131119b73c2ad72ebccf4562d.tar.bz2
r-alacritty-cbcc12944006603131119b73c2ad72ebccf4562d.zip
Add copy/paste/select hint actions
This adds some built-in actions for handling hint selections without having to spawn external applications. The new actions are `Copy`, `Select` and `Paste`.
Diffstat (limited to 'alacritty/src/display/hint.rs')
-rw-r--r--alacritty/src/display/hint.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs
index fe107139..2a5e9c65 100644
--- a/alacritty/src/display/hint.rs
+++ b/alacritty/src/display/hint.rs
@@ -1,7 +1,7 @@
+use alacritty_terminal::term::search::Match;
use alacritty_terminal::term::Term;
-use crate::config::ui_config::Hint;
-use crate::daemon::start_daemon;
+use crate::config::ui_config::{Hint, HintAction};
use crate::display::content::RegexMatches;
/// Percentage of characters in the hints alphabet used for the last character.
@@ -88,7 +88,7 @@ impl HintState {
}
/// Handle keyboard input during hint selection.
- pub fn keyboard_input<T>(&mut self, term: &Term<T>, c: char) {
+ pub fn keyboard_input<T>(&mut self, term: &Term<T>, c: char) -> Option<HintMatch> {
match c {
// Use backspace to remove the last character pressed.
'\x08' | '\x1f' => {
@@ -102,34 +102,25 @@ impl HintState {
// Update the visible matches.
self.update_matches(term);
- let hint = match self.hint.as_ref() {
- Some(hint) => hint,
- None => return,
- };
+ let hint = self.hint.as_ref()?;
// Find the last label starting with the input character.
let mut labels = self.labels.iter().enumerate().rev();
- let (index, label) = match labels.find(|(_, label)| !label.is_empty() && label[0] == c) {
- Some(last) => last,
- None => return,
- };
+ let (index, label) = labels.find(|(_, label)| !label.is_empty() && label[0] == c)?;
// Check if the selected label is fully matched.
if label.len() == 1 {
- // Get text for the hint's regex match.
- let hint_match = &self.matches[index];
- let text = term.bounds_to_string(*hint_match.start(), *hint_match.end());
-
- // Append text as last argument and launch command.
- let program = hint.command.program();
- let mut args = hint.command.args().to_vec();
- args.push(text);
- start_daemon(program, &args);
+ let bounds = self.matches[index].clone();
+ let action = hint.action.clone();
self.stop();
+
+ Some(HintMatch { action, bounds })
} else {
// Store character to preserve the selection.
self.keys.push(c);
+
+ None
}
}
@@ -152,6 +143,15 @@ impl HintState {
}
}
+/// Hint match which was selected by the user.
+pub struct HintMatch {
+ /// Action for handling the text.
+ pub action: HintAction,
+
+ /// Terminal range matching the hint.
+ pub bounds: Match,
+}
+
/// Generator for creating new hint labels.
struct HintLabels {
/// Full character set available.