Class: TextPlayer::Formatters::Shell
- Inherits:
-
Base
- Object
- Base
- TextPlayer::Formatters::Shell
show all
- Defined in:
- lib/text_player/formatters/shell.rb
Overview
Shell formatter - interactive presentation with prompts and colors
Instance Attribute Summary
Attributes inherited from Base
#command_result
Instance Method Summary
collapse
Methods inherited from Base
#initialize, write
Instance Method Details
#to_h ⇒ Object
17
18
19
20
21
|
# File 'lib/text_player/formatters/shell.rb', line 17
def to_h
super.merge(
formatted_output: to_s
)
end
|
#to_s ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/text_player/formatters/shell.rb', line 9
def to_s
if command_result.action_command?
format_game_output
else
format_system_feedback
end
end
|
#write(stream) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/text_player/formatters/shell.rb', line 23
def write(stream)
if command_result.action_command?
content, prompt = (display_content)
stream.write(content)
if prompt
color = command_result.success? ? "\e[32m" : "\e[31m"
stream.write("#{color}#{prompt}\e[0m")
end
else
stream.write(to_s)
end
end
|