Skip to content

Commit

Permalink
fix input-source keyword used in <to>
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Sep 19, 2018
1 parent a1cdabb commit bfdf4e6
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 27 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ 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 <to> 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
*** Added
- 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
Expand Down
4 changes: 3 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
It's the name of the song I'm lisening while writing this.
** Changelog
Check [[./CHANGELOG.org][CHANGELOG]] file.
4 changes: 2 additions & 2 deletions src/karabiner_configurator/conditions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions src/karabiner_configurator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions src/karabiner_configurator/data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[]
(def conf-data {:applications {}
:devices {}
:input-source {}
:input-sources {}
:modifiers {}
:froms {}
:tos {}
Expand Down Expand Up @@ -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))}))
Expand Down
11 changes: 8 additions & 3 deletions src/karabiner_configurator/rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 <from> in main section's " des))
result (if (vector? from)
Expand Down Expand Up @@ -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 <to> 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
Expand Down
4 changes: 2 additions & 2 deletions src/karabiner_configurator/tos.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/karabiner_configurator/froms_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(def result
{:applications {},
:tos {},
:input-source {},
:input-sources {},
:modifiers {:1 {:mandatory ["left_command" "right_shift"],
:optional ["any"]}},
:simlayer-threshold 250,
Expand Down
2 changes: 1 addition & 1 deletion test/karabiner_configurator/layers_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/karabiner_configurator/modifiers_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]},
Expand Down
56 changes: 50 additions & 6 deletions test/karabiner_configurator/rules_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -221,4 +264,5 @@


(t/testing
(t/is (= (sut/parse-mains example-mains) result))))
(t/is (= (sut/parse-mains example-mains) result))))

4 changes: 2 additions & 2 deletions test/karabiner_configurator/tos_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 "",
Expand All @@ -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 ""
Expand Down

0 comments on commit bfdf4e6

Please sign in to comment.