From 09882d47688b9e923b7405f338c4aafb0b8beadd Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 11 Jan 2022 19:11:20 -0600 Subject: [PATCH] Add a `thinkballoon` function for generating thought bubbles --- src/Cowsay.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Cowsay.jl b/src/Cowsay.jl index ae6303c..464c9cc 100644 --- a/src/Cowsay.jl +++ b/src/Cowsay.jl @@ -145,5 +145,35 @@ function sayballoon(message::AbstractString) end #function +function thinkballoon(message::AbstractString) + messagelines = split(message, "\n") + nlines = length(messagelines) + + linelength = max(length.(messagelines)...) + paddinglength = linelength + 2 + + balloon = string( + " ", + repeat("_", paddinglength), + "\n" + ) + for i in 1:nlines + balloon = string( + balloon, + "( ", + rpad(messagelines[i], linelength), + " )\n" + ) + end #for + balloon = string( + balloon, + " ", + repeat("-", paddinglength), + "\n" + ) + + return balloon +end #function + end