From 9b1def304e80067ca06a9ff0f44858077b1596f5 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 28 Dec 2020 21:01:51 -0500 Subject: [PATCH 1/2] alacritty: add CSIu support rationale and spec at http://www.leonerd.org.uk/hacks/fixterms/ --- modules/programs/alacritty.nix | 284 +++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) diff --git a/modules/programs/alacritty.nix b/modules/programs/alacritty.nix index 9c3e8e75dc40..9094c5f69a7e 100644 --- a/modules/programs/alacritty.nix +++ b/modules/programs/alacritty.nix @@ -5,6 +5,285 @@ with lib; let cfg = config.programs.alacritty; yamlFormat = pkgs.formats.yaml { }; + CSIuKeyBindings = [ + # http://www.leonerd.org.uk/hacks/fixterms/ + # Avoid to override default key-bindings + # + # Control + Shift + B ⇒ SearchBackward + # Control + Shift + C ⇒ Copy + # Control + Shift + F ⇒ SearchForward + # Control + Shift + V ⇒ Paste + # Control + 0 ⇒ ResetFontSize + + # ############################## + # Non-Captured CTRL Combinations + # ############################## + { + key = "H"; + mods = "Control"; + chars = "\\x1b[104;5u"; + } + { + key = "I"; + mods = "Control"; + chars = "\\x1b[105;5u"; + } + { + key = "J"; + mods = "Control"; + chars = "\\x1b[106;5u"; + } + { + key = "M"; + mods = "Control"; + chars = "\\x1b[109;5u"; + } + { + key = "Return"; + mods = "Control"; + chars = "\\x1b[13;5u"; + } + { + key = "Slash"; + mods = "Control"; + chars = "\\x1b[47;5u"; + } + + # ###################################### + # Non-Captured CTRL + SHIFT Combinations + # ###################################### + { + key = "51"; + mods = "Control|Shift"; + chars = "\\x1b[60;5u"; + } # Less + { + key = "52"; + mods = "Control|Shift"; + chars = "\\x1b[62;5u"; + } # Greater + + { + key = "A"; + mods = "Control|Shift"; + chars = "\\x1b[65;5u"; + } + # Control + B ⇒ SearchBackward + # { key = "B"; mods = "Control|Shift"; chars = "\\x1b[66;5u"; } + # Control + C ⇒ Copy + # { key = "C"; mods = "Control|Shift"; chars = "\\x1b[67;5u"; } + { + key = "D"; + mods = "Control|Shift"; + chars = "\\x1b[68;5u"; + } + { + key = "E"; + mods = "Control|Shift"; + chars = "\\x1b[69;5u"; + } + # Control + F ⇒ SearchForward + # { key = "F"; mods = "Control|Shift"; chars = "\\x1b[70;5u"; } + { + key = "G"; + mods = "Control|Shift"; + chars = "\\x1b[71;5u"; + } + { + key = "H"; + mods = "Control|Shift"; + chars = "\\x1b[72;5u"; + } + { + key = "I"; + mods = "Control|Shift"; + chars = "\\x1b[73;5u"; + } + { + key = "J"; + mods = "Control|Shift"; + chars = "\\x1b[74;5u"; + } + { + key = "K"; + mods = "Control|Shift"; + chars = "\\x1b[75;5u"; + } + { + key = "L"; + mods = "Control|Shift"; + chars = "\\x1b[76;5u"; + } + { + key = "M"; + mods = "Control|Shift"; + chars = "\\x1b[77;5u"; + } + { + key = "N"; + mods = "Control|Shift"; + chars = "\\x1b[78;5u"; + } + { + key = "O"; + mods = "Control|Shift"; + chars = "\\x1b[79;5u"; + } + { + key = "P"; + mods = "Control|Shift"; + chars = "\\x1b[80;5u"; + } + { + key = "Q"; + mods = "Control|Shift"; + chars = "\\x1b[81;5u"; + } + { + key = "R"; + mods = "Control|Shift"; + chars = "\\x1b[82;5u"; + } + { + key = "S"; + mods = "Control|Shift"; + chars = "\\x1b[83;5u"; + } + { + key = "T"; + mods = "Control|Shift"; + chars = "\\x1b[84;5u"; + } + { + key = "U"; + mods = "Control|Shift"; + chars = "\\x1b[85;5u"; + } + # Control + V ⇒ Paste + # { key = "V"; mods = "Control|Shift"; chars = "\\x1b[86;5u"; } + { + key = "W"; + mods = "Control|Shift"; + chars = "\\x1b[87;5u"; + } + { + key = "X"; + mods = "Control|Shift"; + chars = "\\x1b[88;5u"; + } + { + key = "Y"; + mods = "Control|Shift"; + chars = "\\x1b[89;5u"; + } + { + key = "Z"; + mods = "Control|Shift"; + chars = "\\x1b[90;5u"; + } + + # ################################ + # Non-Captured NumKey Combinations + # ################################ + # Control + 0 ⇒ ResetFontSize + # { key = "Key0"; mods = "Control"; chars = "\\x1b[48;5u"; } + { + key = "Key1"; + mods = "Control"; + chars = "\\x1b[49;5u"; + } + { + key = "Key2"; + mods = "Control"; + chars = "\\x1b[50;5u"; + } + { + key = "Key3"; + mods = "Control"; + chars = "\\x1b[51;5u"; + } + { + key = "Key4"; + mods = "Control"; + chars = "\\x1b[52;5u"; + } + { + key = "Key5"; + mods = "Control"; + chars = "\\x1b[53;5u"; + } + { + key = "Key6"; + mods = "Control"; + chars = "\\x1b[54;5u"; + } + { + key = "Key7"; + mods = "Control"; + chars = "\\x1b[55;5u"; + } + { + key = "Key8"; + mods = "Control"; + chars = "\\x1b[56;5u"; + } + { + key = "Key9"; + mods = "Control"; + chars = "\\x1b[57;5u"; + } + + { + key = "Key0"; + mods = "Control|Shift"; + chars = "\\x1b[48;6u"; + } + { + key = "Key1"; + mods = "Control|Shift"; + chars = "\\x1b[49;6u"; + } + { + key = "Key2"; + mods = "Control|Shift"; + chars = "\\x1b[50;6u"; + } + { + key = "Key3"; + mods = "Control|Shift"; + chars = "\\x1b[51;6u"; + } + { + key = "Key4"; + mods = "Control|Shift"; + chars = "\\x1b[52;6u"; + } + { + key = "Key5"; + mods = "Control|Shift"; + chars = "\\x1b[53;6u"; + } + { + key = "Key6"; + mods = "Control|Shift"; + chars = "\\x1b[54;6u"; + } + { + key = "Key7"; + mods = "Control|Shift"; + chars = "\\x1b[55;6u"; + } + { + key = "Key8"; + mods = "Control|Shift"; + chars = "\\x1b[56;6u"; + } + { + key = "Key9"; + mods = "Control|Shift"; + chars = "\\x1b[57;6u"; + } + ]; in { options = { programs.alacritty = { @@ -17,6 +296,8 @@ in { description = "The Alacritty package to install."; }; + CSIuSupport = mkEnableOption "Enable CSIu support"; + settings = mkOption { type = yamlFormat.type; default = { }; @@ -49,6 +330,9 @@ in { (mkIf cfg.enable { home.packages = [ cfg.package ]; + programs.alacritty.settings.key_bindings = + mkIf cfg.CSIuSupport CSIuKeyBindings; + xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) { # TODO: Replace by the generate function but need to figure out how to # handle the escaping first. From b0bde0c37dc1aca3a87776655daeb2a799999b6c Mon Sep 17 00:00:00 2001 From: David Arnold Date: Thu, 15 Jul 2021 11:24:41 -0500 Subject: [PATCH 2/2] alacritty: test for CSIu support --- .../csiu-enabled-merging-expected.yml | 1 + .../alacritty/csiu-enabled-merging.nix | 27 +++++++++++++++++++ tests/modules/programs/alacritty/default.nix | 1 + 3 files changed, 29 insertions(+) create mode 100644 tests/modules/programs/alacritty/csiu-enabled-merging-expected.yml create mode 100644 tests/modules/programs/alacritty/csiu-enabled-merging.nix diff --git a/tests/modules/programs/alacritty/csiu-enabled-merging-expected.yml b/tests/modules/programs/alacritty/csiu-enabled-merging-expected.yml new file mode 100644 index 000000000000..b362f6aa359d --- /dev/null +++ b/tests/modules/programs/alacritty/csiu-enabled-merging-expected.yml @@ -0,0 +1 @@ +{"key_bindings":[{"chars":"\x1b[104;5u","key":"H","mods":"Control"},{"chars":"\x1b[105;5u","key":"I","mods":"Control"},{"chars":"\x1b[106;5u","key":"J","mods":"Control"},{"chars":"\x1b[109;5u","key":"M","mods":"Control"},{"chars":"\x1b[13;5u","key":"Return","mods":"Control"},{"chars":"\x1b[47;5u","key":"Slash","mods":"Control"},{"chars":"\x1b[60;5u","key":"51","mods":"Control|Shift"},{"chars":"\x1b[62;5u","key":"52","mods":"Control|Shift"},{"chars":"\x1b[65;5u","key":"A","mods":"Control|Shift"},{"chars":"\x1b[68;5u","key":"D","mods":"Control|Shift"},{"chars":"\x1b[69;5u","key":"E","mods":"Control|Shift"},{"chars":"\x1b[71;5u","key":"G","mods":"Control|Shift"},{"chars":"\x1b[72;5u","key":"H","mods":"Control|Shift"},{"chars":"\x1b[73;5u","key":"I","mods":"Control|Shift"},{"chars":"\x1b[74;5u","key":"J","mods":"Control|Shift"},{"chars":"\x1b[75;5u","key":"K","mods":"Control|Shift"},{"chars":"\x1b[76;5u","key":"L","mods":"Control|Shift"},{"chars":"\x1b[77;5u","key":"M","mods":"Control|Shift"},{"chars":"\x1b[78;5u","key":"N","mods":"Control|Shift"},{"chars":"\x1b[79;5u","key":"O","mods":"Control|Shift"},{"chars":"\x1b[80;5u","key":"P","mods":"Control|Shift"},{"chars":"\x1b[81;5u","key":"Q","mods":"Control|Shift"},{"chars":"\x1b[82;5u","key":"R","mods":"Control|Shift"},{"chars":"\x1b[83;5u","key":"S","mods":"Control|Shift"},{"chars":"\x1b[84;5u","key":"T","mods":"Control|Shift"},{"chars":"\x1b[85;5u","key":"U","mods":"Control|Shift"},{"chars":"\x1b[87;5u","key":"W","mods":"Control|Shift"},{"chars":"\x1b[88;5u","key":"X","mods":"Control|Shift"},{"chars":"\x1b[89;5u","key":"Y","mods":"Control|Shift"},{"chars":"\x1b[90;5u","key":"Z","mods":"Control|Shift"},{"chars":"\x1b[49;5u","key":"Key1","mods":"Control"},{"chars":"\x1b[50;5u","key":"Key2","mods":"Control"},{"chars":"\x1b[51;5u","key":"Key3","mods":"Control"},{"chars":"\x1b[52;5u","key":"Key4","mods":"Control"},{"chars":"\x1b[53;5u","key":"Key5","mods":"Control"},{"chars":"\x1b[54;5u","key":"Key6","mods":"Control"},{"chars":"\x1b[55;5u","key":"Key7","mods":"Control"},{"chars":"\x1b[56;5u","key":"Key8","mods":"Control"},{"chars":"\x1b[57;5u","key":"Key9","mods":"Control"},{"chars":"\x1b[48;6u","key":"Key0","mods":"Control|Shift"},{"chars":"\x1b[49;6u","key":"Key1","mods":"Control|Shift"},{"chars":"\x1b[50;6u","key":"Key2","mods":"Control|Shift"},{"chars":"\x1b[51;6u","key":"Key3","mods":"Control|Shift"},{"chars":"\x1b[52;6u","key":"Key4","mods":"Control|Shift"},{"chars":"\x1b[53;6u","key":"Key5","mods":"Control|Shift"},{"chars":"\x1b[54;6u","key":"Key6","mods":"Control|Shift"},{"chars":"\x1b[55;6u","key":"Key7","mods":"Control|Shift"},{"chars":"\x1b[56;6u","key":"Key8","mods":"Control|Shift"},{"chars":"\x1b[57;6u","key":"Key9","mods":"Control|Shift"},{"chars":"\x0c","key":"K","mods":"Control"}]} \ No newline at end of file diff --git a/tests/modules/programs/alacritty/csiu-enabled-merging.nix b/tests/modules/programs/alacritty/csiu-enabled-merging.nix new file mode 100644 index 000000000000..e29fb6f7f0fb --- /dev/null +++ b/tests/modules/programs/alacritty/csiu-enabled-merging.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.alacritty = { + enable = true; + CSIuSupport = true; + package = pkgs.writeScriptBin "dummy-alacritty" ""; + + settings = { + key_bindings = [{ + key = "K"; + mods = "Control"; + chars = "\\x0c"; + }]; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/alacritty/alacritty.yml \ + ${./csiu-enabled-merging-expected.yml} + ''; + }; +} diff --git a/tests/modules/programs/alacritty/default.nix b/tests/modules/programs/alacritty/default.nix index 3ccd9a91f33a..39ab74033a8b 100644 --- a/tests/modules/programs/alacritty/default.nix +++ b/tests/modules/programs/alacritty/default.nix @@ -2,4 +2,5 @@ alacritty-example-settings = ./example-settings.nix; alacritty-empty-settings = ./empty-settings.nix; alacritty-merging-settings = ./settings-merging.nix; + alacritty-csiu-enabled-merging = ./csiu-enabled-merging.nix; }