From da41cc8faa8e38fedf26e1c4c711bd00cef92482 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 21 Nov 2016 19:56:44 -0500 Subject: exporting escape codes --- index.html | 2 +- js/clipboard.js | 4 +++- js/color.js | 38 ++++++++++++++++++++++++++++++++++++++ js/lex.js | 5 +++++ js/matrix.js | 17 +++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index d5a99e3..5a41fe2 100644 --- a/index.html +++ b/index.html @@ -67,7 +67,7 @@
- ascii *irssi mirc + ascii *irssi mirc ansi diff --git a/js/clipboard.js b/js/clipboard.js index 9c3b1b2..fc47740 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -71,7 +71,6 @@ var clipboard = (function () { console.error("unknown type!", item.type) } }) - }, import_colorcode: function (data, no_undo) { @@ -174,6 +173,9 @@ var clipboard = (function () { case 'irssi': output = canvas.irssi({cutoff: 400}) break + case 'ansi': + output = canvas.ansi() + break } if (output.cutoff){ cutoff_warning_el.style.display = 'block' diff --git a/js/color.js b/js/color.js index 0ba29e7..c518327 100644 --- a/js/color.js +++ b/js/color.js @@ -66,3 +66,41 @@ var css_reverse_lookup = {} Object.keys(css_lookup).forEach(function(color){ css_reverse_lookup[ css_lookup[color].charCodeAt(0) - 65 ] = color }) + +var ansi_fg = [ + 97, // white + 30, // black + 34, // dark blue + 32, // green + 91, // light red + 31, // dark red + 35, // purple + 33, // "dark yellow" (orange?) + 93, // "light yellow" + 92, // light green + 36, // cyan (teal?) + 96, // light cyan + 94, // light blue + 95, // light magenta + 90, // dark gray + 37, // light gray +] + +var ansi_bg = [ + 107, // white + 40, // black + 44, // dark blue + 42, // green + 101, // light red + 41, // dark red + 45, // purple + 43, // yellow (orange) + 103, // light yellow + 102, // light green + 46, // cyan (teal?) + 106, // light cyan + 104, // light blue + 105, // light magenta + 100, // dark gray + 47, // light gray +] diff --git a/js/lex.js b/js/lex.js index 20c801b..4c11351 100644 --- a/js/lex.js +++ b/js/lex.js @@ -60,6 +60,11 @@ Lex.prototype.mirc = function(){ return "\x03" + (this.fg&15) + "," + (this.bg&15) + char } } +Lex.prototype.ansi = function(){ + var fg = ansi_fg[ this.fg&15 ] + var bg = ansi_bg[ this.bg&15 ] + return "\\e[" + fg + ";" + bg + "m" + this.sanitize() +} Lex.prototype.assign = function (lex){ this.fg = lex.fg this.bg = lex.bg diff --git a/js/matrix.js b/js/matrix.js index 1aeb929..dbc76c7 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -250,6 +250,23 @@ Matrix.prototype.ascii = function () { var txt = lines.join("\n") return txt } +Matrix.prototype.ansi = function (opts) { + var lines = this.aa.map(function(row, y){ + var last, line = "" + row.forEach(function(lex, x) { + if (lex.eqColor(last)) { + line += lex.sanitize() + } + else { + line += lex.ansi() + last = lex + } + }) + return line + }) + var txt = lines.filter(function(line){ return line.length > 0 }).join('\\e[0m\\n') + "\\e[0m" + return 'echo -e "' + txt + '"' +} Matrix.prototype.mirc = function (opts) { var cutoff = false var lines = this.aa.map(function(row, y){ -- cgit v1.2.3-70-g09d2