Remove throuput control and use the pause/break key to prevent flood.

This commit is contained in:
Florian Mounier
2016-08-08 11:12:22 +02:00
parent 503de38429
commit ac7e9bef8e
6 changed files with 68 additions and 84 deletions

View File

@@ -18,6 +18,10 @@
cols = rows = null
quit = false
openTs = (new Date()).getTime()
cutMessage = '\r\nCutting...... 8< ...... 8< ...... ' +
'\r\nYou can release when there is no more output.' +
'\r\nCutting...... 8< ...... 8< ......' +
'\r\nCutting...... 8< ...... 8< ......'
$ = document.querySelectorAll.bind(document)
@@ -54,10 +58,6 @@ document.addEventListener 'DOMContentLoaded', ->
ws.addEventListener 'error', ->
console.log "WebSocket error", arguments
lastData = ''
t_queue = null
queue = ''
ws.addEventListener 'message', (e) ->
if e.data[0] is 'R'
[cols, rows] = e.data.slice(1).split(',')
@@ -68,22 +68,14 @@ document.addEventListener 'DOMContentLoaded', ->
console.error 'Garbage message'
return
clearTimeout t_queue if t_queue
queue += e.data.slice(1)
if term.stop
queue = queue.slice -10 * 1024
if queue.length > term.buffSize
treat()
unless term.stop?
term.write e.data.slice(1)
else
t_queue = setTimeout treat, 1
treat = ->
term.write queue
if term.stop
term.stop = false
term.body.classList.remove 'stopped'
queue = ''
if term.stop < cutMessage.length
letter = cutMessage[term.stop++]
else
letter = '.'
term.write letter
ws.addEventListener 'close', ->
console.log "WebSocket closed", arguments
@@ -102,7 +94,6 @@ document.addEventListener 'DOMContentLoaded', ->
if not quit
'This will exit the terminal session'
window.bench = (n=100000000) ->
rnd = ''
while rnd.length < n

View File

@@ -80,14 +80,14 @@ class Terminal
@termName = 'xterm'
@cursorBlink = true
@cursorState = 0
@stop = false
@lastcc = 0
@resetVars()
@focus()
@startBlink()
addEventListener 'keydown', @keyDown.bind(@)
addEventListener 'keyup', @keyUp.bind(@)
addEventListener 'keypress', @keyPress.bind(@)
addEventListener 'focus', @focus.bind(@)
addEventListener 'blur', @blur.bind(@)
@@ -1258,12 +1258,26 @@ class Terminal
writeln: (data) ->
@write "#{data}\r\n"
keyUp: (ev) ->
if ev.keyCode is 19 # Pause break
return unless @stop
@body.classList.remove 'stopped'
@stop = null
@out '\x03\n'
keyDown: (ev) ->
# Key Resources:
# https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
# Don't handle modifiers alone
return true if ev.keyCode > 15 and ev.keyCode < 19
if ev.keyCode is 19 # Pause break
return if @stop
@body.classList.add 'stopped'
@stop = 0
@out '\x03'
return false
# Handle shift insert and ctrl insert
# copy/paste usefull for typematrix keyboard
return true if (ev.shiftKey or ev.ctrlKey) and ev.keyCode is 45
@@ -1446,21 +1460,9 @@ class Terminal
# a-z and space
if ev.ctrlKey
if ev.keyCode >= 65 and ev.keyCode <= 90
if ev.keyCode is 67
t = (new Date()).getTime()
if (t - @lastcc) < 500 and not @stop
id = (setTimeout ->)
(clearTimeout id if id not in [
@t_bell, @t_queue, @t_blink]) while id--
@body.classList.add 'stopped'
@stop = true
return @send ' \x7f'
else if @stop
return true
@lastcc = t
key = String.fromCharCode(ev.keyCode - 64)
else if ev.keyCode is 32
else if ev.keyCode is 32
# NUL
key = String.fromCharCode(0)
else if ev.keyCode >= 51 and ev.keyCode <= 55