X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=server.coffee;h=f1e208ab9d2d2fd418b5f715935eb458309734e0;hb=1d26e751e83a991c26082de09155bf6bfa80eb0c;hp=bf3a7502449f2e42e975283c4e5d5e8c310cb8b7;hpb=55d03d755b1b783e32faa32bf0a4d59260660184;p=watch-my-terminal.git diff --git a/server.coffee b/server.coffee index bf3a750..f1e208a 100644 --- a/server.coffee +++ b/server.coffee @@ -1,3 +1,9 @@ +# SETTINGS +term_lines = 32 +term_columns = 104 +http_port = 2218 + + handler = (req, res) -> reply_err = (req, res, msg) -> res.writeHead(200, 'Content-Type': 'text/plain') @@ -35,9 +41,8 @@ io = require('socket.io').listen(app) fs = require('fs') terminal = require('./terminal.coffee') -# SETTINGS -app.listen(2218) -term = terminal.new(104, 66) +app.listen(http_port) +term = terminal.new(term_columns, term_lines) sockets = [] @@ -77,11 +82,15 @@ io.sockets.on 'connection', (socket) -> encode_screen = (height, width, text, attributes) -> state = '' for y in [0...height] - for x in [0...width] - if attributes[y][x] isnt a - state += attr_diff a, attributes[y][x] - a = attributes[y][x] - state += text[y][x] + max = width - 1 + while max >= 0 and text[y][max] is ' ' and (attributes[y][max] & 0x08ff00) is 0 + max -= 1 + if max >= 0 + for x in [0..max] + if attributes[y][x] isnt a + state += attr_diff a, attributes[y][x] + a = attributes[y][x] + state += text[y][x] if y < height - 1 state += '\n' return state