diff --git a/Cargo.toml b/Cargo.toml index 982ce2f5d..ebd36be7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,10 +35,6 @@ path = "src/lib.rs" name = "kanata" path = "src/main.rs" -[[bin]] -name = "transform_chords" -path = "src/transform_chords.rs" - [dependencies] anyhow = "1" clap = { version = "4", features = [ "std", "derive", "help", "suggestions" ], default_features = false } @@ -50,7 +46,6 @@ miette = { version = "5.7.0", features = ["fancy"] } once_cell = "1" parking_lot = "0.12" radix_trie = "0.2" -regex = "1" rustc-hash = "1.1.0" simplelog = "0.12.0" serde_json = { version = "1", features = ["std"], default_features = false, optional = true } diff --git a/cfg_samples/bone_mac.kbd b/cfg_samples/bone_mac.kbd deleted file mode 100644 index 18b77b371..000000000 --- a/cfg_samples/bone_mac.kbd +++ /dev/null @@ -1,160 +0,0 @@ -(defcfg - chords-v2-min-idle-experimental 200 - sequence-input-mode visible-backspaced - ;;process-unmapped-keys yes - concurrent-tap-hold true) -(deftemplate seq (vk-name in out) - (defvirtualkeys $vk-name $out) - (defseq $vk-name $in)) - -(defvirtualkeys rls-sft (multi (release-key lsft)(release-key rsft))) -(defvar rls-sft (on-press tap-vkey rls-sft)) -(deftemplate rls-sft () $rls-sft 5) - -(deflocalkeys-macos - ß 12 - ´ 13 - z 21 - ü 26 - + 27 - ö 39 - ä 40 - < 41 - # 43 - y 44 - - 53 - ^ 86 -) - -(defsrc - ⎋ f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 - ^ 1 2 3 4 5 6 7 8 9 0 ß ´ ⌫ - ↹ q w e r t z u i o p ü + - ⇪ a s d f g h j k l ö ä # ↩ - ‹⇧ < y x c v b n m , . - ▲ ⇧› - fn ‹⌃ ‹⌥ ‹⌘ ␣ ⌘› ⌥› ◀ ▼ ▶ -) - -(deflayer level1 - _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ - = _ - _ j d u a x p h l m w ß rctl - @lv3 c t i e o b n r s g q @lv3 ret - @osf _ f v ü ä ö y z , . k _ @osf - @fn _ _ _ spc @lv4 _ _ _ _ -) - -;; (deflayer level2 -;; S-f1 S-f2 S-f3 S-f4 S-f5 S-f6 S-f7 S-f8 S-f9 S-f10 S-f11 S-f12 -;; _ 1 2 3 4 5 6 7 8 9 0 - = -;; S-tab J D U A X P H L M W _ ´ -;; @lv5 C T I E O B N R S G Q @lv5 S-ret -;; ✗ F V Ü Ä Ö S-@y S-@z - • K ✗ S-up -;; lctl lalt S-lmet spc S-@lv4 ralt S-left S-down S-rght -;; ) - -(deflayer level3 - _ A-f1 A-f2 A-f3 A-f4 A-f5 A-f6 A-f7 A-f8 A-f9 A-f10 A-f11 A-f12 - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ RA-. S-- RA-5 RA-6 ^ S-1 < S-< S-0 S-6 RA-e / - ✗ A-S-7 S-7 RA-8 RA-9 S-+ S-ß S-8 S-9 - S-. RA-l XX A-ret - _ _ # S-4 RA-7 RA-n S-´ + S-5 S-2 S-# S-, M-up _ - _ _ _ _ _ _ _ M-left M-down M-right -) - -(deflayer level4 - _ M-f1 M-f2 M-f3 M-f4 M-f5 M-f6 M-f7 M-f8 M-f9 M-f10 M-f11 M-f12 - _ 1 2 3 4 5 6 7 8 9 0 - = _ - _ pgup bspc up del pgdn lrld 7 8 9 + - rctl - lalt home lft down rght end _ 4 5 6 , . ralt M-ret - lsft ✗ esc tab ins ret f1 S-. 1 2 3 ; _ _ - _ _ _ _ 0 ✗ _ _ _ _ -) - -(deflayer alt - _ A-c A-t A-i A-e A-o A-b A-n A-r A-s A-g A-q @lv3 ret - _ _ _ _ _ _ _ _ _ _ _ _ _ - A-grv 1 2 3 4 5 6 7 8 9 0 - = _ - A-tab A-j A-d A-u A-a A-x A-p h A-l A-m A-w _ rctl - _ _ A-f A-v A-u A-a A-o A-y A-z A-, A-. A-k @lv4 _ - _ lctl @alt lmet spc @lv4 ralt _ _ _ -) - - -(defalias - 😀 (🔣 😀) - 🙁 (unicode 🙁) -) -(deflayer smileys - _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ @😀 _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ -) -(deflayer second_function - _ 🔅 🔆 _ _ bldn blup ◀◀ ▶⏸ ▶▶ 🔇 🔈− 🔈+ - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ _ _ _ - _ _ _ _ _ _ _ _ _ _ -) - -(defalias - fn (layer-while-held second_function) - lv3 (layer-while-held level3) - lv4 (layer-while-held level4) - alt (layer-while-held alt) - sml (layer-while-held smileys) - osf (one-shot-press 2000 lsft) -) - -;;(defseq git-status (g s t)) -;;(deffakekeys git-status (macro g i t spc s t a t u s)) -;;(defalias dot-sequence (macro (sequence 250) 10 .)) -;;(defalias dot-sequence-inputmode (macro (sequence 250 hidden-delay-type) 10 .)) -;; -;;(defseq -;; dotcom (. S-3) -;; dotorg (. S-4) -;;) -;;(deffakekeys -;; dotcom (macro . c o m) -;; dotorg (macro . o r g) -;;) -;;;; There are special keys that you can assign in your actions which will -;;;; never output events to your operating system, but which you can use -;;;; in sequences. They are named: nop0-nop9. -;;(defseq -;; dotcom (nop0 nop1) -;; dotorg (nop8 nop9) -;;) -;;;; A key list within O-(...) signifies simultaneous presses. -;;(defseq -;; dotcom (O-(. c m)) -;; dotorg (O-(. r g)) -;;) - -(defalias unused (switch ((key-timing 1 gt 200)) 0 break)) - -(defchordsv2-experimental - - (include /Users/martin/Workspaces/devtools/kanata/cfg_samples/chords.txt) () 50 all-released () - (x r i) (macro v (t! rls-sft) a l i d a t sldr nop1 e spc nop0) 200 first-release () - (x r i w) (macro v (t! rls-sft) a l i d sldr spc nop0) 200 first-release () - (x i w) (macro v (t! rls-sft) a l i d spc nop0) 200 first-release () - -) -;;(include chords.kbd) - -(t! seq Monday (d a y spc nop0 O-(o g j)) (macro S-m $rls-sft o n d a y nop9 sldr spc nop0)) -(t! seq Tuesday (d a y spc nop0 O-(t u e)) (macro S-t $rls-sft u e s d a y nop9 sldr spc nop0)) -(t! seq DelSpace_. (spc nop0 .) (macro . spc)) -(t! seq DelSpace_, (spc nop0 ,) (macro , spc)) -(t! seq DelSpace_? (spc nop0 S-ß) (macro S-ß spc)) -(t! seq DelSpace_; (spc nop0 ;) (macro ;)) -(t! seq ion (nop1 e spc nop0 O-(d g w)) (macro i o n spc nop0)) -(t! seq ion2 (spc nop0 O-(d g w)) (macro i o n spc nop0)) -(t! seq ion3 (spc nop0 O-(. ,)) (macro i o n spc nop0)) diff --git a/cfg_samples/chords.kbd b/cfg_samples/chords.kbd deleted file mode 100644 index a04893a35..000000000 --- a/cfg_samples/chords.kbd +++ /dev/null @@ -1,155 +0,0 @@ -(defchordsv2-experimental - (w r n) (macro d (t! rls-sft) a y spc nop0) 200 first-release () ;; - (h l o) (macro h (t! rls-sft) e l l o sldr spc nop0) 200 first-release () - ;;include input_chords.txt 50 all-released () - (w f z) (macro d e f spc) 50 all-released () ;; - (l y r k) (macro s p a r k) 50 all-released () ;; - (d a u) (macro i c h spc) 50 all-released () ;; - (p d k) (macro w i r spc) 50 all-released () ;; - (; i r e h) (macro g l a u b spc) 50 all-released () ;; - (f l) (macro e s spc) 50 all-released () ;; - (d l s) (macro i s t spc) 50 all-released () ;; - (w r l) (macro d a s spc) 50 all-released () ;; - (spc w r l) (macro d a s s spc) 50 all-released () ;; - (j d a f) (macro n i c e spc) 50 all-released () ;; - (m g e) (macro z o u spc) 50 all-released () ;; - (s u) (macro t h e) 50 all-released () ;; - (spc r) (macro a) 50 all-released () ;; - (spc r j) (macro a n) 50 all-released () ;; - (r j) (macro a n d spc) 50 all-released () ;; - (r l) (macro a s spc) 50 all-released () ;; - (g k) (macro o r spc) 50 all-released () ;; - (h e) (macro b u t spc) 50 all-released () ;; - (d z) (macro i f spc) 50 all-released () ;; - (l g) (macro s o spc) 50 all-released () ;; - (w j) (macro t h e n spc) 50 all-released () ;; - (h a) (macro b e c a u s e spc) 50 all-released () ;; - (s g) (macro t o spc) 50 all-released () ;; - (g z) (macro o f spc) 50 all-released () ;; - (d j) (macro i n spc) 50 all-released () ;; - (spc z) (macro f o r spc) 50 all-released () ;; - (spc p) (macro w i t h spc) 50 all-released () ;; - ;;(g j) (macro o n spc) 50 all-released () ;; - (r s) (macro a t spc) 50 all-released () ;; - (z o) (macro f r o m spc) 50 all-released () ;; - (h m) (macro b z spc) 50 all-released () ;; - (r h) (macro a b o u t spc) 50 all-released () ;; - (e y) (macro u p spc) 50 all-released () ;; - (d g) (macro i n t o spc) 50 all-released () ;; - (g x) (macro o v e r spc) 50 all-released () ;; - (r z) (macro a f t e r spc) 50 all-released () ;; - (p g) (macro w i t h o u t spc) 50 all-released () ;; - (spc d) (macro S-i spc) 50 all-released () ;; - (spc o f) (macro m e spc) 50 all-released () ;; - (spc o k) (macro m z spc) 50 all-released () ;; - (g e) (macro z o u spc) 50 all-released () ;; - (e k) (macro z o u r spc) 50 all-released () ;; - (u f) (macro h e spc) 50 all-released () ;; - (u o) (macro h i m spc) 50 all-released () ;; - (u d l) (macro h i s spc) 50 all-released () ;; - (l u) (macro s h e spc) 50 all-released () ;; - (u k) (macro h e r spc) 50 all-released () ;; - (d s) (macro i t spc) 50 all-released () ;; - (s l) (macro i t s spc) 50 all-released () ;; - (p f) (macro w e spc) 50 all-released () ;; - (e l) (macro u s spc) 50 all-released () ;; - (g e k) (macro o u r spc) 50 all-released () ;; - (w m) (macro t h e z spc) 50 all-released () ;; - (w k) (macro t h e i r spc) 50 all-released () ;; - (w o) (macro t h e m spc) 50 all-released () ;; - (p a) (macro w h i c h spc) 50 all-released () ;; - (p j) (macro w h e n spc) 50 all-released () ;; - (p s) (macro w h a t spc) 50 all-released () ;; - (p k) (macro w h e r e spc) 50 all-released () ;; - (u g) (macro w h o spc) 50 all-released () ;; - (u p) (macro h o w spc) 50 all-released () ;; - (p m) (macro w h z spc) 50 all-released () ;; - (d l) (macro i s spc) 50 all-released () ;; - (r k) (macro a r e spc) 50 all-released () ;; - (p r) (macro w a s spc) 50 all-released () ;; - (f k) (macro w e r e spc) 50 all-released () ;; - (h f) (macro b e spc) 50 all-released () ;; - (u x) (macro h a v e spc) 50 all-released () ;; - (u n) (macro h a s spc) 50 all-released () ;; - (u w) (macro h a d spc) 50 all-released () ;; - (j s) (macro n o t spc) 50 all-released () ;; - (a j) (macro c a n spc) 50 all-released () ;; - (w g) (macro d o spc) 50 all-released () ;; - (p i) (macro w i l l spc) 50 all-released () ;; - (a w) (macro c o u l d spc) 50 all-released () ;; - (p w) (macro w o u l d spc) 50 all-released () ;; - (l w) (macro s h o u l d spc) 50 all-released () ;; - (i d) (macro l i k e spc) 50 all-released () ;; - (h j) (macro b e e n spc) 50 all-released () ;; - (; f) (macro g e t spc) 50 all-released () ;; - (o r m) (macro m a z spc) 50 all-released () ;; - (o r w) (macro m a d e spc) 50 all-released () ;; - (o /) (macro m a k e spc) 50 all-released () ;; - (r d) (macro s a i d spc) 50 all-released () ;; - (p /) (macro w o r k spc) 50 all-released () ;; - (e n) (macro u s e spc) 50 all-released () ;; - (l m) (macro s a z spc) 50 all-released () ;; - (spc ;) (macro g o spc) 50 all-released () ;; - (/ j) (macro k n o w spc) 50 all-released () ;; - (s /) (macro t a k e spc) 50 all-released () ;; - (spc l f) (macro s e e spc) 50 all-released () ;; - (i /) (macro l o o k spc) 50 all-released () ;; - (a o) (macro c o m e spc) 50 all-released () ;; - (s u /) (macro t h i n k spc) 50 all-released () ;; - (p j s) (macro w a n t spc) 50 all-released () ;; - (; d) (macro g i v e spc) 50 all-released () ;; - (a s) (macro c a n n o t spc) 50 all-released () ;; - (w f) (macro d o e s spc) 50 all-released () ;; - (w d) (macro d i d spc) 50 all-released () ;; - (l f o) (macro s e e m spc) 50 all-released () ;; - (a i) (macro c a l l spc) 50 all-released () ;; - (s u r) (macro t h a n k spc) 50 all-released () ;; - (spc d o) (macro S-i ' m spc) 50 all-released () ;; - (w s) (macro t h a t spc) 50 all-released () ;; - (w d l) (macro t h i s spc) 50 all-released () ;; - (w f l) (macro t h e s e spc) 50 all-released () ;; - (r i) (macro a l l spc) 50 all-released () ;; - (spc g) (macro o n e spc) 50 all-released () ;; - (o g) (macro m o r e spc) 50 all-released () ;; - (s u f) (macro t h e r e spc) 50 all-released () ;; - (g e s) (macro o u t spc) 50 all-released () ;; - (r g) (macro a l s o spc) 50 all-released () ;; - (s o) (macro t i m e spc) 50 all-released () ;; - (l o) (macro s o m e spc) 50 all-released () ;; - (q l) (macro j u s t spc) 50 all-released () ;; - (j f) (macro n e w spc) 50 all-released () ;; - (g w k) (macro o t h e r spc) 50 all-released () ;; - (y i) (macro p e o p l e spc) 50 all-released () ;; - (spc j) (macro n o spc) 50 all-released () ;; - (w r j) (macro t h a n spc) 50 all-released () ;; - (g m) (macro o n l z spc) 50 all-released () ;; - (spc o) (macro m o s t spc) 50 all-released () ;; - (r m) (macro a n z spc) 50 all-released () ;; - (o r) (macro m a n z spc) 50 all-released () ;; - (f i) (macro w e l l spc) 50 all-released () ;; - (z l) (macro f i r s t spc) 50 all-released () ;; - (x m) (macro v e r z spc) 50 all-released () ;; - (j g p) (macro n o w spc) 50 all-released () ;; - (f x) (macro e v e n spc) 50 all-released () ;; - (; g) (macro g o o d spc) 50 all-released () ;; - (; k s) (macro g r e a t spc) 50 all-released () ;; - (p r m) (macro w a z spc) 50 all-released () ;; - (spc s) (macro t w o spc) 50 all-released () ;; - (m k) (macro z e a r spc) 50 all-released () ;; - (h /) (macro b a c k spc) 50 all-released () ;; - (' j) (macro q u e s t i o n spc) 50 all-released () ;; - (l a) (macro s e c o n d spc) 50 all-released () ;; - (w ;) (macro t h i n g spc) 50 all-released () ;; - (spc m) (macro z e s spc) 50 all-released () ;; - (a j v) (macro c a n ' t spc) 50 all-released () ;; - (w d z) (macro d i f f e r e n t spc) 50 all-released () ;; - (w ; u) (macro t h o u g h spc) 50 all-released () ;; - (s k e) (macro t h r o u g h spc) 50 all-released () ;; - (l k) (macro s o r r z spc) 50 all-released () ;; - (o x) (macro m o v e spc) 50 all-released () ;; - (w d k) (macro d i r e c t i o n spc) 50 all-released () ;; - (j t) (macro n e x t spc) 50 all-released () ;; - (l r o) (macro s a m e spc) 50 all-released () ;; - (s y) (macro t o p spc) 50 all-released () ;; - ;;(o g j) (macro m o n t h spc) 50 all-released () ;; -) diff --git a/cfg_samples/chords.txt b/cfg_samples/chords.tsv similarity index 64% rename from cfg_samples/chords.txt rename to cfg_samples/chords.tsv index 4532d8136..8805591bd 100644 --- a/cfg_samples/chords.txt +++ b/cfg_samples/chords.tsv @@ -1,52 +1,12 @@ -def def -spar spark -ich ich -wir wir -glaub glaub -es es -ist ist -das das - das dass -geht geht -ha hab -wird wird -sich sich -scho schon -noc noch -imer immer -nict nicht -abr aber -der der -die die -bei bei -kan kann -mal mal -wied wieder -yiem ziemlich -ab ab -am am -yu zu -sind sind -etw etwas +rus rust col cool nice nice -zou you +you you th the a a an an -mr martin -mauch mauch -gml gmail.com -dew dev -mein mein - mein meine -und und -ome komme -aus aus -mntr mintraching -scal scala - -nam name +man man +name name an and as as or or @@ -71,9 +31,9 @@ io into ov over af after wo without - i i + i I me me - mr my + my my ou you ur your he he @@ -137,8 +97,8 @@ sem seem cl call tha thank - im i'm - id i'd + im I'm + id I'd dt that dis this des these @@ -159,26 +119,25 @@ pl people dan than oz only m most -az any +ay any may many el well fs first -vz very +vy very much much now now ev even go good grt great -waz way +way way t two -zr year +yr year bk back -da da -daz day +day day qn question sc second dg thing - z yes + y yes cn' can't dif different dgh though @@ -192,22 +151,42 @@ nx next sam same tp top cod code -wo wo -wan wann git git to TODO - war war cls class clus cluster -zok zookeeper -gut gut -hst hast -du du -kno know -bin bin -war war -vor vor -suer super -lang lang -lange lange -lnge lange +sure sure +lets let's +sup super +such such +thig thing +yet yet +don done +sem seem +ran ran +job job +bot bot +fx effect +nce once +rad read +ltr later +lot lot +brw brew +unst uninstall +rmv remove + ad add +poe problem +buld build + tol tool +got got +les less + 0 zero + 1 one + 2 two + 3 three + 4 four + 5 five + 6 six + 7 seven + 8 eight + 9 nine diff --git a/cfg_samples/kanata.kbd b/cfg_samples/kanata.kbd index 2d53cfef2..1003b5006 100644 --- a/cfg_samples/kanata.kbd +++ b/cfg_samples/kanata.kbd @@ -224,6 +224,8 @@ If you need help, please feel welcome to ask in the GitHub discussions. ;; tap-hold onwards will start from 0ms after the previous tap-hold expires. ;; concurrent-tap-hold yes + chords-v2-min-idle-experimental 200 + sequence-input-mode visible-backspaced ;; This configuration makes the release of one-shot-press and of the tap in a tap-hold ;; by the defined number of milliseconds (approximate). @@ -1275,8 +1277,27 @@ Syntax (5-tuples): |# (defchordsv2-experimental - (include cfg_samples/chords.txt) () 200 all-released (arrows) + (include cfg_samples/chords.tsv) () 200 all-released (arrows) (a b) c 200 all-released (arrows) - (a b z) (macro S-h e l l o) 250 first-release (arrows) + (a b z) (macro h e l l o) 250 first-release (arrows) (a b z y) (macro b y e) 400 first-release (arrows) ) + +(deftemplate seq (vk-name in out) + (defvirtualkeys $vk-name $out) + (defseq $vk-name $in)) + +(defvirtualkeys rls-sft (multi (release-key lsft)(release-key rsft))) +(defvar rls-sft (on-press tap-vkey rls-sft)) +(deftemplate rls-sft () $rls-sft 5) + +(t! seq Monday (d a y spc nop0 1) (macro S-m $rls-sft o n d a y nop9 sldr spc nop0)) +(t! seq Tuesday (d a y spc nop0 2) (macro S-t $rls-sft u e s d a y nop9 sldr spc nop0)) +(t! seq DelSpace_. (spc nop0 .) (macro . spc)) +(t! seq DelSpace_, (spc nop0 ,) (macro , spc)) +(t! seq DelSpace_? (spc nop0 S-/) (macro S-/ spc)) +(t! seq DelSpace_; (spc nop0 ;) (macro ;)) +(t! seq DelSpace_' (spc nop0 ') (macro ' s spc)) +(t! seq DelSpace_- (spc nop0 -) (macro -)) +(t! seq DelSpace_s (spc nop0 s) (macro s spc)) + diff --git a/cfg_samples/new_chording.kbd b/cfg_samples/new_chording.kbd deleted file mode 100644 index 83da2e168..000000000 --- a/cfg_samples/new_chording.kbd +++ /dev/null @@ -1,17 +0,0 @@ -(defsrc f1) -(deflayer base lrld) -(defcfg process-unmapped-keys yes - sequence-input-mode visible-backspaced - concurrent-tap-hold true) -(deftemplate seq (vk-name in out) - (defvirtualkeys $vk-name $out) - (defseq $vk-name $in)) - -(defchordsv2-experimental - (d a y) (macro sldr d (unshift a y) spc nop0) 200 first-release () - (h l o) (macro h (unshift e l) 5 (unshift l o) sldr spc nop0) 200 first-release () -) -(t! seq Monday (d a y spc nop0 O-(m o n)) (macro S-m (unshift o n d a y) nop9 sldr spc nop0)) -(t! seq Tuesday (d a y spc nop0 O-(t u e)) (macro S-t (unshift u e s d a y) nop9 sldr spc nop0)) -(t! seq DelSpace_. (spc nop0 .) (macro .)) -(t! seq DelSpace_; (spc nop0 ;) (macro ;)) diff --git a/cfg_samples/new_chording_2.kbd b/cfg_samples/new_chording_2.kbd deleted file mode 100644 index cc8a54312..000000000 --- a/cfg_samples/new_chording_2.kbd +++ /dev/null @@ -1,22 +0,0 @@ -(defsrc f1) -(deflayer base lrld) -(defcfg process-unmapped-keys yes - sequence-input-mode visible-backspaced - concurrent-tap-hold true) -(deftemplate seq (vk-name in out) - (defvirtualkeys $vk-name $out) - (defseq $vk-name $in)) - -(defvirtualkeys rls-sft (multi (release-key lsft)(release-key rsft))) -(defvar rls-sft (on-press tap-vkey rls-sft)) -(deftemplate rls-sft () $rls-sft 5) - -(defchordsv2-experimental - (d a y) (macro sldr d (t! rls-sft) a y spc nop0) 200 first-release () - (h l o) (macro h (t! rls-sft) e l l o sldr spc nop0) 200 first-release () - (h l i) (macro h e l l i) 200 first-release () -) -(t! seq Monday (d a y spc nop0 O-(m o n)) (macro S-m $rls-sft o n d a y nop9 sldr spc nop0)) -(t! seq Tuesday (d a y spc nop0 O-(t u e)) (macro S-t $rls-sft u e s d a y nop9 sldr spc nop0)) -(t! seq DelSpace_. (spc nop0 .) (macro .)) -(t! seq DelSpace_; (spc nop0 ;) (macro ;)) diff --git a/cfg_samples/new_chording_3.kbd b/cfg_samples/new_chording_3.kbd deleted file mode 100644 index ca7869fad..000000000 --- a/cfg_samples/new_chording_3.kbd +++ /dev/null @@ -1,21 +0,0 @@ -(defsrc f1) -(deflayer base lrld) -(defcfg process-unmapped-keys yes - sequence-input-mode visible-backspaced - concurrent-tap-hold true) -(deftemplate seq (vk-name in out) - (defvirtualkeys $vk-name $out) - (defseq $vk-name $in)) - -(defvirtualkeys rls-sft (multi (release-key lsft)(release-key rsft))) -(defvar rls-sft (on-press tap-vkey rls-sft)) -(deftemplate rls-sft () $rls-sft 5) - -(defchordsv2-experimental - (d a y) (macro sldr d (t! rls-sft) a y spc nop0) 200 first-release () - (h l o) (macro h (t! rls-sft) e l l o sldr spc nop0) 200 first-release () -) -(t! seq Monday (d a y spc nop0 O-(m o n)) (macro S-m $rls-sft o n d a y nop9 sldr spc nop0)) -(t! seq Tuesday (d a y spc nop0 O-(t u e)) (macro S-t $rls-sft u e s d a y nop9 sldr spc nop0)) -(t! seq DelSpace_. (spc nop0 .) (macro .)) -(t! seq DelSpace_; (spc nop0 ;) (macro ;)) diff --git a/parser/src/cfg/chord.rs b/parser/src/cfg/chord.rs index be285d195..e294fc75b 100644 --- a/parser/src/cfg/chord.rs +++ b/parser/src/cfg/chord.rs @@ -72,7 +72,8 @@ pub(crate) fn parse_defchordv2( .into_iter() .chain(vec![(" ".to_string(), "spc".to_string())].into_iter()) .collect::>(); - let chord_definitions = parse_chord_file(chunk, s).unwrap(); + let file_name = chunk[0].list(s.vars()).unwrap()[1].atom(s.vars()).unwrap(); + let chord_definitions = parse_chord_file(file_name, s).unwrap(); let processed = chord_definitions.iter().map(|chord_def| { let participating_keys = chord_def .keys @@ -90,14 +91,18 @@ pub(crate) fn parse_defchordv2( .map(|c| process(&c.to_string())) .collect_vec(); chars.insert(1, "50".to_string()); - - chars.extend_from_slice(&["sldr".to_string(), "spc".to_string(), "nop0".to_string()]); + + chars.extend_from_slice(&[ + "sldr".to_string(), + "spc".to_string(), + "nop0".to_string(), + ]); let sexpr_string = format!( "(({}) (macro {}))", participating_keys.join(" "), chars.join(" ") ); - let parsed = sexpr::parse(&sexpr_string, "foo").unwrap(); + let parsed = sexpr::parse(&sexpr_string, file_name).unwrap(); let appendix = vec![chunk[2].clone(), chunk[3].clone(), chunk[4].clone()]; let combined = [parsed[0].t.clone(), appendix].concat(); let chunk = combined.as_slice(); @@ -256,8 +261,7 @@ fn parse_disabled_layers(disabled_layers: &SExpr, s: &ParserState) -> Result(chunk: &'a [SExpr], s: &'a ParserState) -> Result> { - let file_name = chunk[0].list(s.vars()).unwrap()[1].atom(s.vars()).unwrap(); +fn parse_chord_file<'a>(file_name: &str, s: &'a ParserState) -> Result> { let input_data = fs::read_to_string(file_name).expect(format!("Unable to read file {}", file_name).as_str()); let parsed_chords = parse_input(&input_data); @@ -281,8 +285,6 @@ fn parse_input(input: &str) -> Vec { .collect() } - - #[derive(Debug)] struct ChordDefinition { keys: String, diff --git a/src/transform_chords.rs b/src/transform_chords.rs deleted file mode 100644 index fd70fa23c..000000000 --- a/src/transform_chords.rs +++ /dev/null @@ -1,150 +0,0 @@ -use kanata_parser::cfg::{self, Cfg, MResult}; -use kanata_state_machine::OsCode; -use regex::Regex; -use std::collections::HashMap; -use std::fs; -use std::path::Path; - -fn parse_kbd_file(file_path: &str) -> MResult { - let path = Path::new(file_path); - return cfg::new_from_file(path); -} -fn main() { - let input_data = fs::read_to_string("cfg_samples/chords.txt").expect("Unable to read file"); - let parsed_config = - parse_kbd_file("cfg_samples/bone_mac.kbd").expect("Unable to parse kbd file"); - - let target_map = parsed_config.layout.b().layers[0][0] - .iter() - .enumerate() - .filter_map(|(idx, layout)| { - layout - .key_codes() - .next() - .map(|kc| kc.to_string().to_lowercase()) - .zip( - idx.try_into() - .ok() - .and_then(|num| OsCode::from_u16(num)) - .map(|osc| osc.to_string().to_lowercase()), - ) - }) - .collect::>() - .into_iter() - .chain(vec![(" ".to_string(), "spc".to_string())].into_iter()) - .collect::>(); - println!("{:?}", target_map); - let parsed_chords = parse_input(&input_data); - println!("{:?}", parsed_chords); - let mapped_chords = map_to_physical_keys(parsed_chords, target_map); - println!("{:?}", mapped_chords); - let output = generate_defchordsv2_experimental(mapped_chords); - fs::write("cfg_samples/chords.kbd", output).expect("Unable to write file"); -} - -fn parse_input(input: &str) -> Vec { - let re = Regex::new(r"^( ?[^\t]+)\t([^\t]+)(?:\t([^\t]*))?$").unwrap(); - input - .lines() - .filter(|line| !line.trim().is_empty() && !line.trim().starts_with("//")) - .filter_map(|line| { - re.captures(line).map(|caps| { - let keys = caps - .get(1) - .unwrap() - .as_str() - .chars() - .map(|k| k.to_string()) - .collect::>(); - let action = caps - .get(2) - .unwrap() - .as_str() - .chars() - .map(|k| k.to_string()) - .collect::>(); - let comment = caps - .get(3) - .map_or(String::new(), |m| m.as_str().trim().to_string()); - ChordDefinition { - keys, - action, - comment, - } - }) - }) - .collect() -} - -fn map_to_physical_keys( - chords: Vec, - key_map: HashMap, -) -> Vec { - let postprocess_map: HashMap = [ - ("semicolon", ";"), - ("slash", "/"), - ("apostrophe", "'") - ].iter().cloned().map(|(k, v)| (k.to_string(), v.to_string())).collect(); - let output_key_map: HashMap = [ - ("y", "z"), - ("z", "y"), - (" ", "spc") - ] - .iter() - .cloned() - .map(|(k, v)| (k.to_string(), v.to_string())) - .collect(); - chords - .into_iter() - .map(|chord| { - let keys = chord - .keys - .iter() - .map(|key| key_map.get(key).unwrap_or(key).clone()) - .map(|key| postprocess_map.get(&key).unwrap_or(&key).clone()) - .collect::>(); - let macro_text = chord - .action - .iter() - .map(|key| if key.chars().next().map_or(false, |c| c.is_uppercase()) { "S-".to_string() + &key.to_lowercase() } else { key.clone() }) - .map(|key| output_key_map.get(&key).unwrap_or(&key).clone()) - .collect::>(); - PhysicalChord { - keys, - macro_text, - comment: chord.comment, - } - }) - .collect() -} - -fn generate_defchordsv2_experimental(chords: Vec) -> String { - let mut output = String::from("(defchordsv2-experimental\n"); - for chord in chords { - let keys_str = chord.keys.join(" "); - output.push_str(&format!( - " ({}) (macro {}) 100 all-released () ;; {}\n", - keys_str, - chord.macro_text.join(" "), - chord.comment - )); - } - output.push_str(")\n"); - output -} - -// Define necessary data structures - -#[derive(Debug)] -struct ChordDefinition { - keys: Vec, - action: Vec, - comment: String, // Optional comment field -} - -#[derive(Debug)] -struct PhysicalChord { - keys: Vec, - macro_text: Vec, - comment: String, // Optional comment field -}