(declare-keys
  command
  ('escape (red/set-top-mode 'normal))
  ('backspace
   (if _red/current-command
     (red/command/erase-backward!)
     (red/set-top-mode 'normal)
     ))
  ('newline
   (let (command _red/current-command)
     (red/command/clear!)
     (_red/root-command-hook command)
     )
   )
  :fallback
  (key-seq)
  (_red/command-mode-handler key-seq)
  )

(defun _red/command-mode-handler
  (key-seq)
  (let (insertable (red/as-insertable-key-seq key-seq))
    (unless (nil? insertable)
      (red/command/append! insertable))))
