Sha256: 38216cb75fbd0e9a81f9b69fd8e761381ef0005ef5e9c93d53858ad6bea4cee7

Contents?: true

Size: 850 Bytes

Versions: 18

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true

require 'colorized_string'

module Dsu
  module Support
    module ColorThemable
      def prompt_with_options(prompt:, options:)
        options = "[#{options.join('/')}]"
        "#{apply_theme(prompt, theme_color: self.prompt)} " \
          "#{apply_theme(options, theme_color: prompt_options)}" \
          "#{apply_theme('>', theme_color: self.prompt)}"
      end

      module_function

      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

      private

      def colorize_string(input, theme_color:)
        ColorizedString[input].colorize(**theme_color)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dsu-2.2.2 lib/dsu/support/color_themable.rb
dsu-2.2.1 lib/dsu/support/color_themable.rb
dsu-2.2.0 lib/dsu/support/color_themable.rb
dsu-2.2.0.rc.2 lib/dsu/support/color_themable.rb
dsu-2.2.0.rc.1 lib/dsu/support/color_themable.rb
dsu-2.1.4 lib/dsu/support/color_themable.rb
dsu-2.1.3 lib/dsu/support/color_themable.rb
dsu-2.1.2 lib/dsu/support/color_themable.rb
dsu-2.1.1 lib/dsu/support/color_themable.rb
dsu-2.0.8 lib/dsu/support/color_themable.rb
dsu-2.0.7 lib/dsu/support/color_themable.rb
dsu-2.0.6 lib/dsu/support/color_themable.rb
dsu-2.0.5 lib/dsu/support/color_themable.rb
dsu-2.0.4 lib/dsu/support/color_themable.rb
dsu-2.0.3 lib/dsu/support/color_themable.rb
dsu-2.0.2 lib/dsu/support/color_themable.rb
dsu-2.0.1 lib/dsu/support/color_themable.rb
dsu-2.0.0.alpha.1 lib/dsu/support/color_themable.rb