From 1f6ebbcfacbcbe91f4e329319884cbc060c94c90 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 4 Jun 2023 03:35:03 -0500 Subject: [PATCH] Basic support for key layouts Adds a small layer for translating input characters from non-QWERTY keyboard layouts into their QWERTY counterparts. After all, it's not the WASD that counts, but the position: ,AOE is just as valid! --- flora-search-aurora.lisp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index f38c1b7..f47bc14 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -103,6 +103,42 @@ with 15 characters-per-line." 32))) +(defvar +qwerty-layout+ + '(#\q #\Q #\w #\W #\e #\E #\r #\R #\t #\T #\y #\Y #\u #\U #\i #\I #\o #\O #\p #\P #\[ #\{ #\] #\} + #\a #\A #\s #\S #\d #\D #\f #\F #\g #\G #\h #\H #\j #\J #\k #\K #\l #\L #\; #\: #\' #\" + #\z #\Z #\x #\X #\c #\C #\v #\V #\b #\B #\n #\N #\m #\M #\, #\< #\. #\> #\/ #\?)) + +(defvar +dvorak-layout+ + '(#\' #\" #\, #\< #\. #\> #\p #\P #\y #\Y #\f #\F #\g #\G #\c #\C #\r #\R #\l #\L #\/ #\? #\= #\+ + #\a #\A #\o #\O #\e #\E #\u #\U #\i #\I #\d #\D #\h #\H #\t #\T #\n #\N #\s #\S #\- #\_ + #\; #\: #\q #\Q #\j #\J #\k #\K #\x #\X #\b #\B #\m #\M #\w #\W #\v #\V #\z #\Z)) + + +(defun parallel-list-item (item-a list-a list-b &key (test #'eql)) + "Given two parallel lists and an item contained in the first list, return its +corresponding item in the other list, by index." + (let ((index (position item-a list-a :test test))) + (if index + (nth index list-b)))) + + +(defun normalize-char (char-plist &optional (layout +qwerty-layout+)) + "Given a character input property list (as received from read-char-plist), +massage the output into parsable, deescaped, QWERTY-according format." + (let ((normalized (deescape-char-plist char-plist))) + (setf (getf normalized :char) + (qwertyize-char (getf normalized :char) + layout)) + normalized)) + + +(defun qwertyize-char (char layout) + "Given a char input in some layout, return the corresponding character in QWERTY. +Not at all comprehensive, but probably-mostly-just-good-enough. ¯\_ (ツ)_/¯" + (or (parallel-list-item char layout +qwerty-layout+) + char)) + + (defun deescape-char-plist (char-plist) "Translate escaped characters into somewhat-semantically-adjacent characters, like left arrow-key (escaped D) into ← (“LEFTWARDS ARROW”)."