Method: Howzit::StringUtils#format_header

Defined in:
lib/howzit/stringutils.rb

#format_header(opts = {}) ⇒ String

Make a fancy title line for the topic

Parameters:

  • opts (Hash) (defaults to: {})

    options

Returns:

  • (String)

    formatted string



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/howzit/stringutils.rb', line 351

def format_header(opts = {})
  title = dup
  options = {
    hr: "\u{254C}",
    color: '{bg}',
    border: '{x}',
    mark: should_mark_iterm?
  }

  options.merge!(opts)

  case Howzit.options[:header_format]
  when :block
    Color.template("#{options[:color]}\u{258C}#{title}#{should_mark_iterm? && options[:mark] ? iterm_marker : ''}{x}")
  else
    cols = TTY::Screen.columns

    cols = Howzit.options[:wrap] if (Howzit.options[:wrap]).positive? && cols > Howzit.options[:wrap]
    title = Color.template("#{options[:border]}#{options[:hr] * 2}( #{options[:color]}#{title}#{options[:border]} )")

    tail = if should_mark_iterm?
             "#{options[:hr] * (cols - title.uncolor.length - 15)}#{options[:mark] ? iterm_marker : ''}"
           else
             options[:hr] * (cols - title.uncolor.length)
           end
    Color.template("#{title}#{tail}{x}")
  end
end