The strategy is now to write in display memory changes done by erase and then displaying the line. Pull out common functionality of ED and EL in a function called nterm-vt100-el-ex.
File modified: lisp/nterm/nterm.el
Change344 at Sun Aug 15 12:24:03 2010 +0200 by Ivan Kanis <ivan@tao>
diff -r cdfa572df871 -r e5bf71cd0e33 lisp/nterm/nterm.el --- a/lisp/nterm/nterm.el Sun Aug 15 12:20:37 2010 +0200 +++ b/lisp/nterm/nterm.el Sun Aug 15 12:24:03 2010 +0200 @@ -1,3 +1,4 @@ +;; -*-coding: utf-8 -*- ;;; nterm.el --- New TERMinal emulator ;; Copyright (C) 2009, 2010 Ivan Kanis @@ -318,17 +319,15 @@ (set-buffer nterm-buffer-name) (while (< emulate-index emulate-length) (setq emulate-char (aref output emulate-index)) - (if (< emulate-char (length (eval nterm-dispatch))) - (progn - (setq emulate-dispatch (aref (eval nterm-dispatch) emulate-char)) - (if emulate-dispatch - (progn - (if nterm-debug-emulator - (message "received 0x%x %c dispatch %S" - emulate-char emulate-char emulate-dispatch)) - (funcall emulate-dispatch emulate-char) - (if nterm-debug-emulator - (message "received 0x%x not handled" emulate-char))))) + (when (< emulate-char (length (eval nterm-dispatch))) + (setq emulate-dispatch (aref (eval nterm-dispatch) emulate-char)) + (when emulate-dispatch + (if nterm-debug-emulator + (message "received 0x%x %c dispatch %S" + emulate-char emulate-char emulate-dispatch)) + (funcall emulate-dispatch emulate-char) + (if nterm-debug-emulator + (message "received 0x%x not handled" emulate-char)))) (incf emulate-index))))) (defun nterm-init () @@ -423,7 +422,7 @@ (set-process-filter process 'nterm-emulate)) (run-hooks 'nterm-mode-hook))) -(defun nterm-scroll-up (top bottom blank-line-function) +(defun nterm-scroll-up (top bottom line-draw-function) "Scroll screen up from TOP to BOTTOM. Use BLANK-LINE-FUNCTION to insert a blank line." (let ((up-pos (nterm-cursor-position-get))) @@ -439,10 +438,10 @@ (nterm-kill-line) (nterm-cursor-position-set (cons bottom 0)) (insert "\n") - (nterm-vt100-line-draw bottom) + (funcall line-draw-function) (nterm-cursor-position-set up-pos))) -(defun nterm-scroll-down (top bottom blank-line-function) +(defun nterm-scroll-down (top bottom line-draw-function) "Scroll screen down from TOP to BOTTOM. Use BLANK-LINE-FUNCTION to insert a blank line." (let ((down-pos (nterm-cursor-position-get))) @@ -457,7 +456,7 @@ (nterm-kill-line) (nterm-cursor-position-set (cons top 0)) (insert "\n") - (nterm-vt100-line-draw) + (funcall line-draw-function) (nterm-cursor-position-set down-pos))) (defun nterm-send-string (string) @@ -917,20 +916,20 @@ "Bell." (ding)) -(defun nterm-vt100-blank-line (char line &optional length replace) - "Insert LENGTH of CHAR at LINE. -If LENGTH is nil use the terminal width If REPLACE is t -characters are overwritten. LINE is 0 based. The cursor is left -at the end of the line" - (nterm-cursor-line-set line) - (or length - (progn - (setq length (nterm-vt100-width)) - (nterm-cursor-col-set 0))) - (let ((line-index 0)) - (while (< line-index length) - (nterm-vt100-char-insert char replace) - (incf line-index)))) +(defun nterm-vt100-blank-line (bl-line bl-start bl-end) + "Blank LINE from START to END. +If END is nil go to the end of the term. Reset all attributes +on the line." + (if (not bl-line) + (setq bl-line (nterm-cursor-line-get))) + (nterm-mem-line-reset bl-line) + (let ((bl-index bl-start)) + (while (< bl-index bl-end) + (aset (cdr (assq 'char (nth bl-line nterm-memory))) bl-index ?\s) + (aset (cdr (assq 'attr (nth bl-line nterm-memory))) + bl-index (nterm-mem-attribute)) + (incf bl-index))) + (nterm-vt100-line-draw bl-line)) (defun nterm-vt100-blink-screen () "Blink timer, handle blinking on the screen." @@ -1336,53 +1335,32 @@ (message "ED par=%d" ed-number)) (while (< ed-index nterm-height) (cond - ((< ed-index ed-line) - (if (not (eq ed-number 0)) - (progn - (nterm-cursor-position-set (cons ed-index 0)) - (nterm-mem-line-reset ed-index) - (nterm-vt100-blank-line ?\s ed-index nil t)))) + ((and (< ed-index ed-line) (not (eq ed-number 0))) + (nterm-vt100-blank-line ed-index 0 nterm-width)) ((= ed-index ed-line) - (cond - ((eq ed-number 0) - (nterm-cursor-position-set (cons ed-line ed-col)) - (nterm-vt100-blank-line ?\s ed-index (- nterm-width ed-col) t)) - ((eq ed-number 1) - (nterm-cursor-position-set (cons ed-line 0)) - (nterm-vt100-blank-line ?\s ed-index (+ ed-col 1) t)) - (t ; ed-number = 2 and everything else - (nterm-cursor-position-set (cons ed-index 0)) - (nterm-mem-line-reset ed-index) - (nterm-vt100-blank-line ?\s ed-index nil t)))) - ((> ed-index ed-line) - (if (not (eq ed-number 1)) - (progn - (nterm-cursor-position-set (cons ed-index 0)) - (nterm-mem-line-reset ed-index) - (nterm-vt100-blank-line ?\s ed-index nil t))))) + (nterm-vt100-el-ex ed-number)) + ((and (> ed-index ed-line) (not (eq ed-number 1))) + (nterm-vt100-blank-line ed-index 0 nterm-width))) (incf ed-index)) - ;; put the cursor back where it was - (nterm-cursor-position-set (cons ed-line ed-col)) (nterm-vt100-escape-end char))) (defun nterm-vt100-el (char) "EL -- Erase In Line - host to vt100." - (let ((el-number (car (nterm-argument-to-list 1 0))) - (el-line (nterm-cursor-line-get)) - (el-col (nterm-cursor-col-get))) - (if nterm-debug-vt100 - (message "EL par=%d" el-number)) - (cond - ((eq el-number 0) - (nterm-vt100-blank-line ?\s el-line (- nterm-width el-col) t)) - ((eq el-number 1) - (nterm-cursor-col-set 0) - (nterm-vt100-blank-line ?\s el-line (+ el-col 1) t)) - (t - (nterm-vt100-blank-line ?\s el-line nil t))) - (nterm-cursor-col-set el-col)) + (if nterm-debug-vt100 + (message "EL par=%d" el-number)) + (nterm-vt100-el-ex (car (nterm-argument-to-list 1 0))) (nterm-vt100-escape-end char)) +(defun nterm-vt100-el-ex (el-ex-number) + "Erase line, used by ED and EL." + (cond + ((eq el-ex-number 0) + (nterm-vt100-blank-line nil (nterm-cursor-col-get) nterm-width)) + ((eq el-ex-number 1) + (nterm-vt100-blank-line nil 0 (1+ (nterm-cursor-col-get)))) + (t ;; 2 and everything else + (nterm-vt100-blank-line nil 0 nterm-width)))) + (defun nterm-vt100-escape-start (char) "Enter escape mode" (setq nterm-dispatch 'nterm-vt100-escape-dispatch)) @@ -1541,7 +1519,7 @@ (nterm-scroll-up (cdr (assq 'top-margin nterm-vt100-state)) (cdr (assq 'bottom-margin nterm-vt100-state)) - 'nterm-vt100-blank-line) + 'nterm-vt100-line-draw) (nterm-cursor-line-set (+ lf-line 1))))) (defun nterm-vt100-line-draw (&optional line) @@ -1668,7 +1646,7 @@ (nterm-scroll-down (cdr (assq 'top-margin nterm-vt100-state)) (cdr (assq 'bottom-margin nterm-vt100-state)) - 'nterm-vt100-blank-line) + 'nterm-vt100-line-draw) (nterm-vt100-cuu char)) (nterm-vt100-escape-end char))