From 1aaa4f818ec4f992455d85fc7b842d48586e2368 Mon Sep 17 00:00:00 2001 From: Tim Rollet Date: Tue, 10 Oct 2017 01:46:06 -0400 Subject: [PATCH 1/3] Add javascript roosay --- src/roosay.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/roosay.js diff --git a/src/roosay.js b/src/roosay.js new file mode 100644 index 0000000..4f6167c --- /dev/null +++ b/src/roosay.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +(function () { + + var DEFAULT_LEN, ROO, BUBBLE_TOP_CHAR, + textToRoo; + + DEFAULT_LEN = 35; + + BUBBLE_TOP_CHAR = "-"; + + roo = ` + \\ /)/) + \\ (ø.ø) + \\ ( /> + __/ _\\ // + '~( '~ )// + _\\ '}/ + \\"--~(/ + `; + + function lineify(maxLen) { + function bar([word, ...words], [line, ...lines]) { + if (!word) return [pad(line), ...lines]; + word = word.trim(); + if (!line) return bar(words, [word, ...lines]); + return bar(words, (word.length + line.length < maxLen) + ? [[line, word].join(" "), ...lines] + : [word, pad(line), ...lines]); + } + function pad(line) { + return line + new Array(maxLen - line.length).fill(" ").join(""); + } + return (s => bar(s.split(" "), [""]).reverse()); + } + + function rooify(text) { + var textLines, maxLineLength, finalOutput, bubbleHeader; + finalOutput = ""; + textLines = lineify(DEFAULT_LEN)(text); + bubbleHeader = new Array(DEFAULT_LEN+2).fill(BUBBLE_TOP_CHAR).join(""); + finalOutput += "/" + bubbleHeader + "\\\n"; + textLines.forEach(l => finalOutput += "| " + l + " |\n"); + finalOutput += "\\" + bubbleHeader + "/"; + finalOutput += roo; + return finalOutput; + } + if (process.stdin.isTTY) { + textToRoo = process.argv.splice(2).join(" "); + console.log(rooify(textToRoo)); + } else { + textToRoo = ""; + process.stdin.on('data', b => textToRoo += b.toString()); + process.stdin.on('end', _ => console.log(rooify(textToRoo))); + process.stdin.resume(); + } + + module.exports = {lineify}; +}()); \ No newline at end of file From 7ae198b238b1b31e0a56811356378733fe6a44f0 Mon Sep 17 00:00:00 2001 From: Tim Rollet Date: Tue, 10 Oct 2017 01:58:53 -0400 Subject: [PATCH 2/3] Spruce up around the edges. --- src/roosay.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/roosay.js b/src/roosay.js index 4f6167c..c760519 100644 --- a/src/roosay.js +++ b/src/roosay.js @@ -1,11 +1,9 @@ #!/usr/bin/env node (function () { - var DEFAULT_LEN, ROO, BUBBLE_TOP_CHAR, textToRoo; DEFAULT_LEN = 35; - BUBBLE_TOP_CHAR = "-"; roo = ` @@ -34,7 +32,7 @@ } function rooify(text) { - var textLines, maxLineLength, finalOutput, bubbleHeader; + var textLines, finalOutput, bubbleHeader; finalOutput = ""; textLines = lineify(DEFAULT_LEN)(text); bubbleHeader = new Array(DEFAULT_LEN+2).fill(BUBBLE_TOP_CHAR).join(""); @@ -44,6 +42,7 @@ finalOutput += roo; return finalOutput; } + if (process.stdin.isTTY) { textToRoo = process.argv.splice(2).join(" "); console.log(rooify(textToRoo)); @@ -53,6 +52,4 @@ process.stdin.on('end', _ => console.log(rooify(textToRoo))); process.stdin.resume(); } - - module.exports = {lineify}; }()); \ No newline at end of file From 8e872f733c379aec148c2adba73bf15738fa5614 Mon Sep 17 00:00:00 2001 From: Tim Rollet Date: Tue, 10 Oct 2017 02:00:12 -0400 Subject: [PATCH 3/3] Remove an extra roo-line. --- src/roosay.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/roosay.js b/src/roosay.js index c760519..966b88c 100644 --- a/src/roosay.js +++ b/src/roosay.js @@ -13,8 +13,7 @@ __/ _\\ // '~( '~ )// _\\ '}/ - \\"--~(/ - `; + \\"--~(/`; function lineify(maxLen) { function bar([word, ...words], [line, ...lines]) {