'faster' version, some lint fixes, notes...

This commit is contained in:
Howland Owl 2013-10-18 17:43:54 +03:00
parent e8bf58f2c5
commit d633e2e31f

View file

@ -1030,8 +1030,19 @@ class @ImageTextMode
bufView[i] = str.charCodeAt(i) for i in [0...str.length] bufView[i] = str.charCodeAt(i) for i in [0...str.length]
buf buf
# tests show the resulting code is not altered for results or for the logic
# but this makes the linter happy. (coffeescript's own I guess.)
# (the constructor right after the class def, before locals)
class @ImageTextModeANSI extends @ImageTextMode class @ImageTextModeANSI extends @ImageTextMode
constructor: ( options ) ->
super @screen
super @font
@palette = new ImageTextModePaletteANSI
@tabstop = 8
@linewrap = 80
@[k] = v for own k, v of options
ANSI_ESC = String.fromCharCode(0x1b) ANSI_ESC = String.fromCharCode(0x1b)
ANSI_CSI = ANSI_ESC + '[' ANSI_CSI = ANSI_ESC + '['
ANSI_TEXT_PROP = 'm' ANSI_TEXT_PROP = 'm'
@ -1044,20 +1055,16 @@ class @ImageTextModeANSI extends @ImageTextMode
ANSI_SEP = ';' ANSI_SEP = ';'
ANSI_RETURN = 'A' ANSI_RETURN = 'A'
constructor: ( options ) -> # not going to mess with this for now, as I think it is the 'write' code
super @screen # for the actual ansi editor. That would be bad to mess up.
super @font # did redo the for loops to read nicer tho.
@palette = new ImageTextModePaletteANSI
@tabstop = 8
@linewrap = 80
@[k] = v for own k, v of options
write: -> write: ->
content = "#{ ANSI_CSI }2J" # initiate document content = "#{ ANSI_CSI }2J" # initiate document
for y in [0..@screen.length - 1] for y in [0...@screen.length]
content += "\n" if !@screen[y]? content += "\n" if !@screen[y]?
continue if !@screen[y]? continue if !@screen[y]?
for x in [0..@getWidth() - 1] for x in [0...@getWidth()]
pixel = @screen[y][x] pixel = @screen[y][x]
if !pixel? if !pixel?
pixel = { ch: ' ', attr: 7 } pixel = { ch: ' ', attr: 7 }
@ -1067,17 +1074,17 @@ class @ImageTextModeANSI extends @ImageTextMode
prevattr = attr prevattr = attr
content += if pixel.ch? then pixel.ch else ' ' content += if pixel.ch? then pixel.ch else ' '
max_x = x max_x = x
#content += "\n"
#content += ANSI_CSI + ANSI_RETURN # go to the next line
content += "#{ ANSI_CSI }0m" content += "#{ ANSI_CSI }0m"
@toBinaryArray(content) @toBinaryArray(content)
gen_args: ( attr ) -> gen_args: ( attr ) ->
fg = 30 + ( attr & 7 ) fg = 30 + ( attr & 7 )
bg = 40 + ( ( attr & 112 ) >> 4) bg = 40 + ( ( attr & 112 ) >> 4)
bl = if attr & 128 then 5 else '' bl = if attr & 128 then 5 else ''
intense = if attr & 8 then 1 else '' intense = if attr & 8 then 1 else ''
# um why do we make this attrs variable and not use it?
attrs = a for a in [fg, bg, bl, intense] when a != '' attrs = a for a in [fg, bg, bl, intense] when a != ''
return [fg, bg, bl, intense].join(";") return [fg, bg, bl, intense].join(";")