X-Git-Url: https://jasonwoof.com/gitweb/?p=watch-my-terminal.git;a=blobdiff_plain;f=index.html;h=6fb1473bb941a1a769a9d73d64e184e3b1606084;hp=091da51765727a90377ba6aa534a3f5329f94d2b;hb=394a14939b00dbbb2a30c8a87ac3333a41c74ef2;hpb=1700d1f6d76490cd696f9072bf28d595a4e484c5 diff --git a/index.html b/index.html index 091da51..6fb1473 100644 --- a/index.html +++ b/index.html @@ -8,10 +8,46 @@ $(function() { var $body = $('body'); var socket = io.connect('http://localhost'); + var color_to_css = function(i) { + return 'color: #' + + ((i & 0xe0) ? 'ff' : '00') + + ((i & 0x1c) ? 'ff' : '00') + + ((i & 0x03) ? 'ff' : '00') + + '; '; + } + var stylize = function (txt, style) { + if(txt.length == 0 || style == 0) { + return txt + } + css = '' + if(style & 0x10000) css += 'font-weight: bold; '; + if(style & 0x20000) css += 'text-decoration: underline; '; + if(style & 0x40000) css += 'text-decoration: underline; '; // blink + if(style & 0x80000) css += 'text-decoration: line-through; '; // invisible + if(style & 0x000ff) css += color_to_css(style & 0xff); + if(style & 0x0ff00) css += 'background-' + color_to_css((style & 0xff00) >> 8); + return $('').text(txt); + } socket.on('init', function (v) { $body.children().remove(); for(i in v.text) { - $body.append($('
').text(v.text[i].join(''))); + div = $('
'); + txt = '' + a = 0; + for(j in v.text[i]) { + if(v.attributes[i][j] != a) { + if(txt.length) { + div.append(stylize(txt, a)); + txt = '' + } + a = v.attributes[i][j] + } + txt += v.text[i][j] + } + if(txt.length) { + div.append(stylize(txt, a)); + } + $body.append(div); } }); });