From 3334442bbc7520bf091ed37e28a1898685691582 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 10 Dec 2017 00:22:41 -0400 Subject: Interpret 'off' SGR commands in ANSI interpreter --- util/ansi.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'util/ansi.js') diff --git a/util/ansi.js b/util/ansi.js index f3f4cbe..c796a2e 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -137,6 +137,12 @@ const ansi = { for (let charI = 0; charI < text.length; charI++) { if (text[charI] === ESC) { + if (false) { + chars[getCursorIndex()] = {char: '%', attributes: []} + cursorCol++ + continue + } + charI++ if (text[charI] !== '[') { @@ -213,9 +219,39 @@ const ansi = { // SGR - Select Graphic Rendition if (text[charI] === 'm') { - for (let arg of args) { + const removeAttribute = attr => { + if (attributes.includes(attr)) { + attributes.splice(attributes.indexOf(attr), 1) + } + } + + for (const arg of args) { if (arg === '0') { attributes.splice(0, attributes.length) + } else if (arg === '22') { // Neither bold nor faint + removeAttribute('1') + removeAttribute('2') + } else if (arg === '23') { // Neither italic nor Fraktur + removeAttribute('3') + removeAttribute('20') + } else if (arg === '24') { // Not underlined + removeAttribute('4') + } else if (arg === '25') { // Blink off + removeAttribute('5') + } else if (arg === '27') { // Inverse off + removeAttribute('7') + } else if (arg === '28') { // Conceal off + removeAttribute('8') + } else if (arg === '29') { // Not crossed out + removeAttribute('9') + } else if (arg === '39') { // Default foreground + for (let i = 0; i < 10; i++) { + removeAttribute('3' + i) + } + } else if (arg === '49') { // Default background + for (let i = 0; i < 10; i++) { + removeAttribute('4' + i) + } } else { attributes.push(arg) } @@ -261,7 +297,7 @@ const ansi = { //let n = 1 // debug - for (let char of chars) { + for (const char of chars) { const newAttributes = ( char.attributes.filter(attr => !(lastChar.attributes.includes(attr))) ) -- cgit 1.3.0-6-gf8a5