+ # we're supposed to ignore leeding zeros, and while we're at it, lets swap
+ # in the default for blank or missing values
+ fix_esc_arg: (value, deef_alt) ->
+ if value? and value != ''
+ while value[0] is '0' and value.length > 1
+ value = value.substr 1
+ return value
+ 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
+ column = 0 + @fix_esc_arg column, 1
+ # convert to 0 base
+ column -= 1
+ if 0 <= column < @width
+ @x = column
+ else
+ console.log "tried to move cursor to invalid column: #{column}"
+ row -= 1
+ if 0 <= row < @height
+ @y = row
+ else
+ console.log "tried to move cursor to invalid row: #{row}"
+
+ # set color, bold, underline, etc
+ csi_m: ->
+ args = []