|
65 | 65 | [tname tinfos]
|
66 | 66 | (mapv
|
67 | 67 | (fn [{:keys [set input shell lazy repeat halt hold_down_ms select_input_source noti softf] :as tinfo}]
|
68 |
| - (let [result (parse-key tname tinfo true true) |
69 |
| - _validate-shell (massert (or (and (vector? shell) (contains? (:templates @conf-data) (first shell))) (string? shell) (nil? shell)) |
70 |
| - (str "invalid `shell` in to definition " tname " " shell ", should be string or keyword")) |
71 |
| - _validate-input (massert (or (nil? input) (and (keyword? input) (contains? (:input-sources @conf-data) input))) |
72 |
| - (str "invalid `input` in to definition " tname " " input ", should be a keyword")) |
73 |
| - _validate-set (massert (or (vector? set) (nil? set)) |
74 |
| - (str "invalid `set` in to definition " tname " " set ", should be a vector")) |
75 |
| - _validate-noti (massert (or (nil? noti) (and (map? noti) |
76 |
| - (or (keyword? (get noti :id)) |
77 |
| - (string? (get noti :id))) |
78 |
| - (or (nil? (get noti :text)) |
79 |
| - (keyword? (get noti :text)) |
80 |
| - (string? (get noti :text))))) |
81 |
| - (str "invalid `noti`, must be a map with at least :id, :id must be string or keyword")) |
82 |
| - _validate-softf (massert (or (nil? softf) (map? softf)) |
83 |
| - (str "invalid `softf`, must be a map with valid keys")) |
84 |
| - result (if (keyword? input) |
85 |
| - (assoc result :select_input_source (input (:input-sources @conf-data))) |
86 |
| - result) |
87 |
| - result (if (string? shell) |
88 |
| - (assoc result :shell_command shell) |
89 |
| - result) |
90 |
| - result (if (vector? shell) |
91 |
| - (assoc result |
92 |
| - :shell_command (apply |
93 |
| - format |
94 |
| - (flatten |
95 |
| - [((first shell) |
96 |
| - (:templates @conf-data)) |
97 |
| - (rest shell) |
98 |
| - ;; optional arguments |
99 |
| - "" "" "" "" "" ""]))) |
100 |
| - result) |
101 |
| - result (if (vector? set) |
102 |
| - (assoc result :set_variable {:name (first set) :value (second set)}) |
103 |
| - result) |
104 |
| - result (if (false? repeat) |
105 |
| - (assoc result :repeat false) |
106 |
| - result) |
107 |
| - result (if (true? halt) |
108 |
| - (assoc result :halt true) |
109 |
| - result) |
110 |
| - result (if (and (number? hold_down_ms) (not (= 0 hold_down_ms))) |
111 |
| - (assoc result :hold_down_milliseconds hold_down_ms) |
112 |
| - result) |
113 |
| - result (if (boolean? lazy) |
114 |
| - (assoc result :lazy lazy) |
115 |
| - result) |
116 |
| - result (if noti |
117 |
| - (let [{:keys [id text]} noti] |
118 |
| - (assoc result :set_notification_message {:id id :text (or text "")})) |
119 |
| - result) |
120 |
| - softf (when softf |
121 |
| - (cset/rename-keys softf {:dbc :cg_event_double_click |
122 |
| - :sleep :iokit_power_management_sleep_system |
123 |
| - :open :open_application |
124 |
| - :setmpos :set_mouse_cursor_position})) |
125 |
| - result (cond-> result |
126 |
| - (map? softf) |
127 |
| - (assoc :software_function softf)) |
128 |
| - result (if select_input_source tinfo result)] |
129 |
| - result)) |
| 68 | + ;; validate-shell |
| 69 | + (massert (or (and (vector? shell) |
| 70 | + (contains? (:templates @conf-data) (first shell))) |
| 71 | + (string? shell) (nil? shell)) |
| 72 | + (format |
| 73 | + "invalid `shell` in to definition %s %s, should be string or keyword" |
| 74 | + tname shell)) |
| 75 | + ;; validate-input |
| 76 | + (massert (or (nil? input) |
| 77 | + (and |
| 78 | + (keyword? input) |
| 79 | + (contains? (:input-sources @conf-data) input))) |
| 80 | + (format |
| 81 | + "invalid `input` in to definition %s %s, should be a keyword" |
| 82 | + tname input)) |
| 83 | + ;; validate-set |
| 84 | + (massert (or (vector? set) (nil? set)) |
| 85 | + (format "invalid `set` in to definition %s %s, should be a vector" |
| 86 | + tname set)) |
| 87 | + ;; validate-noti |
| 88 | + (massert (or (nil? noti) |
| 89 | + (and (map? noti) |
| 90 | + (or (keyword? (get noti :id)) |
| 91 | + (string? (get noti :id))) |
| 92 | + (or (nil? (get noti :text)) |
| 93 | + (keyword? (get noti :text)) |
| 94 | + (string? (get noti :text))))) |
| 95 | + (str "invalid `noti`, must be a map with at least :id, :id must be string or keyword")) |
| 96 | + ;; validate-softf |
| 97 | + (massert (or (nil? softf) (map? softf)) |
| 98 | + (str "invalid `softf`, must be a map with valid keys")) |
| 99 | + (let [softf |
| 100 | + (when softf |
| 101 | + (cset/rename-keys softf {:dbc :cg_event_double_click |
| 102 | + :sleep :iokit_power_management_sleep_system |
| 103 | + :open :open_application |
| 104 | + :setmpos :set_mouse_cursor_position})) |
| 105 | + result |
| 106 | + (cond-> (parse-key tname tinfo true true) |
| 107 | + (keyword? input) |
| 108 | + (assoc :select_input_source (input (:input-sources @conf-data))) |
| 109 | + |
| 110 | + (string? shell) |
| 111 | + (assoc :shell_command shell) |
| 112 | + |
| 113 | + (vector? shell) |
| 114 | + (assoc :shell_command |
| 115 | + (apply |
| 116 | + format |
| 117 | + (flatten |
| 118 | + [((first shell) |
| 119 | + (:templates @conf-data)) |
| 120 | + (rest shell) |
| 121 | + ;; optional arguments |
| 122 | + "" "" "" "" "" ""]))) |
| 123 | + |
| 124 | + (vector? set) |
| 125 | + (assoc :set_variable {:name (first set) :value (second set)}) |
| 126 | + |
| 127 | + (false? repeat) |
| 128 | + (assoc :repeat false) |
| 129 | + |
| 130 | + (true? halt) |
| 131 | + (assoc :halt true) |
| 132 | + |
| 133 | + (and (number? hold_down_ms) (not (= 0 hold_down_ms))) |
| 134 | + (assoc :hold_down_milliseconds hold_down_ms) |
| 135 | + |
| 136 | + (boolean? lazy) |
| 137 | + (assoc :lazy lazy) |
| 138 | + |
| 139 | + noti |
| 140 | + (assoc :set_notification_message {:id (:id noti) |
| 141 | + :text (or (:text noti) "")}) |
| 142 | + |
| 143 | + (map? softf) |
| 144 | + (assoc :software_function softf))] |
| 145 | + (if select_input_source tinfo result))) |
130 | 146 | tinfos))
|
131 | 147 |
|
132 | 148 | (defn generate [tos]
|
|
0 commit comments