@@ -1126,6 +1126,56 @@ def self.hexify(str, col = DefaultWrap, line_start = '', line_end = '', buf_star
1126
1126
return output
1127
1127
end
1128
1128
1129
+ #
1130
+ # Converts a string to one similar to what would be used by cowsay(1), a UNIX utility for
1131
+ # displaying text as if it was coming from an ASCII-cow's mouth:
1132
+ #
1133
+ # __________________
1134
+ # < the cow says moo >
1135
+ # ------------------
1136
+ # \ ^__^
1137
+ # \ (oo)\_______
1138
+ # (__)\ )\/\
1139
+ # ||----w |
1140
+ # || ||
1141
+ #
1142
+ # @param text [String] The string to cowsay
1143
+ # @param width [Fixnum] Width of the cow's cloud. Default's to cowsay(1)'s default, 39.
1144
+ def self . cowsay ( text , width = 39 )
1145
+ # cowsay(1) chunks a message up into 39-byte chunks and wraps it in '| ' and ' |'
1146
+ # Rex::Text.wordwrap(text, 0, 39, ' |', '| ') almost does this, but won't
1147
+ # split a word that has > 39 characters in it which results in oddly formed
1148
+ # text in the cowsay banner, so just do it by hand. This big mess wraps
1149
+ # the provided text in an ASCII-cloud and then makes it look like the cloud
1150
+ # is a thought/word coming from the ASCII-cow. Each line in the
1151
+ # ASCII-cloud is no more than the specified number-characters long, and the cloud corners are
1152
+ # made to look rounded
1153
+ text_lines = text . scan ( Regexp . new ( ".{1,#{ width } }" ) )
1154
+ max_length = text_lines . map ( &:size ) . sort . last
1155
+ cloud_parts = [ ]
1156
+ cloud_parts << " #{ '_' * ( max_length + 2 ) } "
1157
+ if text_lines . size == 1
1158
+ cloud_parts << "< #{ text } >"
1159
+ else
1160
+ cloud_parts << "/ #{ text_lines . first . ljust ( max_length , ' ' ) } \\ "
1161
+ if text_lines . size > 2
1162
+ text_lines [ 1 , text_lines . length - 2 ] . each do |line |
1163
+ cloud_parts << "| #{ line . ljust ( max_length , ' ' ) } |"
1164
+ end
1165
+ end
1166
+ cloud_parts << "\\ #{ text_lines . last . ljust ( max_length , ' ' ) } /"
1167
+ end
1168
+ cloud_parts << " #{ '-' * ( max_length + 2 ) } "
1169
+ cloud_parts << <<EOS
1170
+ \\ ,__,
1171
+ \\ (oo)____
1172
+ (__) )\\
1173
+ ||--|| *
1174
+ EOS
1175
+ cloud_parts . join ( "\n " )
1176
+ end
1177
+
1178
+
1129
1179
##
1130
1180
#
1131
1181
# Transforms
0 commit comments