Module: Dsu::Support::ColorThemable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply_theme(input, theme_color:) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/dsu/support/color_themable.rb', line 19

def apply_theme(input, theme_color:)
  if input.is_a?(Array)
    return input.map do |string|
      colorize_string(string, theme_color: theme_color)
    end.join("\n")
  end

  colorize_string(input, theme_color: theme_color)
end

Instance Method Details

#prompt_with_options(prompt:, options:) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/dsu/support/color_themable.rb', line 8

def prompt_with_options(prompt:, options:)
  # HACK: This module needs to be refactored to be more generic.
  target_color_theme = defined?(color_theme) ? color_theme : self
  options = "[#{options.join(',')}]"
  "#{apply_theme(prompt, theme_color: target_color_theme.prompt)} " \
    "#{apply_theme(options, theme_color: target_color_theme.prompt_options)}" \
    "#{apply_theme('>', theme_color: target_color_theme.prompt)}"
end