aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSabu Siyad <git@ssiyad.com>2022-06-28 23:52:38 +0530
committerGitHub <noreply@github.com>2022-06-28 18:22:38 +0000
commit75b0005619f6e6d3e5e0ba775083b16cd46dac30 (patch)
treefa546f56ae65ca2c084de1dea35e98eda95faf1c
parent6018590d7be62d3a5317f228571d353004da0220 (diff)
downloadalacritty-75b0005619f6e6d3e5e0ba775083b16cd46dac30.tar.gz
alacritty-75b0005619f6e6d3e5e0ba775083b16cd46dac30.zip
Add hexadecimal support to --embed
Closes #6145.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/src/cli.rs31
-rw-r--r--extra/alacritty.man2
-rw-r--r--extra/completions/_alacritty2
-rw-r--r--extra/completions/alacritty.fish2
5 files changed, 33 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 507f3ccc..8591416e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Escape sequence to set underline color (`CSI 58 : 2 : Ps : Ps : Ps m`/`CSI 58 : 5 : Ps m`)
- Escape sequence to reset underline color (`CSI 59 m`)
- Vi mode keybinding (z) to center view around vi mode cursor
+- Accept hexadecimal values starting with `0x` for `--embed`
### Changed
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index be377700..8872ec99 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -1,4 +1,5 @@
use std::cmp::max;
+use std::os::raw::c_ulong;
use std::path::PathBuf;
#[cfg(unix)]
@@ -25,7 +26,7 @@ pub struct Options {
#[clap(long)]
pub ref_test: bool,
- /// Defines the X11 window ID (as a decimal integer) to embed Alacritty within.
+ /// X11 window ID to embed Alacritty within (decimal or hexadecimal with "0x" prefix).
#[clap(long)]
pub embed: Option<String>,
@@ -100,7 +101,7 @@ impl Options {
}
config.window.dynamic_title &= self.window_options.window_identity.title.is_none();
- config.window.embed = self.embed.as_ref().and_then(|embed| embed.parse().ok());
+ config.window.embed = self.embed.as_ref().and_then(|embed| parse_hex_or_decimal(embed));
config.debug.print_events |= self.print_events;
config.debug.log_level = max(config.debug.log_level, self.log_level());
config.debug.ref_test |= self.ref_test;
@@ -173,6 +174,14 @@ fn parse_class(input: &str) -> Result<Class, String> {
}
}
+/// Convert to hex if possible, else decimal
+fn parse_hex_or_decimal(input: &str) -> Option<c_ulong> {
+ input
+ .strip_prefix("0x")
+ .and_then(|value| c_ulong::from_str_radix(value, 16).ok())
+ .or_else(|| input.parse().ok())
+}
+
/// Terminal specific cli options which can be passed to new windows via IPC.
#[derive(Serialize, Deserialize, Args, Default, Debug, Clone, PartialEq, Eq)]
pub struct TerminalOptions {
@@ -393,6 +402,24 @@ mod tests {
assert!(class.is_err());
}
+ #[test]
+ fn valid_decimal() {
+ let value = parse_hex_or_decimal("10485773");
+ assert_eq!(value, Some(10485773));
+ }
+
+ #[test]
+ fn valid_hex_to_decimal() {
+ let value = parse_hex_or_decimal("0xa0000d");
+ assert_eq!(value, Some(10485773));
+ }
+
+ #[test]
+ fn invalid_hex_to_decimal() {
+ let value = parse_hex_or_decimal("0xa0xx0d");
+ assert_eq!(value, None);
+ }
+
#[cfg(target_os = "linux")]
#[test]
fn completions() {
diff --git a/extra/alacritty.man b/extra/alacritty.man
index 1ac63f04..eec20d60 100644
--- a/extra/alacritty.man
+++ b/extra/alacritty.man
@@ -52,7 +52,7 @@ Alacritty looks for the configuration file at the following paths:
On Windows, the configuration file is located at %APPDATA%\\alacritty\\alacritty.yml.
.TP
\fB\-\-embed\fR <parent>
-Defines the X11 window ID (as a decimal integer) to embed Alacritty within
+X11 window ID to embed Alacritty within (decimal or hexadecimal with "0x" prefix)
.TP
\fB\-o\fR, \fB\-\-option\fR <option>...
Override configuration file options [example: cursor.style=Beam]
diff --git a/extra/completions/_alacritty b/extra/completions/_alacritty
index 86226236..50a5c00d 100644
--- a/extra/completions/_alacritty
+++ b/extra/completions/_alacritty
@@ -15,7 +15,7 @@ _alacritty() {
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
-'--embed=[Defines the X11 window ID (as a decimal integer) to embed Alacritty within]:EMBED: ' \
+'--embed=[X11 window ID to embed Alacritty within (decimal or hexadecimal with "0x" prefix)]:EMBED: ' \
'--config-file=[Specify alternative configuration file \[default: $XDG_CONFIG_HOME/alacritty/alacritty.yml\]]:CONFIG_FILE:_files' \
'--socket=[Path for IPC socket creation]:SOCKET:_files' \
'*-o+[Override configuration file options \[example: cursor.style=Beam\]]:OPTION: ' \
diff --git a/extra/completions/alacritty.fish b/extra/completions/alacritty.fish
index f425448b..69b3d777 100644
--- a/extra/completions/alacritty.fish
+++ b/extra/completions/alacritty.fish
@@ -1,4 +1,4 @@
-complete -c alacritty -n "__fish_use_subcommand" -l embed -d 'Defines the X11 window ID (as a decimal integer) to embed Alacritty within' -r
+complete -c alacritty -n "__fish_use_subcommand" -l embed -d 'X11 window ID to embed Alacritty within (decimal or hexadecimal with "0x" prefix)' -r
complete -c alacritty -n "__fish_use_subcommand" -l config-file -d 'Specify alternative configuration file [default: $XDG_CONFIG_HOME/alacritty/alacritty.yml]' -r -F
complete -c alacritty -n "__fish_use_subcommand" -l socket -d 'Path for IPC socket creation' -r -F
complete -c alacritty -n "__fish_use_subcommand" -s o -l option -d 'Override configuration file options [example: cursor.style=Beam]' -r