You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.6 KiB
CoffeeScript
66 lines
1.6 KiB
CoffeeScript
13 years ago
|
class AsciiIo.Renderer.Base extends Backbone.View
|
||
|
events:
|
||
|
'click': 'onClick'
|
||
|
|
||
|
initialize: (options) ->
|
||
|
@cols = options.cols
|
||
|
@lines = options.lines
|
||
|
@showCursor true
|
||
|
@startCursorBlink()
|
||
|
|
||
|
onClick: ->
|
||
|
@trigger('terminal-click')
|
||
|
|
||
12 years ago
|
render: (state) ->
|
||
|
for n, fragments of state.changes
|
||
|
c = if parseInt(n) is state.cursorY then state.cursorX else undefined
|
||
13 years ago
|
@renderLine n, fragments || [], c
|
||
13 years ago
|
|
||
|
renderLine: (n, data, cursorX) ->
|
||
|
throw '#renderLine not implemented'
|
||
|
|
||
|
afterInsertedToDom: ->
|
||
13 years ago
|
sample = $('<span class="font-sample"><span class="line"><span>M</span></span></span>')
|
||
13 years ago
|
@$el.parent().append(sample)
|
||
|
@cellWidth = sample.width()
|
||
13 years ago
|
span = sample.find('span span')
|
||
|
@cellHeight = span.height() + span.css('padding-top') + span.css('padding-bottom')
|
||
13 years ago
|
sample.remove()
|
||
13 years ago
|
@fixTerminalElementSize()
|
||
|
@fixPlayerContainerSize()
|
||
|
|
||
13 years ago
|
renderSnapshot: (text) ->
|
||
|
i = 0
|
||
|
for line in text.split("\n")
|
||
|
fragments = [[line, AsciiIo.Brush.normal()]]
|
||
|
@renderLine i, fragments, undefined
|
||
|
i++
|
||
|
|
||
13 years ago
|
fixTerminalElementSize: ->
|
||
|
|
||
|
fixPlayerContainerSize: ->
|
||
|
@$el.parent('.player').css(width: @$el.outerWidth() + 'px')
|
||
13 years ago
|
|
||
|
showCursor: (show) ->
|
||
|
throw '#showCursor not implemented'
|
||
|
|
||
|
blinkCursor: ->
|
||
|
throw '#blinkCursor not implemented'
|
||
|
|
||
|
resetCursorState: ->
|
||
|
|
||
|
startCursorBlink: ->
|
||
|
@cursorTimerId = setInterval(@blinkCursor.bind(this), 500)
|
||
|
|
||
|
stopCursorBlink: ->
|
||
|
if @cursorTimerId
|
||
|
clearInterval @cursorTimerId
|
||
|
@cursorTimerId = null
|
||
|
|
||
|
restartCursorBlink: ->
|
||
|
@stopCursorBlink()
|
||
|
@resetCursorState()
|
||
|
@startCursorBlink()
|
||
|
|
||
|
visualBell: ->
|