handling ^C in the repl reader to cancel the current input

This commit is contained in:
Alex Shinn 2011-10-30 18:16:33 +09:00
parent 4f9a5d7245
commit e08c0eac45
2 changed files with 12 additions and 4 deletions

View file

@ -241,7 +241,7 @@
;;> needed for a terminal application. ;;> needed for a terminal application.
(define (with-raw-io port thunk) (define (with-raw-io port thunk)
(with-stty '(not icanon echo) thunk port)) (with-stty '(not icanon isig echo) thunk port))
;;> Returns the current terminal width in characters of @var{x}, ;;> Returns the current terminal width in characters of @var{x},
;;> which must be a port or a file descriptor. ;;> which must be a port or a file descriptor.

View file

@ -336,6 +336,7 @@
(v (car keymap))) (v (car keymap)))
(vector-set! v 1 command/beggining-of-line) (vector-set! v 1 command/beggining-of-line)
(vector-set! v 2 command/backward-char) (vector-set! v 2 command/backward-char)
(vector-set! v 3 command/cancel)
(vector-set! v 4 command/forward-delete-char) (vector-set! v 4 command/forward-delete-char)
(vector-set! v 5 command/end-of-line) (vector-set! v 5 command/end-of-line)
(vector-set! v 6 command/forward-char) (vector-set! v 6 command/forward-char)
@ -377,6 +378,13 @@
(else (else
(command/self-insert ch buf out return))))) (command/self-insert ch buf out return)))))
(define (command/cancel ch buf out return)
(command/end-of-line ch buf out return)
(display "^C" out)
(newline out)
(buffer-delete! buf out 0 (buffer-length buf))
(buffer-draw buf out))
(define (command/beep ch buf out return) (define (command/beep ch buf out return)
(write-char (integer->char 7) out)) (write-char (integer->char 7) out))