Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
watch-my-terminal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
run.sh: complain if not passed width/height
[watch-my-terminal.git]
/
server.coffee
diff --git
a/server.coffee
b/server.coffee
index
bf3a750
..
f79fe33
100644
(file)
--- a/
server.coffee
+++ b/
server.coffee
@@
-1,3
+1,14
@@
+# SETTINGS
+term_columns = 97
+term_lines = 63
+http_port = 2218
+
+if process.argv.length > 2
+ term_columns = parseInt process.argv[2]
+if process.argv.length > 3
+ term_lines = parseInt process.argv[3]
+
+
handler = (req, res) ->
reply_err = (req, res, msg) ->
res.writeHead(200, 'Content-Type': 'text/plain')
handler = (req, res) ->
reply_err = (req, res, msg) ->
res.writeHead(200, 'Content-Type': 'text/plain')
@@
-12,6
+23,9
@@
handler = (req, res) ->
when '/terminal.js'
filename = __dirname + '/terminal.coffee'
type = 'text/javascript'
when '/terminal.js'
filename = __dirname + '/terminal.coffee'
type = 'text/javascript'
+ when '/htmlterm.js'
+ filename = __dirname + '/htmlterm.coffee'
+ type = 'text/javascript'
when '/client.js'
filename = __dirname + '/client.coffee'
type = 'text/javascript'
when '/client.js'
filename = __dirname + '/client.coffee'
type = 'text/javascript'
@@
-35,9
+49,8
@@
io = require('socket.io').listen(app)
fs = require('fs')
terminal = require('./terminal.coffee')
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 = []
sockets = []
@@
-77,11
+90,15
@@
io.sockets.on 'connection', (socket) ->
encode_screen = (height, width, text, attributes) ->
state = ''
for y in [0...height]
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
if y < height - 1
state += '\n'
return state