summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-02-07 23:40:46 -0500
committerJules Laplace <jules@okfoc.us>2015-02-07 23:40:46 -0500
commit2b040e6b7ce737e3f0eab8a25996fc2f71540713 (patch)
treeb667330fea12c079cdf8e0feefa34d06e0e6a227 /js
parentebe49c97523205a7764182c45fa213aae79e844e (diff)
load in color codes from sally HTML
Diffstat (limited to 'js')
-rw-r--r--js/clipboard.js40
-rw-r--r--js/color.js19
2 files changed, 58 insertions, 1 deletions
diff --git a/js/clipboard.js b/js/clipboard.js
index 6169b56..af368a5 100644
--- a/js/clipboard.js
+++ b/js/clipboard.js
@@ -87,13 +87,51 @@ var clipboard = (function () {
},
import_html: function () {
+ var alphabet = {}
+ toArray("ABCDEFGHIJKLMNOP").forEach(function(c,i){ alphabet[c] = i })
+
var rapper = document.createElement("div")
rapper.innerHTML = import_textarea.value
var lines = rapper.innerText.split("\n")
var width = lines.reduce(function(a,b){ return Math.max(a, b.length) })
var height = lines.length
zz = rapper.children
- rapper
+ var y = 0;
+ toArray(rapper.children).forEach(function(span){
+ if (span.nodeName !== "SPAN") { return }
+ var x = 0;
+ var row = canvas.aa[y++]
+ if (! row) return
+ toArray(span.childNodes).forEach(function(el){
+ console.log(el)
+ if (x >= row.length) return;
+ var line, colorcode = el.nodeName;
+ if (colorcode === "SPAN") {
+ colorcode = "F" + css_lookup[el.style.color]
+ line = el.innerText
+ }
+ else if (colorcode === "#text") {
+ colorcode = "FA"
+ line = el.nodeValue
+ }
+ else {
+ line = el.innerText
+ }
+ if (colorcode[0] !== "F") { return }
+ if (colorcode.length == 2) { colorcode += "BB" }
+
+ console.log(x, line)
+ for (var i = 0; i < line.length; i++, x++) {
+ var lex = row[x]
+ if (! lex) return
+ lex.char = line[i]
+ lex.fg = alphabet[ colorcode[1] ]
+ lex.bg = alphabet[ colorcode[3] ]
+ lex.opacity = 1
+ lex.build()
+ }
+ })
+ })
},
import_text: function () {
diff --git a/js/color.js b/js/color.js
index 5328095..415ce5d 100644
--- a/js/color.js
+++ b/js/color.js
@@ -32,3 +32,22 @@ function green (n) { return colors[green_names[mod(n, 3)|0]] }
function blue (n) { return colors[blue_names[mod(n, 3)|0]] }
function purple (n) { return colors[purple_names[mod(n, 4)|0]] }
function dark_gray (n) { return colors[dark_gray_names[mod(n, 4)|0]] }
+
+var css_lookup = {
+ 'rgb(255, 255, 255)': 'A',
+ 'rgb(0, 0, 0)': 'B',
+ 'rgb(0, 0, 127)': 'C',
+ 'rgb(0, 147, 0)': 'D',
+ 'red': 'E',
+ 'rgb(127, 0, 0)': 'F',
+ 'rgb(156, 0, 156)': 'G',
+ 'rgb(252, 127, 0)': 'H',
+ 'rgb(255, 255, 0)': 'I',
+ 'rgb(0, 252, 0)': 'J',
+ 'rgb(0, 147, 147)': 'K',
+ 'rgb(0, 255, 255)': 'L',
+ 'rgb(0, 0, 252)': 'M',
+ 'rgb(255, 0, 255)': 'N',
+ 'rgb(127, 127, 127)': 'O',
+ 'rgb(210, 210, 210)': 'P',
+};