Extract SGR codes interpretation to separate class
parent
3371a238b7
commit
6eeafdf699
@ -0,0 +1,60 @@
|
||||
class AsciiIo.SgrInterpreter
|
||||
|
||||
reset: ->
|
||||
@attrs =
|
||||
fg : undefined
|
||||
bg : undefined
|
||||
blink : false
|
||||
bright : false
|
||||
italic : false
|
||||
underline: false
|
||||
|
||||
buildBrush: (oldBrush, numbers) ->
|
||||
@attrs =
|
||||
fg : oldBrush.fg
|
||||
bg : oldBrush.bg
|
||||
blink : oldBrush.blink
|
||||
bright : oldBrush.bright
|
||||
italic : oldBrush.italic
|
||||
underline: oldBrush.underline
|
||||
|
||||
numbers = [0] if numbers.length is 0
|
||||
|
||||
i = 0
|
||||
while i < numbers.length
|
||||
n = numbers[i]
|
||||
|
||||
if n is 0
|
||||
@reset()
|
||||
else if n is 1
|
||||
@attrs.bright = true
|
||||
else if n is 3
|
||||
@attrs.italic = true
|
||||
else if n is 4
|
||||
@attrs.underline = true
|
||||
else if n is 5
|
||||
@attrs.blink = true
|
||||
else if n is 23
|
||||
@attrs.italic = false
|
||||
else if n is 24
|
||||
@attrs.underline = false
|
||||
else if n is 25
|
||||
@attrs.blink = false
|
||||
else if n >= 30 and n <= 37
|
||||
@attrs.fg = n - 30
|
||||
else if n is 38
|
||||
@attrs.fg = numbers[i + 2]
|
||||
i += 2
|
||||
else if n is 39
|
||||
@attrs.fg = undefined
|
||||
else if n >= 40 and n <= 47
|
||||
@attrs.bg = n - 40
|
||||
else if n is 48
|
||||
@attrs.bg = numbers[i + 2]
|
||||
i += 2
|
||||
else if n is 49
|
||||
@attrs.bg = undefined
|
||||
|
||||
i++
|
||||
|
||||
AsciiIo.Brush.create @attrs
|
@ -0,0 +1,6 @@
|
||||
describe 'AsciiIo.SgrInterpreter', ->
|
||||
|
||||
describe '#reset', ->
|
||||
|
||||
describe '#buildBrush', ->
|
||||
|
Loading…
Reference in New Issue