summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-21 19:56:44 -0500
committerJules Laplace <jules@okfoc.us>2016-11-21 19:56:44 -0500
commitda41cc8faa8e38fedf26e1c4c711bd00cef92482 (patch)
tree30f8779177532acb96f2d5d7a82def1e0e5d8d1a
parent9043d36f00094c94f45fb24057886d943463bef9 (diff)
exporting escape codes
-rw-r--r--index.html2
-rw-r--r--js/clipboard.js4
-rw-r--r--js/color.js38
-rw-r--r--js/lex.js5
-rw-r--r--js/matrix.js17
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 @@
</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
+]
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){