Class: WritersRoom::ChatTui

Inherits:
Object
  • Object
show all
Defined in:
lib/writers_room/chat_tui.rb

Overview

Terminal chat interface for ChatSession. Prints styled output directly to stdout (terminal scrollback works). Streams LLM responses token by token. Input and status stay at the bottom of the terminal.

Constant Summary collapse

SPINNER_FRAMES =
%w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
ANSI =
{
  reset:       "\e[0m",
  bold:        "\e[1m",
  dim:         "\e[2m",
  italic:      "\e[3m",
  underline:   "\e[4m",
  red:         "\e[31m",
  green:       "\e[32m",
  yellow:      "\e[33m",
  blue:        "\e[34m",
  magenta:     "\e[35m",
  cyan:        "\e[36m",
  dark_gray:   "\e[90m",
  light_green: "\e[92m",
  light_blue:  "\e[94m",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ ChatTui

Returns a new instance of ChatTui.



30
31
32
# File 'lib/writers_room/chat_tui.rb', line 30

def initialize(session)
  @session = session
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/writers_room/chat_tui.rb', line 34

def run
  @session.log_session_start

  print_styled(@session.welcome_text)
  ctx = @session.context_text
  print_styled(ctx) unless ctx.empty?
  puts

  loop do
    text = read_input
    break if text.nil?
    break if @session.exit_command?(text)
    next  if text.empty?

    result = @session.handle_command(text)
    if result[:handled]
      handle_command_result(result)
      next
    end

    send_streaming_message(text)
  end

  puts
  print_dim(@session.goodbye_text)
  puts
  @session.log_session_end
  @session.messages
end