aboutsummaryrefslogtreecommitdiffstats
path: root/oni/kbd.scm
diff options
context:
space:
mode:
Diffstat (limited to 'oni/kbd.scm')
-rw-r--r--oni/kbd.scm29
1 files changed, 29 insertions, 0 deletions
diff --git a/oni/kbd.scm b/oni/kbd.scm
new file mode 100644
index 0000000..eb7f8d7
--- /dev/null
+++ b/oni/kbd.scm
@@ -0,0 +1,29 @@
+(define-module (oni kbd)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
+
+ #:export (kbd))
+
+(define (convert-modifier mod)
+ (match mod
+ ("C" "Ctrl")
+ ("M" "Mod1")
+ ("S" "Shift")
+ ("s" "Mod4")))
+
+(define (convert-key key)
+ (match key
+ ("RET" "Return")
+ ("SPC" "space")
+ ("<backspace>" "BackSpace")
+ (_ key)))
+
+(define (kbd str)
+ (let ((parts (string-split str #\-)))
+ (string-join
+ (fold-right (lambda (key previous)
+ (if (null? previous)
+ (list (convert-key key))
+ (cons (convert-modifier key) previous)))
+ '() parts)
+ "-")))