Sha256: 93bb4f076bb86a582921c7d4fc199e5f1503163cbf29715b6a726be5ac88bdc7

Contents?: true

Size: 1.02 KB

Versions: 22

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'colorized_string'

module Dsu
  module Support
    module ColorThemable
      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

      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

22 entries across 22 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/support/color_themable.rb
dsu-3.0.4 lib/dsu/support/color_themable.rb
dsu-3.0.3 lib/dsu/support/color_themable.rb
dsu-3.0.1 lib/dsu/support/color_themable.rb
dsu-3.0.0 lib/dsu/support/color_themable.rb
dsu-3.0.0.beta.3 lib/dsu/support/color_themable.rb
dsu-3.0.0.beta.2 lib/dsu/support/color_themable.rb
dsu-3.0.0.beta.1 lib/dsu/support/color_themable.rb
dsu-3.0.0.beta.0 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.12 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.11 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.10 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.9 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.8 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.7 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.6 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.5 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.4 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.3 lib/dsu/support/color_themable.rb
dsu-3.0.0.alpha.2 lib/dsu/support/color_themable.rb