forked from jtroo/kanata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sequences): add
O-(...)
for any-order overlapping keys (jtroo#989
) Gets a lot of the way to jtroo#979, with the caveat that it is really quite inconvenient to configure. Perhaps an external parser can help. For example: - `defchords` can be used for basic single-chords - for composite/contextual chords, a `defchords` output action can trigger sequences, which themselves can use `O-(...)` for subsequent chords Example: ``` (defsrc f1) (deflayer base lrld) (defcfg process-unmapped-keys yes sequence-input-mode visible-backspaced concurrent-tap-hold true) (deftemplate seq (vk-name seq-keys action) (defseq $vk-name $seq-keys) (defvirtualkeys $vk-name $action)) (defvirtualkeys rls-sft (multi (release-key lsft)(release-key rsft))) (deftemplate rls-sft () (on-press tap-vkey 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 (t! 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 (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 ;)) ``` The configuration can write all of the below without having to manually add or backspace the spaces, and only using shift+chords+punctuation. ``` day; Day; day hello hello day Hello day hello Tuesday hello Monday Tuesday. Monday. ```
- Loading branch information
Showing
6 changed files
with
553 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Implements Heap's algorithm. | ||
/* | ||
From Wikipedia: | ||
procedure generate(k: integer, A : array of any): | ||
if k = 1 then | ||
output(A) | ||
else | ||
// Generate permutations with k-th unaltered | ||
// Initially k = length(A) | ||
generate(k - 1, A) | ||
// Generate permutations for k-th swapped with each k-1 initial | ||
for i := 0; i < k-1; i += 1 do | ||
// Swap choice dependent on parity of k (even or odd) | ||
if k is even then | ||
swap(A[i], A[k-1]) // zero-indexed, the k-th is at k-1 | ||
else | ||
swap(A[0], A[k-1]) | ||
end if | ||
generate(k - 1, A) | ||
end for | ||
end if | ||
*/ | ||
|
||
/// Heap's algorithm | ||
pub fn gen_permutations<T: Clone + Default>(a: &[T]) -> Vec<Vec<T>> { | ||
let mut a2 = vec![Default::default(); a.len()]; | ||
a2.clone_from_slice(a); | ||
let mut outs = vec![]; | ||
heaps_alg(a.len(), &mut a2, &mut outs); | ||
outs | ||
} | ||
|
||
fn heaps_alg<T: Clone>(k: usize, a: &mut [T], outs: &mut Vec<Vec<T>>) { | ||
if k == 1 { | ||
outs.push(a.to_vec()); | ||
} else { | ||
heaps_alg(k - 1, a, outs); | ||
for i in 0..k - 1 { | ||
if (k % 2) == 0 { | ||
a.swap(i, k - 1); | ||
} else { | ||
a.swap(0, k - 1); | ||
} | ||
heaps_alg(k - 1, a, outs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.