Class: WritersRoom::Display

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

Overview

Terminal output formatting for scene direction. Per-character color rotation, optional file logging.

Constant Summary collapse

COLORS =
[
  "\e[1;36m", # Cyan bold
  "\e[1;32m", # Green bold
  "\e[1;33m", # Yellow bold
  "\e[1;35m", # Magenta bold
  "\e[1;34m", # Blue bold
  "\e[1;31m", # Red bold
].freeze
DIRECTOR_COLOR =

White

"\e[0;37m"
INFO_COLOR =

Gray

"\e[0;90m"
RESET =
"\e[0m"

Instance Method Summary collapse

Constructor Details

#initialize(log_path: nil, color: $stdout.tty?) ⇒ Display

Returns a new instance of Display.

Parameters:

  • log_path (String, nil) (defaults to: nil)

    optional file path for logging

  • color (Boolean) (defaults to: $stdout.tty?)

    enable ANSI colors (default: auto-detect TTY)



22
23
24
25
26
27
# File 'lib/writers_room/display.rb', line 22

def initialize(log_path: nil, color: $stdout.tty?)
  @color = color
  @character_colors = {}
  @color_index = 0
  @log_file = log_path ? File.open(log_path, "a") : nil
end

Instance Method Details

Display a banner message.

Parameters:

  • text (String)

    banner text



78
79
80
81
82
# File 'lib/writers_room/display.rb', line 78

def banner(text)
  bar = "=" * 60
  puts colorize("\e[1;36m", "\n#{bar}\n#{text}\n#{bar}\n")
  log("#{bar}\n#{text}\n#{bar}")
end

#broadcast(from, message) ⇒ Object

Display broadcast message.

Parameters:

  • from (String)

    sender

  • message (String)

    content



140
141
142
# File 'lib/writers_room/display.rb', line 140

def broadcast(from, message)
  dialog(from, message)
end

#closeObject

Close the log file if open.



154
155
156
# File 'lib/writers_room/display.rb', line 154

def close
  @log_file&.close
end

#complete(who) ⇒ Object

Display scene completion.

Parameters:

  • who (String)

    who marked it complete



147
148
149
150
151
# File 'lib/writers_room/display.rb', line 147

def complete(who)
  line = "[COMPLETE] Scene marked complete by #{who}"
  puts colorize("\e[1;32m", line)
  log(line)
end

#dialog(from, text, emotion: nil) ⇒ Object

Display character dialog.

Parameters:

  • from (String)

    character name

  • text (String)

    dialog content

  • emotion (String, nil) (defaults to: nil)

    optional emotional tag



34
35
36
37
38
39
40
41
# File 'lib/writers_room/display.rb', line 34

def dialog(from, text, emotion: nil)
  color = color_for(from)
  emotion_tag = emotion ? " [#{emotion}]" : ""
  line = "#{from}#{emotion_tag}: #{text}"

  puts colorize(color, line)
  log(line)
end

#director_note(text) ⇒ Object

Display a director note (stage direction).

Parameters:

  • text (String)

    director note



46
47
48
49
50
# File 'lib/writers_room/display.rb', line 46

def director_note(text)
  line = "[DIRECTOR: #{text}]"
  puts colorize(DIRECTOR_COLOR, line)
  log(line)
end

#incoming(to, from, content) ⇒ Object

Display an incoming message notification (for bus debugging).

Parameters:

  • to (String)

    receiver name

  • from (String)

    sender name

  • content (String)

    message content



121
122
123
124
# File 'lib/writers_room/display.rb', line 121

def incoming(to, from, content)
  line = "[#{from} -> #{to}] #{content.to_s[0..80]}"
  log(line)
end

#info(text) ⇒ Object

Display info text (gray).

Parameters:

  • text (String)

    informational message



94
95
96
97
# File 'lib/writers_room/display.rb', line 94

def info(text)
  puts colorize(INFO_COLOR, text)
  log(text)
end

#memory_write(writer, key) ⇒ Object

Display a memory write notification.

Parameters:

  • writer (String)

    who wrote

  • key (String)

    memory key



130
131
132
133
134
# File 'lib/writers_room/display.rb', line 130

def memory_write(writer, key)
  line = "[MEMORY] #{writer} wrote :#{key}"
  puts colorize(INFO_COLOR, line)
  log(line)
end

#scene_header(info) ⇒ Object

Display scene header.

Parameters:

  • info (Hash)

    scene metadata



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/writers_room/display.rb', line 55

def scene_header(info)
  number = info[:scene_number] || info["scene_number"]
  name   = info[:scene_name]   || info["scene_name"]
  loc    = info[:location]     || info["location"]
  chars  = info[:characters]   || info["characters"] || []

  text = "\n    \#{\"=\" * 60}\n    SCENE \#{number}: \#{name}\n    Location: \#{loc}\n    Characters: \#{Array(chars).join(', ')}\n    \#{\"=\" * 60}\n\n  HEADER\n\n  puts colorize(\"\\e[1;36m\", text)\n  log(text)\nend\n"

#separatorObject

Display a separator line.



85
86
87
88
89
# File 'lib/writers_room/display.rb', line 85

def separator
  line = "-" * 60
  puts colorize(INFO_COLOR, line)
  log(line)
end

#stats(stats) ⇒ Object

Display scene statistics.

Parameters:

  • stats (Hash)

    statistics hash



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/writers_room/display.rb', line 102

def stats(stats)
  puts colorize("\e[1;36m", "\n#{'=' * 60}")
  puts colorize("\e[1;36m", "SCENE STATISTICS")
  puts colorize("\e[1;36m", "=" * 60)
  puts "Total lines: #{stats[:total_lines]}"
  puts "\nLines by character:"

  (stats[:lines_by_character] || {}).sort_by { |_, count| -count }.each do |char, count|
    puts "  #{char}: #{count}"
  end

  puts colorize("\e[1;36m", "=" * 60)
end