Python scripts I use to manage my ssh connections, drive mounts, and other bash related things.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

  1. #!/usr/bin/env node
  2. (function () {
  3. var DEFAULT_LEN, ROO, BUBBLE_TOP_CHAR,
  4. textToRoo;
  5. DEFAULT_LEN = 35;
  6. BUBBLE_TOP_CHAR = "-";
  7. roo = `
  8. \\ /)/)
  9. \\ (ø.ø)
  10. \\ ( />
  11. __/ _\\ //
  12. '~( '~ )//
  13. _\\ '}/
  14. \\"--~(/`;
  15. function lineify(maxLen) {
  16. function bar([word, ...words], [line, ...lines]) {
  17. if (!word) return [pad(line), ...lines];
  18. word = word.trim();
  19. if (!line) return bar(words, [word, ...lines]);
  20. return bar(words, (word.length + line.length < maxLen)
  21. ? [[line, word].join(" "), ...lines]
  22. : [word, pad(line), ...lines]);
  23. }
  24. function pad(line) {
  25. return line + new Array(maxLen - line.length).fill(" ").join("");
  26. }
  27. return (s => bar(s.split(" "), [""]).reverse());
  28. }
  29. function rooify(text) {
  30. var textLines, finalOutput, bubbleHeader;
  31. finalOutput = "";
  32. textLines = lineify(DEFAULT_LEN)(text);
  33. bubbleHeader = new Array(DEFAULT_LEN+2).fill(BUBBLE_TOP_CHAR).join("");
  34. finalOutput += "/" + bubbleHeader + "\\\n";
  35. textLines.forEach(l => finalOutput += "| " + l + " |\n");
  36. finalOutput += "\\" + bubbleHeader + "/";
  37. finalOutput += roo;
  38. return finalOutput;
  39. }
  40. if (process.stdin.isTTY) {
  41. textToRoo = process.argv.splice(2).join(" ");
  42. console.log(rooify(textToRoo));
  43. } else {
  44. textToRoo = "";
  45. process.stdin.on('data', b => textToRoo += b.toString());
  46. process.stdin.on('end', _ => console.log(rooify(textToRoo)));
  47. process.stdin.resume();
  48. }
  49. }());