1 async = require 'async'
6 constructor: (width, height) ->
16 resize: (width, height) ->
17 # FIXME: write a version that retains some of the data
22 @attributes[i] = new Array(width)
24 # pass data from stdout
26 return unless data?.length > 0
27 if @partial.length > 0
28 data = @partial + data
30 parts = data.split(/\x1b\[/)
32 if -1 is @escape_sequence_length parts[parts.length - 1]
33 @partial = parts.pop()
35 for i in [0...parts.length]
39 @update_sequence_then_text parts[i]
42 # str has no escape sequences
44 return unless str.length > 0
45 console.log "text: \"#{str}\"" # FIXME
47 # str is the whole escape sequence (minus the esc[ prefix)
48 update_sequence: (str) ->
49 console.log "sequence: \"#{str}\"" # FIXME
51 update_sequence_then_text: (str) ->
52 len = @escape_sequence_length str
54 console.log "couldn't find escape sequence here: #{str.substr 0, 25}"
55 @update_text "ESC[" + str
57 @update_sequence str.substr 0, len
58 @update_text str.substr len
60 escape_sequence_length: (str) ->
61 parts = str.match(/^[0-9;?]{0,25}./)
62 return -1 unless parts?
63 return parts[0].length