From f5c808e10a3fafb23496bf4a93a87f2d9a96b025 Mon Sep 17 00:00:00 2001 From: eknauel Date: Tue, 7 Jun 2005 19:50:43 +0000 Subject: [PATCH] Fix the "terminal emulation" for ascii codes cr and nl. Don't pass strings containing cr or nl to ncurses (leads to garbled output). --- scheme/termbuf.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scheme/termbuf.scm b/scheme/termbuf.scm index 5b4e546..5a2817c 100644 --- a/scheme/termbuf.scm +++ b/scheme/termbuf.scm @@ -1,3 +1,7 @@ +;; turn off debugging for the moment +(define debug-message + (lambda args #f)) + (define-record-type terminal-buffer :terminal-buffer (really-make-terminal-buffer width height view-index x y buffer repaint? @@ -100,18 +104,20 @@ (set-terminal-buffer-x! termbuf 0)) (define (terminal-buffer-add-char termbuf char) - (debug-message "add-char " termbuf) + (debug-message "add-char " termbuf " '" char "' " + (char->ascii char)) (cond ((not (string=? "" (terminal-buffer-esc-code termbuf))) (read-escape-code termbuf char)) ((char=? char (ascii->char 27)) (set-terminal-buffer-esc-code! termbuf (string char))) + ((char=? char (ascii->char 13)) + (goto-beginning-of-line termbuf)) ((char=? char #\newline) (if (cursor-on-last-line? termbuf) (append-empty-line termbuf)) - (goto-next-line termbuf) - (goto-beginning-of-line termbuf)) - (else + (goto-next-line termbuf)) + ((char-set-contains? char-set:printing char) (add-normal-char termbuf char)))) (define (add-normal-char termbuf char) @@ -123,7 +129,10 @@ (insert-char termbuf char)) (else (insert-char termbuf char) - (goto-next-char termbuf)))) + (goto-next-char termbuf))) + (debug-message "add-normal-char " + (string-length (line-at-cursor-position termbuf)) + "'" (line-at-cursor-position termbuf) "'")) (define (curses-paint-terminal-buffer termbuf win) (if (terminal-buffer-repaint? termbuf) @@ -139,6 +148,7 @@ (if (zero? i) 'blorf (begin + (debug-message y ": '" (car lines) "'") (mvwaddstr win y 0 (car lines)) (lp (- i 1) (cdr lines) (+ y 1))))) (position-cursor termbuf win))