Add various SGR (add italic / crossed out / fainted support). Support resize in alternate buffer.

This commit is contained in:
Florian Mounier
2015-10-06 14:05:14 +02:00
parent cf5051d414
commit 909bcfa9f4
7 changed files with 187 additions and 28 deletions

View File

@@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '2.0.0'
__version__ = '2.0.2'
import os

View File

@@ -21,12 +21,24 @@
.underline
text-decoration: underline
.italic
font-style: italic
.faint
text-opacity: .6
.crossed
text-decoration: line-through
/* Not supported, emulated
/* .blink
/* text-decoration: blink
.blink
animation: blink 1s ease-in-out infinite
.blink-fast
animation: blink 250ms ease-in-out infinite
@keyframes blink
0%
opacity: 1

View File

@@ -3098,12 +3098,24 @@ body {
.underline, .nbsp {
text-decoration: underline; }
.italic {
font-style: italic; }
.faint {
text-opacity: .6; }
.crossed {
text-decoration: line-through; }
/* Not supported, emulated */
/* .blink */
/* text-decoration: blink */
.blink {
animation: blink 1s ease-in-out infinite; }
.blink-fast {
animation: blink 250ms ease-in-out infinite; }
@keyframes blink {
0% {
opacity: 1; }

View File

@@ -214,12 +214,15 @@
underline: a.underline,
blink: a.blink,
inverse: a.inverse,
invisible: a.invisible
invisible: a.invisible,
italic: a.italic,
faint: a.faint,
crossed: a.crossed
};
};
Terminal.prototype.equalAttr = function(a, b) {
return a.bg === b.bg && a.fg === b.fg && a.bold === b.bold && a.underline === b.underline && a.blink === b.blink && a.inverse === b.inverse && a.invisible === b.invisible;
return a.bg === b.bg && a.fg === b.fg && a.bold === b.bold && a.underline === b.underline && a.blink === b.blink && a.inverse === b.inverse && a.invisible === b.invisible && a.italic === b.italic && a.faint === b.faint && a.crossed === b.crossed;
};
Terminal.prototype.putChar = function(c) {
@@ -257,9 +260,12 @@
ch: " ",
bold: false,
underline: false,
blink: false,
blink: 0,
inverse: false,
invisible: false
invisible: false,
italic: false,
faint: false,
crossed: false
};
this.curAttr = this.cloneAttr(this.defAttr);
this.params = [];
@@ -553,15 +559,27 @@
if (data.underline) {
classes.push("underline");
}
if (data.blink) {
if (data.blink === 1) {
classes.push("blink");
}
if (data.blink === 2) {
classes.push("blink-fast");
}
if (data.inverse) {
classes.push("reverse-video");
}
if (data.invisible) {
classes.push("invisible");
}
if (data.italic) {
classes.push("italic");
}
if (data.faint) {
classes.push("faint");
}
if (data.crossed) {
classes.push("crossed");
}
if (typeof data.fg === 'number') {
fg = data.fg;
if (data.bold && fg < 8) {
@@ -1692,6 +1710,38 @@
}
}
}
if (this.normal) {
if (oldCols < this.cols) {
i = this.normal.screen.length;
while (i--) {
while (this.normal.screen[i].chars.length < this.cols) {
this.normal.screen[i].chars.push(this.defAttr);
}
this.normal.screen[i].wrap = false;
}
} else if (oldCols > this.cols) {
i = this.normal.screen.length;
while (i--) {
while (this.normal.screen[i].chars.length > this.cols) {
this.normal.screen[i].chars.pop();
}
}
}
j = oldRows;
if (j < this.rows) {
while (j++ < this.rows) {
if (this.normal.screen.length < this.rows) {
this.normal.screen.push(this.blankLine());
}
}
} else if (j > this.rows) {
while (j-- > this.rows) {
if (this.normal.screen.length > this.rows) {
this.normal.screen.pop();
}
}
}
}
if (this.y >= this.rows) {
this.y = this.rows - 1;
}
@@ -1701,7 +1751,6 @@
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
this.refresh(true);
this.normal = null;
if (x || y) {
return this.reset();
}
@@ -1996,18 +2045,31 @@
this.curAttr = this.cloneAttr(this.defAttr);
} else if (p === 1) {
this.curAttr.bold = true;
} else if (p === 2) {
this.curAttr.faint = true;
} else if (p === 3) {
this.curAttr.italic = true;
} else if (p === 4) {
this.curAttr.underline = true;
} else if (p === 5) {
this.curAttr.blink = true;
this.curAttr.blink = 1;
} else if (p === 6) {
this.curAttr.blink = 2;
} else if (p === 7) {
this.curAttr.inverse = true;
} else if (p === 8) {
this.curAttr.invisible = true;
} else if (p === 9) {
this.curAttr.crossed = true;
} else if (p === 10) {
void 0;
} else if (p === 21) {
this.curAttr.bold = false;
} else if (p === 22) {
this.curAttr.bold = false;
this.curAttr.faint = false;
} else if (p === 23) {
this.curAttr.italic = false;
} else if (p === 24) {
this.curAttr.underline = false;
} else if (p === 25) {
@@ -2016,6 +2078,8 @@
this.curAttr.inverse = false;
} else if (p === 28) {
this.curAttr.invisible = false;
} else if (p === 29) {
this.curAttr.crossed = false;
} else if (p === 39) {
this.curAttr.fg = 257;
} else if (p === 49) {
@@ -2345,7 +2409,8 @@
shift: this.shift,
scrollTop: this.scrollTop,
scrollBottom: this.scrollBottom,
tabs: this.tabs
tabs: this.tabs,
curAttr: this.curAttr
};
this.reset();
this.normal = normal;
@@ -2423,6 +2488,7 @@
this.scrollTop = this.normal.scrollTop;
this.scrollBottom = this.normal.scrollBottom;
this.tabs = this.normal.tabs;
this.curAttr = this.normal.curAttr;
this.normal = null;
this.refresh(true);
return this.showCursor();

File diff suppressed because one or more lines are too long

View File

@@ -213,6 +213,9 @@ class Terminal(object):
args = [tornado.options.options.shell or self.callee.shell]
args.append('-i')
# In some cases some shells don't export SHELL var
env['SHELL'] = args[0]
os.execvpe(args[0], args, env)
# This process has been replaced

View File

@@ -111,12 +111,17 @@ class Terminal
blink: a.blink
inverse: a.inverse
invisible: a.invisible
italic: a.italic
faint: a.faint
crossed: a.crossed
equalAttr: (a, b) ->
# Not testing char
(a.bg is b.bg and a.fg is b.fg and a.bold is b.bold and
a.underline is b.underline and a.blink is b.blink and
a.inverse is b.inverse and a.invisible is b.invisible)
a.inverse is b.inverse and a.invisible is b.invisible and
a.italic is b.italic and a.faint is b.faint and
a.crossed is b.crossed)
putChar: (c) ->
if @insertMode
@@ -158,9 +163,12 @@ class Terminal
ch: " "
bold: false
underline: false
blink: false
blink: 0
inverse: false
invisible: false
italic: false
faint: false
crossed: false
@curAttr = @cloneAttr @defAttr
@params = []
@@ -426,11 +434,18 @@ class Terminal
# underline
classes.push "underline" if data.underline
# blink
classes.push "blink" if data.blink
classes.push "blink" if data.blink is 1
classes.push "blink-fast" if data.blink is 2
# inverse
classes.push "reverse-video" if data.inverse
# invisible
classes.push "invisible" if data.invisible
# italic
classes.push "italic" if data.italic
# faint
classes.push "faint" if data.faint
# crossed
classes.push "crossed" if data.crossed
if typeof data.fg is 'number'
fg = data.fg
@@ -1571,6 +1586,31 @@ class Terminal
el = @children.pop()
el?.parentNode.removeChild el
if @normal
# resize cols
if oldCols < @cols
# does xterm use the default attr?
i = @normal.screen.length
while i--
while @normal.screen[i].chars.length < @cols
@normal.screen[i].chars.push @defAttr
@normal.screen[i].wrap = false
else if oldCols > @cols
i = @normal.screen.length
while i--
while @normal.screen[i].chars.length > @cols
@normal.screen[i].chars.pop()
# resize rows
j = oldRows
if j < @rows
while j++ < @rows
@normal.screen.push @blankLine() if @normal.screen.length < @rows
else if j > @rows
while j-- > @rows
@normal.screen.pop() if @normal.screen.length > @rows
# make sure the cursor stays on screen
@y = @rows - 1 if @y >= @rows
@x = @cols - 1 if @x >= @cols
@@ -1579,12 +1619,6 @@ class Terminal
@scrollBottom = @rows - 1
@refresh(true)
# it's a real nightmare trying
# to resize the original
# screen buffer. just set it
# to null for now.
@normal = null
@reset() if x or y
resizeWindowPlease: (cols) ->
@@ -1786,17 +1820,26 @@ class Terminal
# CSI Pm m Character Attributes (SGR).
# Ps = 0 -> Normal (default).
# Ps = 1 -> Bold.
# Ps = 4 -> Underlined.
# Ps = 5 -> Blink (appears as Bold).
# Ps = 7 -> Inverse.
# Ps = 8 -> Invisible, i.e., hidden (VT300).
# Ps = 0 -> Normal (default).
# Ps = 1 -> Bold.
# Ps = 2 -> Faint
# Ps = 3 -> Italic
# Ps = 4 -> Underlined.
# Ps = 5 -> Blink.
# Ps = 6 -> Blink rapid
# Ps = 7 -> Inverse.
# Ps = 8 -> Invisible, i.e., hidden (VT300).
# Ps = 9 -> Crossed out
# Ps = 1 0 -> Primary font
# Ps = 2 1 -> Bold off
# Ps = 2 2 -> Normal (neither bold nor faint).
# Ps = 2 3 -> Non italic
# Ps = 2 4 -> Not underline.
# Ps = 2 5 -> Steady (not blinking).
# Ps = 2 7 -> Positive (not inverse).
# Ps = 2 8 -> Visible, i.e., not hidden (VT300).
# Ps = 2 9 -> Not crossed out
# Ps = 3 0 -> Set foreground color to Black.
# Ps = 3 1 -> Set foreground color to Red.
# Ps = 3 2 -> Set foreground color to Green.
@@ -1876,12 +1919,21 @@ class Terminal
else if p is 1
# bold text
@curAttr.bold = true
else if p is 2
# bold text
@curAttr.faint = true
else if p is 3
# italic text
@curAttr.italic = true
else if p is 4
# underline text
@curAttr.underline = true
else if p is 5
# blink
@curAttr.blink = true
@curAttr.blink = 1
else if p is 6
# blink fast
@curAttr.blink = 2
else if p is 7
# inverse and positive
# test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
@@ -1889,13 +1941,23 @@ class Terminal
else if p is 8
# invisible
@curAttr.invisible = true
else if p is 9
# crossed out
@curAttr.crossed = true
else if p is 10
# Primary Font
# ignoring
undefined
else if p is 21
# bold off
@curAttr.bold = false
else if p is 22
# not bold
@curAttr.bold = false
@curAttr.faint = false
else if p is 23
# not italic
@curAttr.italic = false
else if p is 24
# not underline
@curAttr.underline = false
@@ -1908,6 +1970,9 @@ class Terminal
else if p is 28
# not invisible
@curAttr.invisible = false
else if p is 29
# not crossed out
@curAttr.crossed = false
else if p is 39
# reset fg
@curAttr.fg = 257
@@ -2353,6 +2418,7 @@ class Terminal
scrollTop: @scrollTop
scrollBottom: @scrollBottom
tabs: @tabs
curAttr: @curAttr
@reset()
@normal = normal
@showCursor()
@@ -2495,11 +2561,11 @@ class Terminal
@scrollTop = @normal.scrollTop
@scrollBottom = @normal.scrollBottom
@tabs = @normal.tabs
@curAttr = @normal.curAttr
@normal = null
@refresh(true)
@showCursor()
# CSI Ps ; Ps r
# Set Scrolling Region [top;bottom] (default = full size of win-
# dow) (DECSTBM).