Module: OllamaChat::Feedback

Included in:
Chat, Database::Models::AppState, FollowChat, StateSelectors::Common, ToolCallProcessor, Tools::Concern, Vim
Defined in:
lib/ollama_chat/feedback.rb

Overview

Provides typed user-facing output to STDOUT.

Examples:

feedback("Done.", type: :success)     # → ✅ Done.
feedback("Cancelled.", type: :cancel) # → ❌ Cancelled.

Constant Summary collapse

PREFIXES =

Glyph prefixes keyed by message type.

Unknown types trigger a warn via the default proc but still emit the message without a prefix.

Hash.new {
  warn "type %s not defined!" % _2.inspect unless _2.nil?
}.merge(
  success: "\u2705",        # ✅
  cancel:  "\u274C",        # ❌
  denied:  "\u{1F6AB}",     # 🚫
  warn:    "\u26A0",        # ⚠️
  info:    "\u2139",        # ℹ️
  alarm:   "\u{1F514}"      # 🔔
)

Instance Method Summary collapse

Instance Method Details

#feedback(msg, type: nil, output: STDOUT, newline: true, timeout: nil) ⇒ nil

Write a user-facing message to STDOUT with an optional glyph prefix.

Parameters:

  • msg (String) —

    The message body.

  • type (Symbol, nil) (defaults to: nil) —

    Selects the prefix from PREFIXES. Omit for unadorned output.

  • output (IO) (defaults to: STDOUT) —

    The IO to write to. Defaults to STDOUT. Override when routing to a different stream (e.g., a use_pager yielded IO).

  • newline (Boolean) (defaults to: true) —

    When true (default), ensures the message ends with exactly one newline before writing. Set to false for mid-line or no-trailing-newline output.

Returns:

  • (nil)


36
37
38
39
40
41
42
43
# File 'lib/ollama_chat/feedback.rb', line 36

def feedback(msg, type: nil, output: STDOUT, newline: true, timeout: nil)
  prefix = PREFIXES[type&.to_sym]&.+(' ')
  newline and msg = msg.sub(/(?<!\n)\z/, ?\n)
  output.print(prefix.to_s + msg)
  timeout.nil? and return
  chat.confirm?(prompt: '⏎  Press any key to continue (%s). ', timeout:)
  nil
end