JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add csi_J, fix csi_K(2)
[watch-my-terminal.git] / terminal.coffee
index b66bf00..f3ed817 100644 (file)
@@ -109,22 +109,6 @@ class Terminal
                else
                        return deef_alt
 
-       # clear (some or all of) current line
-       csi_K: (direction) ->
-               switch @fix_esc_arg direction, '0'
-                       when '0' # erase to right
-                               for i in [@x...@width]
-                                       @text[@y][i] = ' '
-                                       @attributes[@y][i] = @a
-                       when '1' # erase to left
-                               for i in [0...@x]
-                                       @text[@y][i] = ' '
-                                       @attributes[@y][i] = @a
-                       when '0' # erase whole line
-                               for i in [0...@width]
-                                       @text[@y][i] = ' '
-                                       @attributes[@y][i] = @a
-
        # set cursor position (one based)
        csi_H: (row, column) ->
                row = 0 + @fix_esc_arg row, 1
@@ -141,6 +125,45 @@ class Terminal
                else
                        console.log "tried to move cursor to invalid row: #{row}"
 
+       # clear lines (implemented inclusive of the current line)
+       csi_J: (direction) ->
+               switch @fix_esc_arg direction, '0'
+                       when '0' # erase down
+                               for row in [@y...@height]
+                                       for i in [0...@width]
+                                               @text[row][i] = ' '
+                                               @attributes[row][i] = @a
+                       when '1' # erase up
+                               for row in [0..@y]
+                                       for i in [0...@width]
+                                               @text[row][i] = ' '
+                                               @attributes[row][i] = @a
+                       when '2' # erase everything
+                               for row in [0...@height]
+                                       for i in [0...@width]
+                                               @text[row][i] = ' '
+                                               @attributes[row][i] = @a
+                       else
+                               console.log "confusing arg for csi_J: #{direction}"
+
+       # clear (some or all of) current line
+       csi_K: (direction) ->
+               switch @fix_esc_arg direction, '0'
+                       when '0' # erase to right
+                               for i in [@x...@width]
+                                       @text[@y][i] = ' '
+                                       @attributes[@y][i] = @a
+                       when '1' # erase to left
+                               for i in [0...@x]
+                                       @text[@y][i] = ' '
+                                       @attributes[@y][i] = @a
+                       when '2' # erase whole line
+                               for i in [0...@width]
+                                       @text[@y][i] = ' '
+                                       @attributes[@y][i] = @a
+                       else
+                               console.log "confusing arg for csi_K: #{direction}"
+
        # set color, bold, underline, etc
        csi_m: ->
                args = []