JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
init: send normal screen too when on alt
authorJason Woofenden <jason@jasonwoof.com>
Fri, 1 Feb 2013 04:39:34 +0000 (23:39 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Fri, 1 Feb 2013 04:39:34 +0000 (23:39 -0500)
server.coffee
terminal.coffee

index 06f6aed..bf3a750 100644 (file)
@@ -74,18 +74,25 @@ io.sockets.on 'connection', (socket) ->
                        return "\x1b[#{parts.join ';'}m"
                else
                        return ''
+       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]
+                       if y < height - 1
+                               state += '\n'
+               return state
 
        a = 0x07
        state = ''
-       # FIXME handle alt screen
-       for y in [0...term.height]
-               for x in [0...term.width]
-                       if term.attributes[y][x] isnt a
-                               state += attr_diff a, term.attributes[y][x]
-                               a = term.attributes[y][x]
-                       state += term.text[y][x]
-               if y < term.height - 1
-                       state += '\n'
+       if term.saved_normal_screen?
+               state += encode_screen term.height, term.width, term.saved_normal_screen.text, term.saved_normal_screen.attributes
+               state += "\x1b[#{term.saved_normal_screen.y + 1};#{term.saved_normal_screen.x + 1}H"
+               state += "\x1b[?1049h\x1b[H" # flip to alt screen and move cursor home
+       state += encode_screen term.height, term.width, term.text, term.attributes
        state += attr_diff a, term.a
        state += "\x1b[#{term.y + 1};#{term.x + 1}H"
        unless term.cursor_visible
index 242d246..174c005 100644 (file)
@@ -286,7 +286,7 @@ class Terminal
                                        if @saved_normal_screen?
                                                log "ignoring request to switch to the alt screen because we're already on the alt screen"
                                                return
-                                       @saved_normal_screen = [@x, @y, @text, @attributes]
+                                       @saved_normal_screen = x: @x, y: @y, text: @text, attributes: @attributes
                                        @text = []
                                        @attributes = []
                                        for y in [0...@height]
@@ -311,10 +311,10 @@ class Terminal
                                        if not @saved_normal_screen?
                                                log "ignoring request to switch to the normal screen because we're already on the normal screen"
                                                return
-                                       @x = @saved_normal_screen[0]
-                                       @y = @saved_normal_screen[1]
-                                       @text = @saved_normal_screen[2]
-                                       @attributes = @saved_normal_screen[3]
+                                       @x = @saved_normal_screen.x
+                                       @y = @saved_normal_screen.y
+                                       @text = @saved_normal_screen.text
+                                       @attributes = @saved_normal_screen.attributes
                                        @saved_normal_screen = null
                                else
                                        log "confusing arg for csiq_l: #{arg}"