From 9c5d94b31beba0cceb75f7013dd6657f645cf638 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 10 May 2022 19:45:57 -0500 Subject: [PATCH] Add support for cow "modes" Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com> --- src/Cowsay.jl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Cowsay.jl b/src/Cowsay.jl index 23b460b..810b948 100644 --- a/src/Cowsay.jl +++ b/src/Cowsay.jl @@ -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 - `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 ```jldoctest julia> cowsay("Have you mooed today?") @@ -153,6 +163,8 @@ function cowmoo(message::AbstractString, mode; kwargs...) wrap = dict_or_default(kwargs, :wrap, 40) nowrap = dict_or_default(kwargs, :nowrap, false) + eyes, tongue = construct_face!(eyes, tongue; kwargs...) + # Default to 'say' mode if mode ==:think balloon = thinkballoon @@ -168,6 +180,53 @@ function cowmoo(message::AbstractString, mode; kwargs...) return string(speechbubble, cow(eyes=eyes, tongue=tongue, thoughts=thoughts)) 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)