From bfdf4e6be3489f36acdada3f31fda34efdd8a847 Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Wed, 19 Sep 2018 23:32:39 +0800 Subject: [PATCH] fix input-source keyword used in --- CHANGELOG.org | 11 +++- README.org | 4 +- src/karabiner_configurator/conditions.clj | 4 +- src/karabiner_configurator/core.clj | 4 +- src/karabiner_configurator/data.clj | 8 +-- src/karabiner_configurator/rules.clj | 11 +++- src/karabiner_configurator/tos.clj | 4 +- test/karabiner_configurator/froms_test.clj | 2 +- test/karabiner_configurator/layers_test.clj | 2 +- .../karabiner_configurator/modifiers_test.clj | 2 +- test/karabiner_configurator/rules_test.clj | 56 +++++++++++++++++-- test/karabiner_configurator/tos_test.clj | 4 +- 12 files changed, 85 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 2a59607..33cefac 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -3,7 +3,14 @@ All notable changes to this project will be documented in this file. This change ** Unreleased -[Unreleased]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.1.6...HEAD +[Unreleased]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.1.7...HEAD + +** 0.1.7 - 2018-09-19 +*** Fixed +- use keyword defined in :input-sources to as key + +[0.1.7]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.1.6...v0.1.7 + ** 0.1.6 - 2018-09-15 *** Fixed - karabiner.json broken when can't find karabiner.edn @@ -11,7 +18,7 @@ All notable changes to this project will be documented in this file. This change - can install through brew now, ~brew install yqrashawn/goku/goku~ - ~gokuw~ as watch script, ~brew services start goku~ as service -[0.1.6]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.1.2...v0.1.3 +[0.1.6]: https://github.com/yqrashawn/GokuRakuJoudo/compare/v0.1.3...v0.1.6 ** 0.1.3 - 2018-09-11 *** Fixed diff --git a/README.org b/README.org index 9f926c6..ce895c6 100644 --- a/README.org +++ b/README.org @@ -61,4 +61,6 @@ parse error. - mouse key has no abbreviation keyword in main rules ** The name -It's the name of the song I'm lisening while writing this. \ No newline at end of file +It's the name of the song I'm lisening while writing this. +** Changelog +Check [[./CHANGELOG.org][CHANGELOG]] file. diff --git a/src/karabiner_configurator/conditions.clj b/src/karabiner_configurator/conditions.clj index 8cf85af..a4361d0 100644 --- a/src/karabiner_configurator/conditions.clj +++ b/src/karabiner_configurator/conditions.clj @@ -58,8 +58,8 @@ (do (update-used-simlayers-config (condi (:simlayers conf-data))) (update-used-simlayers-config (assoc-in used-simlayers-config [:from :sim] - (conj (:sim (:from used-simlayers-config)) - (keyword (:key_code from))))))) + (into [] (conj (:sim (:from used-simlayers-config)) + (keyword (:key_code from))) ))))) {:name (name condi) :value 1 :type condi-type}) diff --git a/src/karabiner_configurator/core.clj b/src/karabiner_configurator/core.clj index 6bd65ca..18a44dd 100644 --- a/src/karabiner_configurator/core.clj +++ b/src/karabiner_configurator/core.clj @@ -25,11 +25,11 @@ (defn generate "generate configuration" [conf] - (let [{:keys [applications devices keyboard-type input-source tos froms modifiers layers simlayers raws main simlayer-threshold templates]} conf] + (let [{:keys [applications devices keyboard-type input-sources tos froms modifiers layers simlayers raws main simlayer-threshold templates]} conf] (update-static-conf :applications applications) (update-static-conf :devices devices) (update-static-conf :keyboard-type keyboard-type) - (update-static-conf :input-source tos) + (update-static-conf :input-sources input-sources) (update-static-conf :templates templates) (if (number? simlayer-threshold) (update-static-conf :simlayer-threshold simlayer-threshold)) diff --git a/src/karabiner_configurator/data.clj b/src/karabiner_configurator/data.clj index ad8a18b..97cea62 100644 --- a/src/karabiner_configurator/data.clj +++ b/src/karabiner_configurator/data.clj @@ -8,7 +8,7 @@ [] (def conf-data {:applications {} :devices {} - :input-source {} + :input-sources {} :modifiers {} :froms {} :tos {} @@ -87,9 +87,9 @@ (contains? (:devices conf-data)) {:name :devices :value (kw (:devices conf-data))} - (contains? (:input-source conf-data)) - {:name :input-source - :value (kw (:input-source conf-data))} + (contains? (:input-sources conf-data)) + {:name :input-sources + :value (kw (:input-sources conf-data))} (contains? (:simlayers conf-data)) {:name :simlayers :value (kw (:simlayers conf-data))})) diff --git a/src/karabiner_configurator/rules.clj b/src/karabiner_configurator/rules.clj index 50e826b..f542daa 100644 --- a/src/karabiner_configurator/rules.clj +++ b/src/karabiner_configurator/rules.clj @@ -19,7 +19,7 @@ [des from] (let [result nil validate-from (assert (or (and (vector? from) (= 2 (count from)) (k? (first from)) (k? (second from))) - (and (keyword? from) (or (k? from) (special-modi-k? from) (nn? (from (:froms conf-data))))) + (and (keyword? from) (or (k? from) (special-modi-k? from) (contains? (:froms conf-data) from))) (map? from)) (str "invalid in main section's " des)) result (if (vector? from) @@ -112,13 +112,18 @@ (let [result nil validate-to (assert (or (and (keyword? to) (or (k? to) (special-modi-k? to) + (contains? (:input-sources conf-data) to) (contains? (:tos conf-data) to))) (string? to) (vector? to) (map? to)) (str "invalid in main section's " des)) - result (if (keyword? to) - (rule-parse-keyword des to)) + result (if (contains? (:input-sources conf-data) to) + (into [] (tos/parse-to des [{:input to}])) + result) + result (if (and (keyword? to) (not (contains? (:input-sources conf-data) to))) + (rule-parse-keyword des to) + result) result (if (nn? result) (cond (vector? result) result diff --git a/src/karabiner_configurator/tos.clj b/src/karabiner_configurator/tos.clj index 08d3c3a..61b2022 100644 --- a/src/karabiner_configurator/tos.clj +++ b/src/karabiner_configurator/tos.clj @@ -65,12 +65,12 @@ result (parse-key tname tinfo true true) validate-shell (assert (or (and (vector? shell) (contains? (:templates conf-data) (first shell))) (string? shell) (nil? shell)) (str "invalid `shell` in to defination " tname " " shell ", should be string or keyword")) - validate-input (assert (or (nil? input) (and (keyword? input) (contains? (:input-source conf-data) input))) + validate-input (assert (or (nil? input) (and (keyword? input) (contains? (:input-sources conf-data) input))) (str "invalid `input` in to defination " tname " " input ", should be a keyword")) validate-set (assert (or (vector? set) (nil? set)) (str "invalid `set` in to defination " tname " " set ", should be a vector")) result (if (keyword? input) - (assoc result :select_input_source (input (:input-source conf-data))) + (assoc result :select_input_source (input (:input-sources conf-data))) result) result (if (string? shell) (assoc result :shell_command shell) diff --git a/test/karabiner_configurator/froms_test.clj b/test/karabiner_configurator/froms_test.clj index b341c6b..ee82ae3 100644 --- a/test/karabiner_configurator/froms_test.clj +++ b/test/karabiner_configurator/froms_test.clj @@ -26,7 +26,7 @@ (def result {:applications {}, :tos {}, - :input-source {}, + :input-sources {}, :modifiers {:1 {:mandatory ["left_command" "right_shift"], :optional ["any"]}}, :simlayer-threshold 250, diff --git a/test/karabiner_configurator/layers_test.clj b/test/karabiner_configurator/layers_test.clj index 9ff97f3..eb5557e 100644 --- a/test/karabiner_configurator/layers_test.clj +++ b/test/karabiner_configurator/layers_test.clj @@ -18,7 +18,7 @@ :chromes ["^com\\.google\\.Chrome$" "^com\\.google\\.Chrome\\.canary$"]}, :tos {}, - :input-source {}, + :input-sources {}, :modifiers {}, :simlayer-threshold 250, :devices {:hhkb-bt [{:vendor_id 1278, diff --git a/test/karabiner_configurator/modifiers_test.clj b/test/karabiner_configurator/modifiers_test.clj index 0a95184..466daf4 100644 --- a/test/karabiner_configurator/modifiers_test.clj +++ b/test/karabiner_configurator/modifiers_test.clj @@ -10,7 +10,7 @@ (def result {:applications {}, :tos {}, - :input-source {}, + :input-sources {}, :modifiers {:111 {:mandatory ["left_command" "left_control"]}, :222 {:mandatory ["left_command" "left_shift"]}, :3 {:mandatory ["left_command"]}, diff --git a/test/karabiner_configurator/rules_test.clj b/test/karabiner_configurator/rules_test.clj index cac2e3d..1193369 100644 --- a/test/karabiner_configurator/rules_test.clj +++ b/test/karabiner_configurator/rules_test.clj @@ -24,7 +24,10 @@ [:!C#Pq ["command-q" 1] :safari {:delayed {:invoked ["command-q" 0] :canceled ["command-q" 0]}}]]} {:des "Mouse button" :rules [[{:pkey :button5} :mission_control] - [{:pkey :button4} [{:pkey :button1} {:pkey :button1} :!!grave_accent_and_tilde]]]}]) + [{:pkey :button4} [{:pkey :button1} {:pkey :button1} :!!grave_accent_and_tilde]]]} + {:des "Change input source" + :rules [[:i :us :q-mode] + [:o :squirrel :q-mode]]}]) (def result [{:description "a to 1", @@ -186,7 +189,42 @@ "left_control" "left_option" "left_shift"]}], - :type "basic"}]}]) + :type "basic"}]} + {:description "Change input source", + :manipulators [{:from {:key_code "i"}, + :to [{:select_input_source {:input_mode_id "", + :input_source_id "com.apple.keylayout.US", + :language "en"}}], + :conditions [{:name "q-mode", + :value 1, + :type "variable_if"}], + :type "basic"} + {:key :q, + :from {:simultaneous [{:key_code "i"}], + :simultaneous_options {:detect_key_down_uninterruptedly false, + :key_down_order "insensitive", + :key_up_order "insensitive", + :key_up_when "any"}}, + :to [{:select_input_source {:input_mode_id "", + :input_source_id "com.apple.keylayout.US", + :language "en"}}]} + {:from {:key_code "o"}, + :to [{:select_input_source {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel", + :input_source_id "com.googlecode.rimeime.inputmethod.Squirrel.Rime", + :language "zh-Hans"}}], + :conditions [{:name "q-mode", + :value 1, + :type "variable_if"}], + :type "basic"} + {:key :q, + :from {:simultaneous [{:key_code "o"}], + :simultaneous_options {:detect_key_down_uninterruptedly false, + :key_down_order "insensitive", + :key_up_order "insensitive", + :key_up_when "any"}}, + :to [{:select_input_source {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel", + :input_source_id "com.googlecode.rimeime.inputmethod.Squirrel.Rime", + :language "zh-Hans"}}]}]}]) (t/deftest generate-mains @@ -197,13 +235,18 @@ :chromes ["^com\\.google\\.Chrome$" "^com\\.google\\.Chrome\\.canary$"]} :devices {:hhkb-bt [{:vendor_id 1278 :product_id 51966}] :hhkb [{:vendor_id 2131 :product_id 256}]} - :input-source {} + :input-sources {:squirrel {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel" + :input_source_id "com.googlecode.rimeime.inputmethod.Squirrel.Rime" + :language "zh-Hans"} + :us {:input_mode_id "" + :input_source_id "com.apple.keylayout.US" + :language "en"}} :templates {:example-template "osascript -e 'display dialog \"%s\"'"} :modifiers {} :froms {:my-spacebar {:key :spacebar}} :tos {} - :layers {} - :simlayers {:vi-mode {:parameters {:basic.simultaneous_threshold_milliseconds 250}, + :simlayers {:q-mode {:key :q} + :vi-mode {:parameters {:basic.simultaneous_threshold_milliseconds 250}, :to [{:set ["vi-mode" 1]}], :from {:sim [:d], :simo {:interrupt true, @@ -221,4 +264,5 @@ (t/testing - (t/is (= (sut/parse-mains example-mains) result)))) \ No newline at end of file + (t/is (= (sut/parse-mains example-mains) result)))) + diff --git a/test/karabiner_configurator/tos_test.clj b/test/karabiner_configurator/tos_test.clj index b32b640..55e85eb 100644 --- a/test/karabiner_configurator/tos_test.clj +++ b/test/karabiner_configurator/tos_test.clj @@ -79,7 +79,7 @@ :key_code "d"}] :6 [{:modifiers ["left_command" "right_shift"], :key_code "d"}]} - :input-source {:squirrel {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel", + :input-sources {:squirrel {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel", :input_source_id "com.googlecode.rimeime.inputmethod.Squirrel.Rime", :language "zh-Hans"}, :us {:input_mode_id "", @@ -98,7 +98,7 @@ (init-conf-data) (update-conf-data (assoc conf-data :templates {:launch "osascript -e 'tell application \"Alfred 3\" to run trigger \"launch%s\" in workflow \"yqrashawn.workflow.launcher\" with argument \"\"'"})) (update-conf-data (assoc conf-data :modifiers {:1 {:mandatory ["left_command", "right_shift"]}})) - (update-conf-data (assoc conf-data :input-source {:squirrel {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel" + (update-conf-data (assoc conf-data :input-sources {:squirrel {:input_mode_id "com.googlecode.rimeime.inputmethod.Squirrel" :input_source_id "com.googlecode.rimeime.inputmethod.Squirrel.Rime" :language "zh-Hans"} :us {:input_mode_id ""