diff options
| -rw-r--r-- | index.html | 2 | ||||
| -rw-r--r-- | js/clipboard.js | 4 | ||||
| -rw-r--r-- | js/color.js | 38 | ||||
| -rw-r--r-- | js/lex.js | 5 | ||||
| -rw-r--r-- | js/matrix.js | 17 |
5 files changed, 64 insertions, 2 deletions
@@ -67,7 +67,7 @@ </div> <div id="import_rapper"> - <span id="format_el">ascii *irssi mirc</span> + <span id="format_el">ascii *irssi mirc ansi</span> <span id="import_buttons"> <button id="import_button">import</button> </span> 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 +] @@ -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){ |
