From c3f3da13183e994db9823928df976a609e519dad Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 19 Feb 2012 15:12:56 +0100 Subject: [PATCH] Tab stop support --- app/assets/javascripts/player/vt.js.coffee | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/player/vt.js.coffee b/app/assets/javascripts/player/vt.js.coffee index b872d0b..aee9a02 100644 --- a/app/assets/javascripts/player/vt.js.coffee +++ b/app/assets/javascripts/player/vt.js.coffee @@ -166,6 +166,7 @@ class AsciiIo.VT "\x1bP([^\\\\])*?\\\\": (data) -> # DCS, Device Control String "\x1bD": -> @index() "\x1bE": -> @newLine() + "\x1bH": -> @setHorizontalTabStop() "\x1bM": -> @reverseIndex() "\x1b7": (data) -> # save cursor pos and char attrs @@ -224,7 +225,6 @@ class AsciiIo.VT @eraseCharacters @n when "Z" @goToPriorHorizontalTabStop @n - when "b" @repeatLastCharacter @n when "d" # VPA - Vertical Position Absolute @@ -484,15 +484,43 @@ class AsciiIo.VT @goToColumn col setHorizontalTabStop: -> - # @tabStops << @cursorX + unless _(@tabStops).include(@cursorX) + pos = _(@tabStops).sortedIndex(@cursorX) + @tabStops.splice(pos, 0, @cursorX) + + goToNextHorizontalTabStop: (n) -> + x = @getNextTabStop() + @goToRowAndColumn(@cursorY + 1, x + 1) + @updateLine() + + goToPriorHorizontalTabStop: (n) -> + x = @getPriorTabStop() + @goToRowAndColumn(@cursorY + 1, x + 1) + @updateLine() + + getNextTabStop: -> + for x in @tabStops + if x > @cursorX + return x + + @cols + + getPriorTabStop: -> + ret = 0 + + for x in @tabStops + if x > @cursorX + break - goToNextHorizontalTabStop: -> + ret = x - goToPriorHorizontalTabStop: -> + ret clearHorizontalTabStop: -> + console.log 'clearHorizontalTabStop' clearAllHorizontalTabStops: -> + console.log 'clearAllHorizontalTabStops' saveCursor: -> @savedCol = @cursorX @@ -605,6 +633,7 @@ class AsciiIo.VT @lineData = @normalBuffer @dirtyLines = {} @brush = AsciiIo.Brush.create({}) + @tabStops = (x for x in [0...@cols] when x % 8 is 0) @fg = @bg = undefined @bright = false