Add cowsay functionality
This commit is contained in:
parent
5d73082493
commit
a6783ea51a
1 changed files with 58 additions and 1 deletions
|
@ -1,5 +1,62 @@
|
||||||
module cowsay
|
module cowsay
|
||||||
|
|
||||||
# Write your package code here.
|
export cowsay_function
|
||||||
|
|
||||||
|
function cowsay_function(message::AbstractString)
|
||||||
|
messagelines = split(message, "\n")
|
||||||
|
nlines = length(messagelines)
|
||||||
|
|
||||||
|
linelength = max(length.(messagelines)...)
|
||||||
|
paddinglength = linelength + 2
|
||||||
|
|
||||||
|
if nlines == 1
|
||||||
|
balloon = string(
|
||||||
|
" ",
|
||||||
|
repeat("_", paddinglength),
|
||||||
|
"\n< ",
|
||||||
|
message,
|
||||||
|
" >\n ",
|
||||||
|
repeat("-", paddinglength),
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
balloon = string(
|
||||||
|
" ",
|
||||||
|
repeat("_", paddinglength),
|
||||||
|
"\n/ ",
|
||||||
|
rpad(messagelines[1], linelength),
|
||||||
|
" \\\n"
|
||||||
|
)
|
||||||
|
if nlines > 2
|
||||||
|
for i=2:nlines-1
|
||||||
|
balloon = string(
|
||||||
|
balloon,
|
||||||
|
"| ",
|
||||||
|
rpad(messagelines[i], linelength),
|
||||||
|
" |\n"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
balloon = string(
|
||||||
|
balloon,
|
||||||
|
"\\ ",
|
||||||
|
rpad(messagelines[end], linelength),
|
||||||
|
" /\n ",
|
||||||
|
repeat("-", paddinglength),
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
cow = string(
|
||||||
|
" \\ ^__^\n",
|
||||||
|
" \\ (oo)\\_______\n",
|
||||||
|
" (__)\\ )\\/\\\n",
|
||||||
|
" ||----w |\n",
|
||||||
|
" || ||"
|
||||||
|
)
|
||||||
|
|
||||||
|
println(string(balloon, cow))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue