aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty/src')
-rw-r--r--alacritty/src/cli.rs31
1 files changed, 29 insertions, 2 deletions
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() {