diff --git a/app/assets/javascripts/player/terminal_view.js.coffee b/app/assets/javascripts/player/terminal_view.js.coffee index 974537e..a0b1f0f 100644 --- a/app/assets/javascripts/player/terminal_view.js.coffee +++ b/app/assets/javascripts/player/terminal_view.js.coffee @@ -37,41 +37,51 @@ class AsciiIo.TerminalView extends Backbone.View @renderLine n, data || [], c renderLine: (n, data, cursorX) -> - html = [] + html = '' i = 0 + prevBrush = undefined for d in data if d [char, brush] = d - html[i] = @createSpan(char, brush, i is cursorX) + + if brush != prevBrush or i is cursorX or i is (cursorX + 1) + if prevBrush + html += '' + + html += @createSpan(brush, i is cursorX) + + prevBrush = brush + + html += char else - html[i] = ' ' + html += ' ' i++ - @$el.find(".line:eq(" + n + ")").html html.join("") + html += '' if html.length > 0 + + @$el.find(".line:eq(" + n + ")").html html #.join("") - createSpan: (char, brush, hasCursor) -> - prefix = "" - postfix = "" + createSpan: (brush, hasCursor) -> + span = "" if hasCursor or brush.fg isnt undefined or brush.bg isnt undefined or brush.bright or brush.underline - prefix = "" - postfix = "" + span += " bg" + brush.bg if brush.bg isnt undefined + span += " cursor visible" if hasCursor + span += "\">" - prefix + char + postfix + span showCursor: (show) -> if show