Add support for cow "modes"

Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com>
This commit is contained in:
Thomas A. Christensen II 2022-05-10 19:45:57 -05:00
parent 4cd2cf5a07
commit 9c5d94b31b
Signed by: millironx
GPG key ID: 139C07724802BC5D

View file

@ -59,6 +59,16 @@ Print an ASCII picture of a cow saying/thinking `message`
- `wrap::Int=40`: The number of characters at which to wrap `message` to a new line - `wrap::Int=40`: The number of characters at which to wrap `message` to a new line
- `nowrap::Bool=false`: Don't perform text wrapping on `message` - `nowrap::Bool=false`: Don't perform text wrapping on `message`
## Cow appearance Keywords
- `borg::Bool=false`: Initiates Borg mode
- `dead::Bool=false`: Causes the cow to appear dead
- `greedy::Bool=false`: Invokes greedy mode
- `paranoid::Bool=false`: Causes a state of paranoia to come over the cow
- `stoned::Bool=false`: Makes the cow appear thoroughly stoned
- `tired::Bool=false`: Yields a tired cow
- `wired::Bool=false`: Somewhat the opposite of `tired`, and initiates wired mode
- `young::Bool=false`: Brings on the cow's youthful appearance
# Example # Example
```jldoctest ```jldoctest
julia> cowsay("Have you mooed today?") julia> cowsay("Have you mooed today?")
@ -153,6 +163,8 @@ function cowmoo(message::AbstractString, mode; kwargs...)
wrap = dict_or_default(kwargs, :wrap, 40) wrap = dict_or_default(kwargs, :wrap, 40)
nowrap = dict_or_default(kwargs, :nowrap, false) nowrap = dict_or_default(kwargs, :nowrap, false)
eyes, tongue = construct_face!(eyes, tongue; kwargs...)
# Default to 'say' mode # Default to 'say' mode
if mode ==:think if mode ==:think
balloon = thinkballoon balloon = thinkballoon
@ -168,6 +180,53 @@ function cowmoo(message::AbstractString, mode; kwargs...)
return string(speechbubble, cow(eyes=eyes, tongue=tongue, thoughts=thoughts)) return string(speechbubble, cow(eyes=eyes, tongue=tongue, thoughts=thoughts))
end end
function construct_face!(eyes, tongue; kwargs...)
borg = dict_or_default(kwargs, :borg, false)
dead = dict_or_default(kwargs, :dead, false)
greedy = dict_or_default(kwargs, :greedy, false)
paranoid = dict_or_default(kwargs, :paranoid, false)
stoned = dict_or_default(kwargs, :stoned, false)
tired = dict_or_default(kwargs, :tired, false)
wired = dict_or_default(kwargs, :wired, false)
young = dict_or_default(kwargs, :young, false)
if borg
eyes = "=="
end
if dead
eyes = "xx"
tongue = "U "
end
if greedy
eyes = "\$\$"
end
if paranoid
eyes = "@@"
end
if stoned
eyes = "**"
tongue = "U "
end
if tired
eyes = "--"
end
if wired
eyes = "OO"
end
if young
eyes = ".."
end
return eyes, tongue
end
""" """
dict_or_default(dict, key, value) dict_or_default(dict, key, value)