X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=terminal.coffee;h=d5830c5401e27aa73e159f3db5ee82f570ac92ac;hb=e5cb729bf87ae7e8a3473a4527af609e49d61321;hp=abc006a42e3a528f339bb57317dc998201f31c2a;hpb=790fe120c484c9bc3736aacc1fdaa9904177e383;p=watch-my-terminal.git diff --git a/terminal.coffee b/terminal.coffee index abc006a..d5830c5 100644 --- a/terminal.coffee +++ b/terminal.coffee @@ -83,18 +83,20 @@ class Terminal when '\x0d' # cr @x = 0 when '\x08' # backspace - if @x > 0 + if @x is 0 + @x = @width - 1 + if @y > 0 + @y -= 1 + else @x -= 1 - @text[@y][@x] = ' ' - # should this set the attribute too? when '\x0a', '\x0b' # lf, vertical tab (same thing) @wrap_to_next_line() else + if @x >= @width + @wrap_to_next_line() @text[@y][@x] = c @attributes[@y][@x] = @a @x += 1 - if @x is @width - @wrap_to_next_line() return set_attribute_bits: (mask, value) -> @@ -112,11 +114,9 @@ class Terminal # 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 + # handle blank/missing args and convert to 0 base + row = @fix_esc_arg(row, 1) - 1 + column = @fix_esc_arg(column, 1) - 1 #clamp values if column < 0 @@ -132,15 +132,21 @@ class Terminal @x = column @y = row - # clear lines (implemented inclusive of the current line) + # clear to screen edge(es) csi_J: (direction) -> switch @fix_esc_arg direction, '0' when '0' # erase down + # rest of current line + @csi_K direction + # rest of lines for row in [@y...@height] for i in [0...@width] @text[row][i] = ' ' @attributes[row][i] = @a when '1' # erase up + # beginning of current line + @csi_K direction + # all previous lines for row in [0..@y] for i in [0...@width] @text[row][i] = ' ' @@ -152,6 +158,7 @@ class Terminal @attributes[row][i] = @a else console.log "confusing arg for csi_J: #{direction}" + return # clear (some or all of) current line csi_K: (direction) -> @@ -161,7 +168,12 @@ class Terminal @text[@y][i] = ' ' @attributes[@y][i] = @a when '1' # erase to left - for i in [0...@x] + # @x can equal @width (after printing to right-most column) + if @x < @width + max = @x + else + max = @width - 1 + for i in [0..max] @text[@y][i] = ' ' @attributes[@y][i] = @a when '2' # erase whole line @@ -170,6 +182,7 @@ class Terminal @attributes[@y][i] = @a else console.log "confusing arg for csi_K: #{direction}" + return # misc csiq_h: ->