Add cowsaid function for returning cow art strings

This commit is contained in:
Thomas A. Christensen II 2022-02-01 15:55:56 -06:00
parent b068326b2e
commit d8a67143b3
Signed by: millironx
GPG key ID: 139C07724802BC5D

View file

@ -2,6 +2,7 @@ module Cowsay
export cowsay export cowsay
export cowthink export cowthink
export cowsaid
include("cows/blowfish.cow.jl") include("cows/blowfish.cow.jl")
include("cows/bunny.cow.jl") include("cows/bunny.cow.jl")
@ -77,8 +78,7 @@ julia> cowthink("Have I mooed today?")
``` ```
""" """
function cowsay(message::AbstractString; cow=default, eyes="oo", tongue=" ") function cowsay(message::AbstractString; cow=default, eyes="oo", tongue=" ")
balloon = sayballoon(message) println(cowsaid(message, cow=cow, eyes=eyes, tongue=tongue))
println(string(balloon, cow(eyes=eyes, tongue=tongue)))
end end
""" """
@ -93,6 +93,25 @@ function cowthink(message::AbstractString; cow=default, eyes="oo", tongue=" ")
println(string(balloon, cow(eyes=eyes, tongue=tongue, thoughts="o"))) println(string(balloon, cow(eyes=eyes, tongue=tongue, thoughts="o")))
end end
"""
cowsaid(message::AbstractString; kwargs...)
cowthunk(message::AbstractString; kwargs...)
Constructs cow art and returns it as a string instead of printing it. See [`cowsay`](@ref)
for implementation details.
# Example
```jldoctest
julia> cowsaid("Have you mooed today?")
" _______________________\\n< Have you mooed today? >\\n -----------------------\\n \\\\ ^__^\\n \\\\ (oo)\\\\_______\\n (__)\\\\ )\\\\/\\\\\\n ||----w |\\n || ||\\n"
```
"""
function cowsaid(message::AbstractString; cow=default, eyes="oo", tongue=" ")
balloon = sayballoon(message)
return string(balloon, cow(eyes=eyes, tongue=tongue))
end
""" """
function sayballoon(message::AbstractString) function sayballoon(message::AbstractString)