Cowsay

Prints an ASCII cow that speaks. Hints: For multiple words or lines, the message has to be quoted. Press SHIFT+ENTER to make a new line.

Command line interface

Syntax

  1. $ cowsay [message]

Arguments

  • message – (string, optional) The message the cow will say.
    Default: The cow will just bleat.

Example

Todo

  • Make options to use other animals

cowsay.js

  1. /**
  2. * Cowsay
  3. **/
  4. TinyShell.plugins.cowsay = new Class({
  5. description: "Express yourself as a cow",
  6. run : function(t, args, line) {
  7. var text = (args.length ? args[0] : "Moooh ?!").split("\n");
  8. var rows = text.length;
  9. var cols = 0;
  10. for (var i = 0; i < rows; i++) if (text[i].length > cols) cols = text[i].length;
  11. t.print();
  12. t.print(" _"+this.repeat("_", cols)+"_ ");
  13. for (var i = 0; i < rows; i++) t.print(" "+(rows<2?"<":!i?"/":i+1<rows?"|":"\\")+" "+text[i]+this.repeat(" ", cols-text[i].length)+" "+(rows<2?">":!i?"\\":i+1<rows?"|":"/"));
  14. t.print(" -"+this.repeat("-", cols)+"- ");
  15. t.print(" \\ ^__^");
  16. t.print(" \\ (oo)\\_______");
  17. t.print(" (__)\\ )\\/\\");
  18. t.print(" ||----w |");
  19. t.print(" || ||");
  20. t.print();
  21. t.resume();
  22. },
  23. repeat: function(str, n) {
  24. var space = "";
  25. for (var i = 0; i < n; i++) space += str;
  26. return space;
  27. }
  28. });

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>