Module: Aidp::MessageDisplay

Overview

Mixin providing a consistent display_message helper across classes. Usage:

include Aidp::MessageDisplay
display_message("Hello", type: :success)

Supports color types: :error, :success, :warning, :info, :highlight, :muted

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

COLOR_MAP =
{
  error: :red,
  success: :green,
  warning: :yellow,
  warn: :yellow,
  info: :blue,
  highlight: :cyan,
  muted: :bright_black
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
# File 'lib/aidp/message_display.rb', line 22

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#display_message(message, type: :info) ⇒ Object

Instance helper for displaying a colored message via TTY::Prompt



27
28
29
30
31
32
33
34
# File 'lib/aidp/message_display.rb', line 27

def display_message(message, type: :info)
  # Ensure message is UTF-8 encoded to handle emoji and special characters
  message_str = message.to_s
  message_str = message_str.force_encoding("UTF-8") if message_str.encoding.name == "ASCII-8BIT"
  message_str = message_str.encode("UTF-8", invalid: :replace, undef: :replace)
  prompt = message_display_prompt
  prompt.say(message_str, color: COLOR_MAP.fetch(type, :white))
end

#message_display_promptObject

Provide a memoized prompt per including instance (if it defines @prompt)



37
38
39
40
41
42
43
# File 'lib/aidp/message_display.rb', line 37

def message_display_prompt
  if instance_variable_defined?(:@prompt) && @prompt
    @prompt
  else
    @__message_display_prompt ||= TTY::Prompt.new
  end
end