Try fixing session size

This commit is contained in:
Florian Mounier
2015-10-13 11:40:32 +02:00
parent 7371b8b4e1
commit fc5879f2d4
7 changed files with 40 additions and 68 deletions

View File

@@ -238,16 +238,20 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
del sessions[session]
@classmethod
def broadcast(cls, session, message, user):
cls.history[session] += message
def broadcast(cls, session, message, user, emitter=None):
if message[0] == 'S':
cls.history[session] += message[1:]
if len(cls.history[session]) > cls.session_history_size:
cls.history[session] = cls.history[session][
-cls.session_history_size:]
sessions = cls.sessions.get(user.name, [])
for session in sessions[session]:
try:
session.write_message(message)
if session != emitter:
session.write_message(message)
except Exception:
session.log.exception('Error on broadcast')
session.close()
def write(self, message):
@@ -268,6 +272,10 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
if self.session and self.secure_user:
term = self.user_terminals.get(self.session)
term and term.write(message)
if message[0] == 'R':
# Broadcast resize
TermWebSocket.broadcast(
self.session, message, self.secure_user, self)
else:
self._terminal.write(message)

View File

@@ -47,10 +47,16 @@
t_queue = null;
queue = '';
ws.addEventListener('message', function(e) {
var ref;
if (e.data[0] === 'R') {
ref = e.data.slice(1).split(','), cols = ref[0], rows = ref[1];
term.resize(cols, rows, true);
return;
}
if (t_queue) {
clearTimeout(t_queue);
}
queue += e.data;
queue += e.data.slice(1);
if (term.stop) {
queue = queue.slice(-10 * 1024);
}
@@ -305,7 +311,8 @@
}
this.showCursor();
this.body.classList.add('focus');
return this.body.classList.remove('blur');
this.body.classList.remove('blur');
return this.resize();
};
Terminal.prototype.blur = function() {
@@ -1648,7 +1655,7 @@
})(this)), this.visualBell);
};
Terminal.prototype.resize = function(x, y) {
Terminal.prototype.resize = function(x, y, notif) {
var el, h, i, j, line, oldCols, oldRows, px, w;
if (x == null) {
x = null;
@@ -1656,6 +1663,9 @@
if (y == null) {
y = null;
}
if (notif == null) {
notif = false;
}
oldCols = this.cols;
oldRows = this.rows;
this.computeCharSize();
@@ -1669,7 +1679,9 @@
if ((!x && !y) && oldCols === this.cols && oldRows === this.rows) {
return;
}
this.ctl('Resize', this.cols, this.rows);
if (!notif) {
this.ctl('Resize', this.cols, this.rows);
}
if (oldCols < this.cols) {
i = this.screen.length;
while (i--) {

File diff suppressed because one or more lines are too long

View File

@@ -277,12 +277,11 @@ class Terminal(object):
s = struct.pack("HHHH", rows, cols, 0, 0)
fcntl.ioctl(self.fd, termios.TIOCSWINSZ, s)
log.info('SIZE (%d, %d)' % (cols, rows))
elif message[0] == 'S':
log.debug('WRIT<%r' % message)
self.writer.write(message[1:])
self.writer.flush()
elif message[0] == 'T':
tornado.options.options.theme = message[1:]
def shell_handler(self, fd, events):
if events & ioloop.READ:
@@ -293,7 +292,7 @@ class Terminal(object):
log.debug('READ>%r' % read)
if read and len(read) != 0:
self.send(read.decode('utf-8', 'replace'))
self.send('S' + read.decode('utf-8', 'replace'))
else:
events = ioloop.ERROR

View File

@@ -60,59 +60,6 @@ def get_hex_ip_port(remote):
return ''.join(ipv6_parts) + ':%04X' % port
def get_style_path():
opts = tornado.options.options
if opts.theme and os.path.exists(opts.theme):
if os.path.isdir(opts.theme):
theme = os.path.join(opts.theme, 'style.sass')
if os.path.exists(theme):
return theme
else:
return opts.theme
if opts.theme:
theme = 'themes/%s/' % opts.theme
else:
theme = '/'
for ext in ['css', 'scss', 'sass']:
for fn in [
'/etc/butterfly/%sstyle' % theme,
os.path.expanduser('~/.butterfly/%sstyle' % theme)]:
if os.path.exists('%s.%s' % (fn, ext)):
return '%s.%s' % (fn, ext)
def get_style():
style = get_style_path()
if style is None:
return
if style.endswith('.scss') or style.endswith('.sass'):
sass_path = os.path.join(
os.path.dirname(__file__), 'sass')
try:
import sass
sass.CompileError
except Exception:
log.error('You must install libsass to use sass '
'(pip install libsass)')
return
base = os.path.dirname(style)
try:
return sass.compile(filename=style, include_paths=[
base, sass_path])
except sass.CompileError:
log.error(
'Unable to compile style.scss (filename: %s, paths: %r) ' % (
style, [base, sass_path]), exc_info=True)
return
with open(style) as s:
return s.read()
def parse_cert(cert):
user = None

View File

@@ -55,8 +55,13 @@ document.addEventListener 'DOMContentLoaded', ->
queue = ''
ws.addEventListener 'message', (e) ->
if e.data[0] is 'R'
[cols, rows] = e.data.slice(1).split(',')
term.resize cols, rows, true
return
clearTimeout t_queue if t_queue
queue += e.data
queue += e.data.slice(1)
if term.stop
queue = queue.slice -10 * 1024

View File

@@ -201,6 +201,7 @@ class Terminal
@showCursor()
@body.classList.add('focus')
@body.classList.remove('blur')
@resize()
blur: ->
@cursorState = 1
@@ -1541,7 +1542,7 @@ class Terminal
@body.classList.remove cls
), @visualBell
resize: (x=null, y=null) ->
resize: (x=null, y=null, notif=false) ->
oldCols = @cols
oldRows = @rows
@computeCharSize()
@@ -1556,7 +1557,7 @@ class Terminal
if (not x and not y) and oldCols == @cols and oldRows == @rows
return
@ctl 'Resize', @cols, @rows
@ctl 'Resize', @cols, @rows unless notif
# resize cols
if oldCols < @cols