JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
parse and render inverse attribute
authorJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 06:48:24 +0000 (01:48 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 06:48:24 +0000 (01:48 -0500)
client.coffee
terminal.coffee

index cb46305..cf973f8 100644 (file)
@@ -61,14 +61,20 @@ $ ->
        socket = io.connect('http://localhost')
 
        color_to_css = (i) ->
-               index = 0xff & i
+               # handle inverse bit
+               if i & 0x080000
+                       index = ((i >> 8) & 0xff)
+               else
+                       index = (i & 0xff)
+
                # lighten the basic 8 colors when they're bold
                if ((i & 0x10000) and index < 8)
                        index += 8
                return 'color: #' + palette[index] + '; '
 
        bg_color_to_css = (i) ->
-               return 'background-' + color_to_css((i & 0x10000) | ((i & 0xff00) >> 8))
+               # xor the inverse bit, to get color_to_css to use the bg color
+               return 'background-' + color_to_css(i ^ 0x080000)
 
        stylize = (txt, style) ->
                if (txt.length == 0 or style == 0x000007)
@@ -77,9 +83,9 @@ $ ->
                css += 'font-weight: bold; ' if style & 0x10000
                css += 'text-decoration: underline; ' if style & 0x20000
                css += 'font-style: italic; ' if style & 0x40000 # blink
-               css += 'text-decoration: line-through; ' if style & 0x80000 # invisible
-               css += color_to_css(style) if style & 0x000ff
-               css += bg_color_to_css(style) if style & 0x0ff00
+               css += 'text-decoration: line-through; ' if style & 0x100000 # invisible
+               css += color_to_css(style) if ((style & 0x0800ff) isnt 0x07)
+               css += bg_color_to_css(style) if (style & 0x08ff00)
                return $('<span style="'+css+'"></span>').text(txt)
 
        redraw_wait = false
index d5830c5..0ba72f4 100644 (file)
@@ -100,7 +100,7 @@ class Terminal
                return
 
        set_attribute_bits: (mask, value) ->
-               @a = (@a & ~mask) | value
+               @a = ((@a & ~mask) | value)
 
        # we're supposed to ignore leeding zeros, and while we're at it, lets swap
        # in the default for blank or missing values
@@ -221,36 +221,41 @@ class Terminal
        csi_m: ->
                args = []
                for i in arguments
-                       args.push @fix_esc_arg i, 0
+                       args.push @fix_esc_arg i, '0'
 
                while args.length > 0
-                       switch args.shift()
-
+                       arg = args.shift()
+                       switch arg
                                # remove all style/color
                                when '0'
-                                       @set_attribute_bits 0xffffff, 0x000007
+                                       @a = 0
 
                                # style attributes
                                when '1' # bold
-                                       @set_attribute_bits 0x10000, 0x10000
+                                       @set_attribute_bits 0x010000, 0x010000
+                               # FIXME add '3' for italic ('23' to turn it off)
                                when '4' # underline
-                                       @set_attribute_bits 0x20000, 0x20000
+                                       @set_attribute_bits 0x020000, 0x020000
                                when '5' # blink
-                                       @set_attribute_bits 0x40000, 0x40000
+                                       @set_attribute_bits 0x040000, 0x040000
+                               when '7' # inverse
+                                       @set_attribute_bits 0x080000, 0x080000
                                when '8' # invisible
-                                       @set_attribute_bits 0x80000, 0x80000
+                                       @set_attribute_bits 0x100000, 0x100000
 
                                # disable style attributes
                                when '22' # not bold... according to a page
-                                       @set_attribute_bits 0x10000, 0
+                                       @set_attribute_bits 0x010000, 0
                                when '21' # ... though this would make more sense for "not bold"
-                                       @set_attribute_bits 0x10000, 0
+                                       @set_attribute_bits 0x010000, 0
                                when '24' # not underline
-                                       @set_attribute_bits 0x20000, 0
+                                       @set_attribute_bits 0x020000, 0
                                when '25' # not blink
-                                       @set_attribute_bits 0x40000, 0
+                                       @set_attribute_bits 0x040000, 0
+                               when '27' # not inverse
+                                       @set_attribute_bits 0x080000, 0
                                when '28' # not invisible
-                                       @set_attribute_bits 0x80000, 0
+                                       @set_attribute_bits 0x100000, 0
 
                                when '100' # reset colors but not other attributes
                                        @set_attribute_bits 0xffff, 0x0007
@@ -343,10 +348,10 @@ class Terminal
                                when '107' # bg bright white
                                        @set_attribute_bits 0xff, 0x0f
 
-
                                else
                                        # if we don't recognize the style, go back to default
-                                       @set_attribute_bits 0xffffff, 0
+                                       console.log "unrecognized csi_m arg: \"#{arg}\""
+                                       @a = 0
                return
 
        # str is the whole escape sequence (minus the esc[ prefix)