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)
|
#:use-module (ice-9 textual-ports)
|
||||||
#:export (start-loop))
|
#:export (start-loop))
|
||||||
|
|
||||||
(define modes '(#:normal-mode #:insert-mode))
|
(define modes '(normal-mode insert-mode))
|
||||||
|
|
||||||
(define* (start-loop #:key (win (init-win))
|
(define* (start-loop #:key (win (init-win))
|
||||||
(file #f))
|
(file #f))
|
||||||
(if file (find-file win file))
|
(if file (find-file win file))
|
||||||
(core-loop win))
|
(core-loop win))
|
||||||
|
|
||||||
(define* (core-loop win #:optional (mode #:normal-mode))
|
(define* (core-loop win #:optional (mode 'normal-mode))
|
||||||
(define process-result
|
(define process-result
|
||||||
(case mode
|
(case mode
|
||||||
((#:normal-mode) (normal-mode-process-input win (getch win)))
|
((normal-mode) (normal-mode-process-input win (getch win)))
|
||||||
((#:insert-mode) (insert-mode-process-input win (getch win)))))
|
((insert-mode) (insert-mode-process-input win (getch win)))))
|
||||||
(if (memq process-result modes)
|
(if (memq process-result modes)
|
||||||
(core-loop win process-result)
|
(core-loop win process-result)
|
||||||
(core-loop win mode)))
|
(core-loop win mode)))
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
(move win (- y 1) x))
|
(move win (- y 1) x))
|
||||||
((eqv? key KEY_DOWN)
|
((eqv? key KEY_DOWN)
|
||||||
(move win (+ y 1) x))
|
(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)))))
|
(else (insch win (normal key) #:y y #:x (+ x 1)))))
|
||||||
|
|
||||||
(define (normal-mode-process-input win key)
|
(define (normal-mode-process-input win key)
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
(move win (- y 1) x))
|
(move win (- y 1) x))
|
||||||
((eqv? key KEY_DOWN)
|
((eqv? key KEY_DOWN)
|
||||||
(move win (+ y 1) x))
|
(move win (+ y 1) x))
|
||||||
((eqv? key #\i) #:insert-mode)
|
((eqv? key #\i) 'insert-mode)
|
||||||
((eqv? key #\q)
|
((eqv? key #\q)
|
||||||
(endwin)
|
(endwin)
|
||||||
(quit))))
|
(quit))))
|
||||||
|
@ -60,4 +60,5 @@
|
||||||
(define (find-file win file)
|
(define (find-file win file)
|
||||||
(when (file-exists? file)
|
(when (file-exists? file)
|
||||||
(addstr win (call-with-input-file file get-string-all))
|
(addstr win (call-with-input-file file get-string-all))
|
||||||
(refresh win)))
|
(refresh win)
|
||||||
|
(move win 0 0)))
|
||||||
|
|
Loading…
Reference in New Issue