Data buffering in VT

openid
Marcin Kulik 13 years ago
parent ab32a32734
commit 9c5201905c

@ -1,6 +1,7 @@
class AsciiIo.VT
constructor: (cols, lines, @renderer) ->
@data = ''
@sb = new AsciiIo.ScreenBuffer(cols, lines)
@fg = @bg = undefined
@ -260,16 +261,18 @@ class AsciiIo.VT
@COMPILED_PATTERNS = ([new RegExp("^" + re), f] for re, f of @PATTERNS)
feed: (data) ->
while data.length > 0
@data += data
while @data.length > 0
match = null
for pattern in @COMPILED_PATTERNS
match = pattern[0].exec(data)
match = pattern[0].exec(@data)
if match
handler = pattern[1]
handler.call(this, data, match)
data = data.slice(match[0].length)
handler.call(this, @data, match)
@data = @data.slice(match[0].length)
break
break unless match
@ -278,4 +281,4 @@ class AsciiIo.VT
@renderer.render(changes, @sb.cursorX, @sb.cursorY)
@sb.clearChanges()
data.length is 0
@data.length is 0

@ -196,10 +196,6 @@ describe 'AsciiIo.VT', ->
describe ']', ->
# Operating system command
# beforeEach ->
# vt = new AsciiIo.VT(cols, lines, renderer)
# vt.sb = {} # will throw 'undefined is not a function'
describe '0;...BELL', ->
beforeEach ->
data += ']0;foobar\x07'
@ -240,11 +236,11 @@ describe 'AsciiIo.VT', ->
data += '['
describe 'buffering', ->
# it 'allows parsing in chunks', ->
# spyOn vt, 'handleSGR'
# vt.feed(data)
# vt.feed('m')
# expect(vt.handleSGR).toHaveBeenCalled()
it 'allows parsing in chunks', ->
spyOn vt, 'handleSGR'
vt.feed(data)
vt.feed('m')
expect(vt.handleSGR).toHaveBeenCalled()
describe '@', ->
it 'calls reserveCharacters', ->

Loading…
Cancel
Save