Add optional io choosing for cowsay and cowthink

This commit is contained in:
Thomas A. Christensen II 2022-02-01 16:29:08 -06:00
parent a25f5f4678
commit d2a4226cbb
Signed by: millironx
GPG key ID: 139C07724802BC5D
2 changed files with 20 additions and 5 deletions

View file

@ -39,8 +39,8 @@ include("cows/vader.cow.jl")
include("cows/www.cow.jl") include("cows/www.cow.jl")
""" """
cowsay(message::AbstractString; kwargs...) cowsay([io,] message::AbstractString; kwargs...)
cowthink(message::AbstractString; kwargs...) cowthink([io,] message::AbstractString; kwargs...)
Print an ASCII picture of a cow saying/thinking `message` Print an ASCII picture of a cow saying/thinking `message`
@ -79,18 +79,26 @@ julia> cowthink("Have I mooed today?")
``` ```
""" """
function cowsay(message::AbstractString; cow=default, eyes="oo", tongue=" ") function cowsay(message::AbstractString; cow=default, eyes="oo", tongue=" ")
println(cowsaid(message, cow=cow, eyes=eyes, tongue=tongue)) cowsay(stdout, message, cow=cow, eyes=eyes, tongue=tongue)
end
function cowsay(io::IO, message::AbstractString; cow=default, eyes="oo", tongue=" ")
println(io, cowsaid(message, cow=cow, eyes=eyes, tongue=tongue))
end end
""" """
cowthink(message::AbstractString; kwargs...) cowthink([io,] message::AbstractString; kwargs...)
Print an ASCII picture of a cow thinking `message` Print an ASCII picture of a cow thinking `message`
See [`cowsay`](@ref) See [`cowsay`](@ref)
""" """
function cowthink(message::AbstractString; cow=default, eyes="oo", tongue=" ") function cowthink(message::AbstractString; cow=default, eyes="oo", tongue=" ")
println(cowthunk(message, cow=cow, eyes=eyes, tongue=tongue)) cowthink(stdout, message, cow=cow, eyes=eyes, tongue=tongue)
end
function cowthink(io::IO, message::AbstractString; cow=default, eyes="oo", tongue=" ")
println(io, cowthunk(message, cow=cow, eyes=eyes, tongue=tongue))
end end
""" """

View file

@ -18,4 +18,11 @@ DocMeta.setdocmeta!(Cowsay, :DocTestSetup, :(using Cowsay); recursive=true)
# Multi-liner say balloon # Multi-liner say balloon
@test Cowsay.sayballoon("One line\nTwo line\nRed line\nBlue line") == " ___________\n/ One line \\\n| Two line |\n| Red line |\n\\ Blue line /\n -----------\n" @test Cowsay.sayballoon("One line\nTwo line\nRed line\nBlue line") == " ___________\n/ One line \\\n| Two line |\n| Red line |\n\\ Blue line /\n -----------\n"
end end
@testset "IO Funkiness" begin
# Cowsay with io redirection
@test_warn cowsaid("Moo") cowsay(stderr, "Moo")
# Cowthink with io redirection
@test_warn cowthunk("Moo") cowthink(stderr, "Moo")
end
end end