aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-11-19 23:34:40 +0000
committerGitHub <noreply@github.com>2021-11-19 23:34:40 +0000
commitc89939b5d14e581e1aeaa940d81843192e0abc79 (patch)
tree8a78647fbb23b3fde68339ca2a2c9599315c7094 /alacritty/src
parentb0da035e9ecabfa13438386a6ce87072b7cc3c98 (diff)
downloadr-alacritty-c89939b5d14e581e1aeaa940d81843192e0abc79.tar.gz
r-alacritty-c89939b5d14e581e1aeaa940d81843192e0abc79.tar.bz2
r-alacritty-c89939b5d14e581e1aeaa940d81843192e0abc79.zip
Switch to clap-generated completions
The current completions required a lot of domain-specific knowledge about each individual shell and their completion functionality. Much of which is sparsely documented. While clap does not generate perfect completions, since parameters like `-e` are missing completions, it does a reasonable job while requiring no work on writing these completions. Since access to `cli.rs` isn't possible from the `build.rs`, these completions aren't always generated on build. Instead a test verifies that there has been no changes to these completions and provides a simple code sample for re-generating them. This should provide a simple solution with minimal overhead.
Diffstat (limited to 'alacritty/src')
-rw-r--r--alacritty/src/cli.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index ce0563ff..d939aff5 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -246,6 +246,13 @@ pub enum SocketMessage {
mod tests {
use super::*;
+ #[cfg(target_os = "linux")]
+ use std::fs::File;
+ #[cfg(target_os = "linux")]
+ use std::io::Read;
+
+ #[cfg(target_os = "linux")]
+ use clap::Shell;
use serde_yaml::mapping::Mapping;
#[test]
@@ -334,4 +341,32 @@ mod tests {
let class = parse_class("one,two,three");
assert!(class.is_err());
}
+
+ #[cfg(target_os = "linux")]
+ #[test]
+ fn completions() {
+ let mut clap = Options::clap();
+
+ for (shell, file) in &[
+ (Shell::Bash, "alacritty.bash"),
+ (Shell::Fish, "alacritty.fish"),
+ (Shell::Zsh, "_alacritty"),
+ ] {
+ let mut generated = Vec::new();
+ clap.gen_completions_to("alacritty", *shell, &mut generated);
+ let generated = String::from_utf8_lossy(&generated);
+
+ let mut completion = String::new();
+ let mut file = File::open(format!("../extra/completions/{}", file)).unwrap();
+ file.read_to_string(&mut completion).unwrap();
+
+ assert_eq!(generated, completion);
+ }
+
+ // NOTE: Use this to generate new completions.
+ //
+ // clap.gen_completions("alacritty", Shell::Bash, "../extra/completions/");
+ // clap.gen_completions("alacritty", Shell::Fish, "../extra/completions/");
+ // clap.gen_completions("alacritty", Shell::Zsh, "../extra/completions/");
+ }
}