diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2020-06-05 01:10:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 01:10:31 +0300 |
commit | f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5 (patch) | |
tree | a61843b8ffe5fc25cc3a35157bc1a4346f37d40b /alacritty/src | |
parent | 1e32e5a5154a2e765ca0b3ab8e50e4c01bbe5d18 (diff) | |
download | r-alacritty-f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5.tar.gz r-alacritty-f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5.tar.bz2 r-alacritty-f99220f01553c6c9d36e1f4ce01c007f4d4d4cb5.zip |
Refactor Shell, Command, and Launcher to share impl
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/cli.rs | 8 | ||||
-rw-r--r-- | alacritty/src/config/bindings.rs | 41 | ||||
-rw-r--r-- | alacritty/src/config/mouse.rs | 18 | ||||
-rw-r--r-- | alacritty/src/input.rs | 4 |
4 files changed, 20 insertions, 51 deletions
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index 5f6b7804..f7c591e6 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -18,7 +18,7 @@ use std::path::PathBuf; use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; use log::{self, error, LevelFilter}; -use alacritty_terminal::config::{Delta, Dimensions, Shell, DEFAULT_NAME}; +use alacritty_terminal::config::{Delta, Dimensions, Program, DEFAULT_NAME}; use alacritty_terminal::index::{Column, Line}; use crate::config::Config; @@ -41,7 +41,7 @@ pub struct Options { pub class: Option<String>, pub embed: Option<String>, pub log_level: LevelFilter, - pub command: Option<Shell<'static>>, + pub command: Option<Program>, pub hold: bool, pub working_dir: Option<PathBuf>, pub config: Option<PathBuf>, @@ -243,9 +243,9 @@ impl Options { // The following unwrap is guaranteed to succeed. // If `command` exists it must also have a first item since // `Arg::min_values(1)` is set. - let command = String::from(args.next().unwrap()); + let program = String::from(args.next().unwrap()); let args = args.map(String::from).collect(); - options.command = Some(Shell::new_with_args(command, args)); + options.command = Some(Program::WithArgs { program, args }); } if matches.is_present("hold") { diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 41a0b1db..c74a0c2c 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -22,6 +22,7 @@ use serde::de::{self, MapAccess, Unexpected, Visitor}; use serde::{Deserialize, Deserializer}; use serde_yaml::Value as SerdeValue; +use alacritty_terminal::config::Program; use alacritty_terminal::term::TermMode; use alacritty_terminal::vi_mode::ViMotion; @@ -94,7 +95,7 @@ pub enum Action { /// Run given command. #[serde(skip)] - Command(String, Vec<String>), + Command(Program), /// Move vi mode cursor. #[serde(skip)] @@ -763,7 +764,7 @@ impl<'a> Deserialize<'a> for RawBinding { let mut mode: Option<TermMode> = None; let mut not_mode: Option<TermMode> = None; let mut mouse: Option<MouseButton> = None; - let mut command: Option<CommandWrapper> = None; + let mut command: Option<Program> = None; use de::Error; @@ -860,7 +861,7 @@ impl<'a> Deserialize<'a> for RawBinding { return Err(<V::Error as Error>::duplicate_field("command")); } - command = Some(map.next_value::<CommandWrapper>()?); + command = Some(map.next_value::<Program>()?); }, } } @@ -882,12 +883,7 @@ impl<'a> Deserialize<'a> for RawBinding { }, (Some(action), None, None) => action, (None, Some(chars), None) => Action::Esc(chars), - (None, None, Some(cmd)) => match cmd { - CommandWrapper::Just(program) => Action::Command(program, vec![]), - CommandWrapper::WithArgs { program, args } => { - Action::Command(program, args) - }, - }, + (None, None, Some(cmd)) => Action::Command(cmd), _ => { return Err(V::Error::custom( "must specify exactly one of chars, action or command", @@ -929,33 +925,6 @@ impl<'a> Deserialize<'a> for KeyBinding { } } -#[serde(untagged)] -#[derive(Debug, Deserialize, Clone, PartialEq, Eq)] -pub enum CommandWrapper { - Just(String), - WithArgs { - program: String, - #[serde(default)] - args: Vec<String>, - }, -} - -impl CommandWrapper { - pub fn program(&self) -> &str { - match self { - CommandWrapper::Just(program) => program, - CommandWrapper::WithArgs { program, .. } => program, - } - } - - pub fn args(&self) -> &[String] { - match self { - CommandWrapper::Just(_) => &[], - CommandWrapper::WithArgs { args, .. } => args, - } - } -} - /// Newtype for implementing deserialize on glutin Mods. /// /// Our deserialize impl wouldn't be covered by a derive(Deserialize); see the diff --git a/alacritty/src/config/mouse.rs b/alacritty/src/config/mouse.rs index 9192aba9..1a5aec3d 100644 --- a/alacritty/src/config/mouse.rs +++ b/alacritty/src/config/mouse.rs @@ -4,9 +4,9 @@ use glutin::event::ModifiersState; use log::error; use serde::{Deserialize, Deserializer}; -use alacritty_terminal::config::{failure_default, LOG_TARGET_CONFIG}; +use alacritty_terminal::config::{failure_default, Program, LOG_TARGET_CONFIG}; -use crate::config::bindings::{CommandWrapper, ModsWrapper}; +use crate::config::bindings::ModsWrapper; #[serde(default)] #[derive(Default, Clone, Debug, Deserialize, PartialEq, Eq)] @@ -26,7 +26,7 @@ pub struct Mouse { pub struct Url { /// Program for opening links. #[serde(deserialize_with = "deserialize_launcher")] - pub launcher: Option<CommandWrapper>, + pub launcher: Option<Program>, /// Modifier used to open links. #[serde(deserialize_with = "failure_default")] @@ -39,9 +39,7 @@ impl Url { } } -fn deserialize_launcher<'a, D>( - deserializer: D, -) -> ::std::result::Result<Option<CommandWrapper>, D::Error> +fn deserialize_launcher<'a, D>(deserializer: D) -> std::result::Result<Option<Program>, D::Error> where D: Deserializer<'a>, { @@ -55,7 +53,7 @@ where return Ok(None); } - match <Option<CommandWrapper>>::deserialize(val) { + match <Option<Program>>::deserialize(val) { Ok(launcher) => Ok(launcher), Err(err) => { error!( @@ -73,11 +71,11 @@ impl Default for Url { fn default() -> Url { Url { #[cfg(not(any(target_os = "macos", windows)))] - launcher: Some(CommandWrapper::Just(String::from("xdg-open"))), + launcher: Some(Program::Just(String::from("xdg-open"))), #[cfg(target_os = "macos")] - launcher: Some(CommandWrapper::Just(String::from("open"))), + launcher: Some(Program::Just(String::from("open"))), #[cfg(windows)] - launcher: Some(CommandWrapper::Just(String::from("explorer"))), + launcher: Some(Program::Just(String::from("explorer"))), modifiers: Default::default(), } } diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 01c43ecc..652f4d19 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -147,7 +147,9 @@ impl<T: EventListener> Execute<T> for Action { let text = ctx.terminal_mut().clipboard().load(ClipboardType::Selection); paste(ctx, &text); }, - Action::Command(ref program, ref args) => { + Action::Command(ref program) => { + let args = program.args(); + let program = program.program(); trace!("Running command {} with args {:?}", program, args); match start_daemon(program, args) { |