aboutsummaryrefslogtreecommitdiffstats
path: root/oni/kbd.scm
blob: f6956f43453e0d095441feda0861ad793b4a16c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 (λ (key previous)
                   (if (null? previous)
                       (list (convert-key key))
                       (cons (convert-modifier key) previous)))
                 '() parts)
     "-")))