Last active
August 29, 2015 14:13
-
-
Save granolocks/999534a618bc9166f240 to your computer and use it in GitHub Desktop.
Pwnie Say
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| MAX_WIDTH = 40 | |
| TOP_CAP = "_" | |
| BOTTOM_CAP = "-" | |
| SINGLE_ROW_LEFT_END = "<" | |
| SINGLE_ROW_RIGHT_END = ">" | |
| MULTI_ROW_END = "|" | |
| UP_LEFT_CORNER = "/" | |
| UP_RIGHT_CORNER = "\\" | |
| BOTTOM_LEFT_CORNER = "\\" | |
| BOTTOM_RIGHT_CORNER = "/" | |
| PRINTER = Proc.new{|l,txt,r| puts(l + " " + txt + " " + r)} | |
| PHRASE = ARGV.join(" ").split("\n") | |
| # HORSE FROM: http://www.asciiworld.com/-Horses-.html | |
| PWNIE =<<HORSE | |
| \\ >>\\. | |
| \\ /_ )`. | |
| \\ / _)`^)`. _.---. _ | |
| (_,' \\ `^-)"" `.\\ | |
| | | \\ | |
| \\ / | | |
| / \\ /.___.'\\ (\\ (_ | |
| < ,"|| \\ |`. \\`-' | |
| \\\\ () )| )/ | |
| |_>|> /_] // | |
| /_] /_] | |
| HORSE | |
| chunks = PHRASE.map do |paragraph| | |
| paragraph.split(' ').each_with_object([]) do |word, collector| | |
| collector[0] ||= [] | |
| if (collector[-1].join(' ').length + 1 + word.length) > MAX_WIDTH | |
| collector << [] | |
| end | |
| collector[-1] << word | |
| end | |
| end | |
| context_max_length = chunks.map do |para| | |
| para.length == 0 ? [0] : para.map{|x|x.join(' ').length}.sort[-1] | |
| end.flatten.sort[-1] | |
| chunks.map!{|x| x.empty? ? [['']] : x} | |
| puts " " + (TOP_CAP * (context_max_length + 2)) | |
| chunks.each do |paragraph| | |
| paragraph.each do |chunk| | |
| output = chunk.join(" ").ljust(context_max_length) | |
| if chunks.length == 1 && paragraph.length == 1 | |
| PRINTER.call(SINGLE_ROW_LEFT_END, output, SINGLE_ROW_RIGHT_END) | |
| elsif chunk == chunks[0][0] | |
| PRINTER.call(UP_LEFT_CORNER, output, UP_RIGHT_CORNER) | |
| elsif chunk == chunks[-1][-1] | |
| PRINTER.call(BOTTOM_LEFT_CORNER, output, BOTTOM_RIGHT_CORNER) | |
| else | |
| PRINTER.call(MULTI_ROW_END, output, MULTI_ROW_END) | |
| end | |
| end | |
| end | |
| puts " " + (BOTTOM_CAP * (context_max_length + 2)) | |
| puts PWNIE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment