Class: WritersRoom::Display
- Inherits:
-
Object
- Object
- WritersRoom::Display
- 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
-
#banner(text) ⇒ Object
Display a banner message.
-
#broadcast(from, message) ⇒ Object
Display broadcast message.
-
#close ⇒ Object
Close the log file if open.
-
#complete(who) ⇒ Object
Display scene completion.
-
#dialog(from, text, emotion: nil) ⇒ Object
Display character dialog.
-
#director_note(text) ⇒ Object
Display a director note (stage direction).
-
#incoming(to, from, content) ⇒ Object
Display an incoming message notification (for bus debugging).
-
#info(text) ⇒ Object
Display info text (gray).
-
#initialize(log_path: nil, color: $stdout.tty?) ⇒ Display
constructor
A new instance of Display.
-
#memory_write(writer, key) ⇒ Object
Display a memory write notification.
-
#scene_header(info) ⇒ Object
Display scene header.
-
#separator ⇒ Object
Display a separator line.
-
#stats(stats) ⇒ Object
Display scene statistics.
Constructor Details
#initialize(log_path: nil, color: $stdout.tty?) ⇒ Display
Returns a new instance of Display.
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
#banner(text) ⇒ Object
Display a banner message.
78 79 80 81 82 |
# File 'lib/writers_room/display.rb', line 78 def (text) = "=" * 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.
140 141 142 |
# File 'lib/writers_room/display.rb', line 140 def broadcast(from, ) dialog(from, ) end |
#close ⇒ Object
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.
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.
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).
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).
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).
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.
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.
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" |
#separator ⇒ Object
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.
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 |