Module: Aidp::Interfaces::UiInterface

Included in:
NullUI, TtyUI
Defined in:
lib/aidp/interfaces/ui_interface.rb

Overview

UiInterface defines the contract for user interface operations. This interface abstracts TTY-based UI components for extraction into the agent-harness gem, allowing different UI implementations.

The interface covers two main areas:

  1. Message display - showing status messages to users
  2. Spinner/progress - showing activity indicators

Examples:

Implementing the interface

class MyUI
  include Aidp::Interfaces::UiInterface

  def say(message, type: :info)
    puts "[#{type.upcase}] #{message}"
  end

  def with_spinner(title:, &block)
    puts "Starting: #{title}"
    result = yield
    puts "Done: #{title}"
    result
  end
end

Using an injected UI

class Provider
  def initialize(ui: NullUI.new)
    @ui = ui
  end

  def process
    @ui.say("Starting process", type: :info)
    @ui.with_spinner(title: "Processing") do
      # do work
    end
  end
end

Constant Summary collapse

MESSAGE_TYPES =

Message types for display_message

[:info, :success, :warning, :error, :highlight, :muted].freeze

Instance Method Summary collapse

Instance Method Details

#quiet?Boolean

Check if we're in quiet mode (suppress non-critical messages).

Returns:

  • (Boolean)

    true if non-critical messages should be suppressed



77
78
79
# File 'lib/aidp/interfaces/ui_interface.rb', line 77

def quiet?
  false
end

#say(message, type: :info) ⇒ void

This method returns an undefined value.

Display a message to the user.

Parameters:

  • message (String)

    the message to display

  • type (Symbol) (defaults to: :info)

    one of MESSAGE_TYPES (:info, :success, :warning, :error, :highlight, :muted)

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/aidp/interfaces/ui_interface.rb', line 52

def say(message, type: :info)
  raise NotImplementedError, "#{self.class} must implement #say"
end

#spinner(title:) ⇒ SpinnerInterface

Create a spinner for manual control. Returns an object that responds to :auto_spin, :success, :error, and :update_title

Parameters:

  • title (String)

    initial spinner title

Returns:

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/aidp/interfaces/ui_interface.rb', line 70

def spinner(title:)
  raise NotImplementedError, "#{self.class} must implement #spinner"
end

#with_spinner(title:) { ... } ⇒ Object

Execute a block with a spinner indicator.

Parameters:

  • title (String)

    the spinner title

Yields:

  • the block to execute

Returns:

  • (Object)

    the result of the block

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/aidp/interfaces/ui_interface.rb', line 61

def with_spinner(title:)
  raise NotImplementedError, "#{self.class} must implement #with_spinner"
end