JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
display cursor, handle show/hide sequences
authorJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 21:18:07 +0000 (16:18 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 21:18:07 +0000 (16:18 -0500)
client.coffee
server.coffee
terminal.coffee

index c14c426..14e5a6f 100644 (file)
@@ -92,6 +92,14 @@ $ ->
        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 = $('<div>')
                        txt = ''
@@ -106,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 = ->
@@ -136,4 +146,5 @@ $ ->
                term.a = v.a
                term.text = v.text
                term.attributes = v.attributes
+               term.cursor_visible = v.cursor_visible
                redraw()
index d66b6cd..7adfc69 100644 (file)
@@ -49,7 +49,7 @@ io.sockets.on 'connection', (socket) ->
                                sockets.splice i, 1
                                return
 
-       socket.emit 'init', width: term.width, height: term.height, x: term.x, y: term.y, a: term.a, text: term.text, attributes: term.attributes
+       socket.emit 'init', width: term.width, height: term.height, x: term.x, y: term.y, a: term.a, text: term.text, attributes: term.attributes, cursor_visible: term.cursor_visible
 
 process.stdin.resume()
 process.stdin.setEncoding 'utf8'
index 12d8a74..d371476 100644 (file)
@@ -19,6 +19,7 @@ class Terminal
                @a = 0x000007 # cursor attributes
                @partial = ''
                @saved_normal_screen = null
+               @cursor_visible = true
                @resize width, height
 
        resize: (width, height) ->
@@ -32,7 +33,7 @@ class Terminal
                        @attributes[y] = []
                        for x in [0...width]
                                @text[y].push ' '
-                               @attributes[y].push 0
+                               @attributes[y].push 0x07
 
        # pass data from stdout
        update: (data) ->
@@ -56,7 +57,7 @@ class Terminal
                # clear top line
                for i in [0...@width]
                        @text[0][i] = ' '
-                       @attributes[0][i] = 0
+                       @attributes[0][i] = 0x07
                # move (newly cleared) top line to the bottom
                tmp = @text.shift()
                @text.push(tmp)
@@ -220,6 +221,8 @@ class Terminal
                for i in arguments
                        arg = @fix_esc_arg i, ''
                        switch arg
+                               when '25'
+                                       @cursor_visible = true
                                when '1049'
                                        if @saved_normal_screen?
                                                console.log "ignoring request to switch to the alt screen because we're already on the alt screen"
@@ -232,7 +235,7 @@ class Terminal
                                                @attributes[y] = []
                                                for x in [0...@width]
                                                        @text[y].push ' '
-                                                       @attributes[y].push 0
+                                                       @attributes[y].push 0x07
                                else
                                        console.log "confusing arg for csiq_h: #{arg}"
        # unmisc
@@ -241,6 +244,8 @@ class Terminal
                for i in arguments
                        arg = @fix_esc_arg i, ''
                        switch arg
+                               when '25'
+                                       @cursor_visible = false
                                when '1049'
                                        if not @saved_normal_screen?
                                                console.log "ignoring request to switch to the normal screen because we're already on the normal screen"