From 7d80be2bf7bfb65719dff6437959509e12487078 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Sun, 30 Nov 2014 16:53:50 -0500 Subject: import ascii art --- js/clipboard.js | 32 +++++++++++++++++++++++++++++--- js/lex.js | 2 -- js/matrix.js | 9 +++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/js/clipboard.js b/js/clipboard.js index 97261bc..5354771 100644 --- a/js/clipboard.js +++ b/js/clipboard.js @@ -36,14 +36,14 @@ var clipboard = (function () { focus() clipboard.importing = true import_button.style.display = "inline-block" - export_button.style.display = format_group.display = "none" + export_button.style.display = format_group.style.display = "none" import_textarea.value = "" }, export_mode: function () { focus() clipboard.importing = false import_button.style.display = "none" - export_button.style.display = format_group.display = "inline-block" + export_button.style.display = format_group.style.display = "inline-block" clipboard.export_data() }, import_data: function () { @@ -51,6 +51,30 @@ var clipboard = (function () { lines = data.split("\n") var width = lines.reduce(function(a,b){ return Math.max(a, b.length) }) var height = lines.length + if (width > 200) { + return alert("input too wide") + } + if (height > 200) { + return alert("input too tall") + } + canvas.clear() + lines.forEach(function(line, y){ + var row = canvas.aa[y] + if (! row) return + for (var x = 0; x < line.length; x++) { + var lex = row[x] + if (! lex) return + lex.char = line[x] + lex.fg = brush.bg + lex.build() + } + }) +// var pasted_region = new Matrix (width, height, function(x,y){ +// var lex = new Lex (x,y) +// lex.char = lines[y][x] || " " +// lex.build() +// return lex +// }) }, export_data: function () { var output @@ -76,4 +100,6 @@ var clipboard = (function () { return exports -})() \ No newline at end of file +})() + + diff --git a/js/lex.js b/js/lex.js index 29f452b..e6f1f67 100644 --- a/js/lex.js +++ b/js/lex.js @@ -90,8 +90,6 @@ Lex.prototype.demolish = function(){ this.span.parentNode.removeChild(this.span) this.span = null } - - Lex.prototype.key = function(char, keyCode) { if (! char) { return } this.char = char diff --git a/js/matrix.js b/js/matrix.js index 81ced3e..96421ff 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -114,10 +114,15 @@ Matrix.prototype.mirc = function () { Matrix.prototype.irssi = function(){ var txt = this.mirc() .replace(/\%/g, '%%') + .replace(/\\/g, '\\') .replace(/\"/g, '\\\"') + .replace(/\'/g, '\\\'') .replace(/\`/g, '\\\`') - .replace(/\\n/g, '\\n') - .replace(/\x03/g, '\\x03') + .replace(/\s+\n/g, '\n') + .replace(/\s+$/g, '\n') + .replace(/\n/g, '\\n') + .replace(/\x03/g, '\\x03'); + console.log(txt) return '/exec -out printf "' + txt + '"\n' } Matrix.prototype.expand = function(i){ -- cgit v1.2.3-70-g09d2