+
+ # move lines downwards (arg is how far)
+ csi_L: (lines) ->
+ lines = parseInt @fix_esc_arg lines, '1'
+
+ rearrange = (a) =>
+ return [
+ a[0...@y]..., # keep everything above cursor
+ a[@scroll_bottom - lines + 1 .. @scroll_bottom]..., # we'll clear these shortly
+ a[@y..@scroll_bottom - lines]..., # lines that are moving down
+ a[@scroll_bottom + 1 ... @height]... # rest of screen
+ ]
+ @text = rearrange @text
+ @attributes = rearrange @attributes
+
+ # clear the lines we scrolled off (and put back in as "new")
+ for y in [@y...@y+lines]
+ for x in [0...@width]
+ @text[y][x] = ' '
+ @attributes[y][x] = 0x07
+
+ # move lines upwards (arg is how far)
+ # this obliterates the line under the cursor and arg-1 following it
+ csi_M: (lines) ->
+ lines = parseInt @fix_esc_arg lines, '1'
+
+ rearrange = (a) =>
+ return [
+ a[0 ... @y]..., # keep everything above cursor
+ a[@y + lines .. @scroll_bottom]..., # lines we're moving up
+ a[@y ... @y + lines]..., # recycle these
+ a[@scroll_bottom + 1 ... @height]... # keep the rest
+ ]
+ @text = rearrange @text
+ @attributes = rearrange @attributes
+
+ # clear the lines we're recycling
+ for y in [@scroll_bottom - lines + 1 .. @scroll_bottom]
+ for x in [0...@width]
+ @text[y][x] = ' '
+ @attributes[y][x] = 0x07
+
+ # delete chars (without moving the cursor)
+ csi_X: (chars) ->
+ chars = parseInt @fix_esc_arg chars, '1'
+ x = @x
+ for c in [0...chars]
+ if x >= @width
+ return
+ @text[@y][x] = ' '
+ @attributes[@y][x] = @a
+ x += 1
+ return
+ "csi_@": (chars) ->
+ chars = parseInt @fix_esc_arg chars, '1'
+ if chars < 1
+ return
+ if chars > @width - @x
+ chars = @width - @x
+ else
+ dest = @width - 1
+ if dest >= @width
+ dest = @width - 1
+ while dest - chars >= @x
+ @text[@y][dest] = @text[@y][dest - chars]
+ @attributes[@y][dest] = @attributes[@y][dest - chars]
+ dest -= 1
+ @csi_X chars # clear
+ csi_P: (chars) ->
+ chars = parseInt @fix_esc_arg chars, '1'
+ if chars < 1
+ return
+ if chars > @width - @x
+ chars = @width - @x
+ else
+ dest = @x
+ while dest < @width - chars
+ @text[@y][dest] = @text[@y][dest + chars]
+ @attributes[@y][dest] = @attributes[@y][dest + chars]
+ dest += 1
+ # clear the space moved out of
+ x = @width - chars
+ while x < @width
+ @text[@y][x] = ' '
+ @attributes[@y][x] = @a
+ x += 1
+
+ # set modes not starting with "?"
+ csi_h: (args...) ->
+ for i in args
+ arg = @fix_esc_arg i, ''
+ switch arg
+ when '0' # error (ignored
+ return
+ when '2' # KAM -- keyboard action
+ return
+ when '4' # put cursor in "INSERT" mode
+ return
+ when '12' # turn local echo off (or on?)
+ return
+ # TODO when '20' LNM linefeed/newline
+ else
+ log "Unimplemented arg for csi_h: #{arg}"
+ # set modes starting with "?"
+ csiq_h: (args...) ->
+ for i in args
+ arg = @fix_esc_arg i, ''
+ switch arg
+ when '1' # mode ?1
+ # numlock on
+ return
+ when '25'
+ @cursor_visible = true
+ when '1000'
+ # x11 normal mouse tracking
+ return