Add nowrap
keyword argument to disable text wrapping
This commit is contained in:
parent
bc04423125
commit
3d2f86d275
2 changed files with 18 additions and 2 deletions
|
@ -56,7 +56,8 @@ Print an ASCII picture of a cow saying/thinking `message`
|
||||||
cowfiles support this, though.
|
cowfiles support this, though.
|
||||||
- `tongue::AbstractString=" "`: A two-character string to be drawn in for the tongue. Not
|
- `tongue::AbstractString=" "`: A two-character string to be drawn in for the tongue. Not
|
||||||
all cowfiles support this.
|
all cowfiles support this.
|
||||||
- `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`
|
||||||
|
|
||||||
# Example
|
# Example
|
||||||
```jldoctest
|
```jldoctest
|
||||||
|
@ -150,6 +151,7 @@ function cowmoo(message::AbstractString, mode; kwargs...)
|
||||||
eyes = dict_or_default(kwargs, :eyes, "oo")
|
eyes = dict_or_default(kwargs, :eyes, "oo")
|
||||||
tongue = dict_or_default(kwargs, :tongue, " ")
|
tongue = dict_or_default(kwargs, :tongue, " ")
|
||||||
wrap = dict_or_default(kwargs, :wrap, 40)
|
wrap = dict_or_default(kwargs, :wrap, 40)
|
||||||
|
nowrap = dict_or_default(kwargs, :nowrap, false)
|
||||||
|
|
||||||
# Default to 'say' mode
|
# Default to 'say' mode
|
||||||
if mode ==:think
|
if mode ==:think
|
||||||
|
@ -160,7 +162,8 @@ function cowmoo(message::AbstractString, mode; kwargs...)
|
||||||
thoughts = "\\"
|
thoughts = "\\"
|
||||||
end
|
end
|
||||||
|
|
||||||
speechbubble = balloon(TextWrap.wrap(message, width=wrap))
|
wrapped_message = !nowrap ? TextWrap.wrap(message, width=wrap) : message
|
||||||
|
speechbubble = balloon(wrapped_message)
|
||||||
|
|
||||||
return string(speechbubble, cow(eyes=eyes, tongue=tongue, thoughts=thoughts))
|
return string(speechbubble, cow(eyes=eyes, tongue=tongue, thoughts=thoughts))
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,4 +25,17 @@ DocMeta.setdocmeta!(Cowsay, :DocTestSetup, :(using Cowsay); recursive=true)
|
||||||
# Cowthink with io redirection
|
# Cowthink with io redirection
|
||||||
@test_warn cowthunk("Moo") cowthink(stderr, "Moo")
|
@test_warn cowthunk("Moo") cowthink(stderr, "Moo")
|
||||||
end
|
end
|
||||||
|
@testset "Word Wrapping" begin
|
||||||
|
# Long text, default wrap
|
||||||
|
@test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo") == " _________________________________________\n/ Rollin' down a long highway out through \\\n| New Mexico driftin' down to Santa Fe to |\n\\ ride a bull in a rodeo /\n -----------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n"
|
||||||
|
|
||||||
|
# Long text, no wrap
|
||||||
|
@test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", nowrap=true) == " ________________________________________________________________________________________________________\n< Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo >\n --------------------------------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n"
|
||||||
|
|
||||||
|
# Long text, conflicting wrap instructions (nowrap should win)
|
||||||
|
@test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", wrap=80, nowrap=true) == " ________________________________________________________________________________________________________\n< Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo >\n --------------------------------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n"
|
||||||
|
|
||||||
|
# Long text, different wrap amount
|
||||||
|
@test cowsaid("Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to ride a bull in a rodeo", wrap=80) == " _________________________________________________________________________________\n/ Rollin' down a long highway out through New Mexico driftin' down to Santa Fe to \\\n\\ ride a bull in a rodeo /\n ---------------------------------------------------------------------------------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue