diff --git a/docs/changelog.markdown b/docs/changelog.markdown index 01975e71d..f84727c3a 100644 --- a/docs/changelog.markdown +++ b/docs/changelog.markdown @@ -12,6 +12,10 @@ brief notes about them may accumulate here. * Windows: Fixed AltGr handling for European layouts * Removed old TOML config file parsing code +* Removed old `arg="something"` key binding parameter. This was a remnant from + the TOML based configuration. You're unlikely to notice this unless you + followed an example from the docs; migrate instead to using eg: + `action=wezterm.action{ActivateTab=i-1}` to pass the integer argument. ### 20200517-122836-92c201c6 diff --git a/docs/config/keys.markdown b/docs/config/keys.markdown index d952fc860..0020a9718 100644 --- a/docs/config/keys.markdown +++ b/docs/config/keys.markdown @@ -154,14 +154,12 @@ for i = 1, 8 do table.insert(mykeys, { key=tostring(i), mods="CTRL|ALT", - action="ActivateTab", - arg=tostring(i-1) + action=wezterm.action{ActivateTab=i-1}, }) -- F1 through F8 to activate that tab table.insert(mykeys, { key="F" .. tostring(i), - action="ActivateTab", - arg=tostring(i-1) + action=wezterm.action{ActivateTab=i-1}, }) end diff --git a/src/config/keys.rs b/src/config/keys.rs index 94f1d0494..9c5e8b73f 100644 --- a/src/config/keys.rs +++ b/src/config/keys.rs @@ -1,5 +1,4 @@ -use crate::keyassignment::{KeyAssignment, SpawnTabDomain}; -use anyhow::{anyhow, Error}; +use crate::keyassignment::KeyAssignment; use serde::{Deserialize, Deserializer, Serialize}; use termwiz::input::{KeyCode, Modifiers}; @@ -9,125 +8,10 @@ pub struct Key { pub key: KeyCode, #[serde(deserialize_with = "de_modifiers", default)] pub mods: Modifiers, - // TODO: migrate this to using KeyAssignment directly. - // We're preserving KeyAction here for a release or - // two to allow for a slightly more graceful migration - // for user configs. - pub action: KeyAction, - // TODO: once action is switched to KeyAssignment, remove - // the arg field. Maybe we can use the presence of this - // field to warn users that they need to migrate? - #[serde(default)] - pub arg: Option, + pub action: KeyAssignment, } impl_lua_conversion!(Key); -impl std::convert::TryInto for &Key { - type Error = Error; - fn try_into(self) -> Result { - Ok(match self.action { - KeyAction::SpawnTab => KeyAssignment::SpawnTab(SpawnTabDomain::DefaultDomain), - KeyAction::SpawnTabInCurrentTabDomain => { - KeyAssignment::SpawnTab(SpawnTabDomain::CurrentTabDomain) - } - KeyAction::SpawnTabInDomain => { - let arg = self - .arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))?; - - if let Ok(id) = arg.parse() { - KeyAssignment::SpawnTab(SpawnTabDomain::Domain(id)) - } else { - KeyAssignment::SpawnTab(SpawnTabDomain::DomainName(arg.to_string())) - } - } - KeyAction::SpawnWindow => KeyAssignment::SpawnWindow, - KeyAction::ToggleFullScreen => KeyAssignment::ToggleFullScreen, - KeyAction::Copy => KeyAssignment::Copy, - KeyAction::Paste => KeyAssignment::Paste, - KeyAction::Hide => KeyAssignment::Hide, - KeyAction::HideApplication => KeyAssignment::HideApplication, - KeyAction::QuitApplication => KeyAssignment::QuitApplication, - KeyAction::Show => KeyAssignment::Show, - KeyAction::IncreaseFontSize => KeyAssignment::IncreaseFontSize, - KeyAction::DecreaseFontSize => KeyAssignment::DecreaseFontSize, - KeyAction::ResetFontSize => KeyAssignment::ResetFontSize, - KeyAction::Nop => KeyAssignment::Nop, - KeyAction::CloseCurrentTab => KeyAssignment::CloseCurrentTab, - KeyAction::ActivateTab => KeyAssignment::ActivateTab( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .parse()?, - ), - KeyAction::ActivateTabRelative => KeyAssignment::ActivateTabRelative( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .parse()?, - ), - KeyAction::SendString => KeyAssignment::SendString( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .to_owned(), - ), - KeyAction::ReloadConfiguration => KeyAssignment::ReloadConfiguration, - KeyAction::MoveTab => KeyAssignment::MoveTab( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .parse()?, - ), - KeyAction::MoveTabRelative => KeyAssignment::MoveTabRelative( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .parse()?, - ), - KeyAction::ScrollByPage => KeyAssignment::ScrollByPage( - self.arg - .as_ref() - .ok_or_else(|| anyhow!("missing arg for {:?}", self))? - .parse()?, - ), - KeyAction::ShowTabNavigator => KeyAssignment::ShowTabNavigator, - KeyAction::Action(ref a) => a.clone(), - }) - } -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub enum KeyAction { - SpawnTab, - SpawnTabInCurrentTabDomain, - SpawnTabInDomain, - SpawnWindow, - ToggleFullScreen, - Copy, - Paste, - ActivateTabRelative, - IncreaseFontSize, - DecreaseFontSize, - ResetFontSize, - ActivateTab, - SendString, - Nop, - Hide, - HideApplication, - QuitApplication, - Show, - CloseCurrentTab, - ReloadConfiguration, - MoveTab, - MoveTabRelative, - ScrollByPage, - ShowTabNavigator, - Action(KeyAssignment), -} -impl_lua_conversion!(KeyAction); - fn de_keycode<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, diff --git a/src/config/mod.rs b/src/config/mod.rs index aa864f4bc..61aa71bec 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -12,7 +12,6 @@ use portable_pty::{CommandBuilder, PtySize}; use serde::{Deserialize, Serialize}; use std; use std::collections::HashMap; -use std::convert::TryInto; use std::ffi::{OsStr, OsString}; use std::fs; use std::io::prelude::*; @@ -652,8 +651,7 @@ impl Config { let mut map = HashMap::new(); for k in &self.keys { - let value = k.try_into()?; - map.insert((k.key, k.mods), value); + map.insert((k.key, k.mods), k.action.clone()); } Ok(map) diff --git a/src/keyassignment.rs b/src/keyassignment.rs index 9bcfef172..a83cae661 100644 --- a/src/keyassignment.rs +++ b/src/keyassignment.rs @@ -81,6 +81,7 @@ pub enum KeyAssignment { SpawnCommandInNewWindow(SpawnCommand), ShowLauncher, } +impl_lua_conversion!(KeyAssignment); pub struct KeyMap(HashMap<(KeyCode, KeyModifiers), KeyAssignment>); diff --git a/src/scripting/mod.rs b/src/scripting/mod.rs index 9cdb5a43c..4b7fb8416 100644 --- a/src/scripting/mod.rs +++ b/src/scripting/mod.rs @@ -212,10 +212,11 @@ fn font_with_fallback<'lua>( /// } /// } /// ``` -fn action<'lua>(lua: &'lua Lua, action: Table<'lua>) -> mlua::Result { - let wrapper = lua.create_table()?; - wrapper.set("Action", action)?; - Ok(from_lua_value(Value::Table(wrapper))?) +fn action<'lua>( + _lua: &'lua Lua, + action: Table<'lua>, +) -> mlua::Result { + Ok(from_lua_value(Value::Table(action))?) } fn read_dir<'lua>(_: &'lua Lua, path: String) -> mlua::Result> {