Skip to content

Commit

Permalink
Merge pull request #2186 from tonycpsu/master
Browse files Browse the repository at this point in the history
Support underline and inverse in ANSI escape codes
  • Loading branch information
takluyver authored Feb 14, 2017
2 parents 0e453e7 + d3cd858 commit a33d136
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions notebook/static/base/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ define([
var fg = [];
var bg = [];
var bold = false;
var underline = false;
var inverse = false;
var match;
var out = [];
var numbers = [];
Expand Down Expand Up @@ -330,6 +332,14 @@ define([
classes.push("ansi-bold");
}

if (underline) {
classes.push("ansi-underline");
}

if (inverse) {
classes.push("ansi-inverse");
}

if (classes.length || styles.length) {
out.push("<span");
if (classes.length) {
Expand All @@ -353,11 +363,19 @@ define([
case 0:
fg = bg = [];
bold = false;
underline = false;
inverse = false;
break;
case 1:
case 5:
bold = true;
break;
case 4:
underline = true;
break;
case 7:
inverse = true;
break;
case 21:
case 22:
bold = false;
Expand Down
2 changes: 2 additions & 0 deletions notebook/static/notebook/less/ansicolors.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
.ansicolors(white, #C5C1B4, #A1A6B2);

.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
.ansi-inverse { outline: 0.5px dotted; }

/* The following styles are deprecated an will be removed in a future version */

Expand Down
36 changes: 36 additions & 0 deletions tools/tests/ANSI Test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,42 @@
"RESET = ESC + \"00m\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bold, underline and inverse text"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is normal text\n",
"\n",
"\u001b[01mThis is bold text\u001b[00m\n",
"\n",
"\u001b[04mThis is underlined text\u001b[00m\n",
"\n",
"\u001b[07mThis is inverse text\u001b[00m\n"
]
}
],
"source": [
"print (\"This is normal text\")\n",
"print()\n",
"print (\"{ESC}01mThis is bold text{RESET}\".format(**locals()))\n",
"print()\n",
"print (\"{ESC}04mThis is underlined text{RESET}\".format(**locals()))\n",
"print()\n",
"print (\"{ESC}07mThis is inverse text{RESET}\".format(**locals()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit a33d136

Please sign in to comment.