JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
wrap lines in <code>s not <divs>
[watch-my-terminal.git] / server.coffee
index bf3a750..adf1d55 100644 (file)
@@ -37,7 +37,7 @@ terminal = require('./terminal.coffee')
 
 # SETTINGS
 app.listen(2218)
-term = terminal.new(104, 66)
+term = terminal.new(104, 34)
 
 sockets = []
 
@@ -77,11 +77,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