lib/defcli/formatting.rb
# Fit a text in a given width (number of chars).
# @param txt [String]
# @param width [Integer] maximum width
# @return [Array] list of lines of text
Fit a text in a given width (number of chars).
Fit a text in a given width ( number of chars ) .
def format_result(r, color = true)
        require "colored" if color
        word = r[:word]
        word = word.bold if color
        rating = format_result_rating(r, color)
        definition = tab(fit(r[:definition], 75)).join "\n"
        text = "* #{word}"
        text << " (#{rating})" if rating
        text << ":\n\n#{definition}\n"
        text << "(📍 #{r[:location]})\n" if r[:location]
        text << (format_result_examples(r, color) or "")
        text + "\n\n"
      end
def format_result ( r , color = true ) require "colored" if color word = r [ :word ] word = word . bold if color rating = format_result_rating ( r , color ) definition = tab ( fit ( r [ :definition ] , 75 ) ) . join "\n" text = "* #{word}" text << " (#{rating})" if rating text << ":\n\n#{definition}\n" text << "(📍 #{r[:location]})\n" if r[ l o cation] text << ( format_result_examples ( r , color ) or "" ) text + "\n\n" end
Fit a text in a given width (number of chars).
Fit a text in a given width ( number of chars ) .
list of lines of text
list of lines of text
Array
r
<not_specific>
color
<not_specific>
<not_specific>
None
width
<not_specific>
None