A Common Lisper walks into a Schemer bar and says
This commit is contained in:
parent
976a1b137d
commit
8a3c3b1aca
|
@ -5,18 +5,18 @@
|
|||
#:use-module (ice-9 textual-ports)
|
||||
#:export (start-loop))
|
||||
|
||||
(define modes '(#:normal-mode #:insert-mode))
|
||||
(define modes '(normal-mode insert-mode))
|
||||
|
||||
(define* (start-loop #:key (win (init-win))
|
||||
(file #f))
|
||||
(if file (find-file win file))
|
||||
(core-loop win))
|
||||
|
||||
(define* (core-loop win #:optional (mode #:normal-mode))
|
||||
(define* (core-loop win #:optional (mode 'normal-mode))
|
||||
(define process-result
|
||||
(case mode
|
||||
((#:normal-mode) (normal-mode-process-input win (getch win)))
|
||||
((#:insert-mode) (insert-mode-process-input win (getch win)))))
|
||||
((normal-mode) (normal-mode-process-input win (getch win)))
|
||||
((insert-mode) (insert-mode-process-input win (getch win)))))
|
||||
(if (memq process-result modes)
|
||||
(core-loop win process-result)
|
||||
(core-loop win mode)))
|
||||
|
@ -37,7 +37,7 @@
|
|||
(move win (- y 1) x))
|
||||
((eqv? key KEY_DOWN)
|
||||
(move win (+ y 1) x))
|
||||
((eqv? key #\esc) #:normal-mode)
|
||||
((eqv? key #\esc) 'normal-mode)
|
||||
(else (insch win (normal key) #:y y #:x (+ x 1)))))
|
||||
|
||||
(define (normal-mode-process-input win key)
|
||||
|
@ -52,7 +52,7 @@
|
|||
(move win (- y 1) x))
|
||||
((eqv? key KEY_DOWN)
|
||||
(move win (+ y 1) x))
|
||||
((eqv? key #\i) #:insert-mode)
|
||||
((eqv? key #\i) 'insert-mode)
|
||||
((eqv? key #\q)
|
||||
(endwin)
|
||||
(quit))))
|
||||
|
@ -60,4 +60,5 @@
|
|||
(define (find-file win file)
|
||||
(when (file-exists? file)
|
||||
(addstr win (call-with-input-file file get-string-all))
|
||||
(refresh win)))
|
||||
(refresh win)
|
||||
(move win 0 0)))
|
||||
|
|
Loading…
Reference in New Issue