X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.coffee;h=14e5a6fab510dd4dac14c5e5c3ad184e8dce852f;hb=469415c385464dc424c37f4602bf59233bbaa738;hp=1497d10c95eea8ffbb4dcab7b8d979a584ce07b4;hpb=2123b27defd2e348562d9bc725449dd5a987e450;p=watch-my-terminal.git diff --git a/client.coffee b/client.coffee index 1497d10..14e5a6f 100644 --- a/client.coffee +++ b/client.coffee @@ -56,35 +56,50 @@ $ -> ] $body = $('body') + $body.css backgroundColor: "##{palette[0]}", color: "##{palette[7]}" 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) return txt css = '' - 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 += 'font-weight: bold; ' if style & 0x010000 + css += 'text-decoration: underline; ' if style & 0x020000 + css += 'font-style: italic; ' if style & 0x200000 # italic + css += 'opacity: 0; ' if style & 0x100000 # invisible + css += color_to_css(style) if ((style & 0x0800ff) isnt 0x07) + css += bg_color_to_css(style) if (style & 0x08ff00) return $('').text(txt) redraw_wait = false redraw_again = false redraw_now = -> $body.children().remove() + # cursor can be just off the right side, but we draw it on the last column in that case + if term.x >= term.width + cursor_x = term.width - 1 + else + cursor_x = term.x + # invert the cursor TODO: make it blink + if term.cursor_visible + term.attributes[term.y][cursor_x] ^= 0x080000 for i in [0...term.text.length] div = $('
') txt = '' @@ -99,6 +114,8 @@ $ -> if txt.length div.append(stylize(txt, a)) $body.append(div) + if term.cursor_visible + term.attributes[term.y][cursor_x] ^= 0x080000 # limit to 50fps redraw = -> @@ -129,4 +146,5 @@ $ -> term.a = v.a term.text = v.text term.attributes = v.attributes + term.cursor_visible = v.cursor_visible redraw()