Class: Sus::Output::Text
Direct Known Subclasses
XTerm
Constant Summary
collapse
- INDENTATION =
"\t"
Constants included
from Messages
Messages::FAILED_PREFIX, Messages::PASSED_PREFIX
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Messages
#assert, #error, #error_prefix, #fail_prefix, #inform, #inform_prefix, #pass_prefix, #skip, #skip_prefix
Constructor Details
#initialize(io) ⇒ Text
Returns a new instance of Text.
14
15
16
17
18
19
20
21
|
# File 'lib/sus/output/text.rb', line 14
def initialize(io)
@io = io
@styles = {reset: self.reset}
@indent = String.new
@styles[:indent] = @indent
end
|
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
35
36
37
|
# File 'lib/sus/output/text.rb', line 35
def io
@io
end
|
#styles ⇒ Object
Returns the value of attribute styles.
23
24
25
|
# File 'lib/sus/output/text.rb', line 23
def styles
@styles
end
|
Instance Method Details
#[](key) ⇒ Object
60
61
62
|
# File 'lib/sus/output/text.rb', line 60
def [] key
@styles[key]
end
|
#[]=(key, value) ⇒ Object
64
65
66
|
# File 'lib/sus/output/text.rb', line 64
def []= key, value
@styles[key] = value
end
|
#append(buffer) ⇒ Object
29
30
31
32
33
|
# File 'lib/sus/output/text.rb', line 29
def append(buffer)
buffer.each do |operation|
self.public_send(*operation)
end
end
|
#buffered ⇒ Object
25
26
27
|
# File 'lib/sus/output/text.rb', line 25
def buffered
Buffered.new(self)
end
|
#colors? ⇒ Boolean
76
77
78
|
# File 'lib/sus/output/text.rb', line 76
def colors?
false
end
|
#indent ⇒ Object
39
40
41
|
# File 'lib/sus/output/text.rb', line 39
def indent
@indent << INDENTATION
end
|
#indented ⇒ Object
47
48
49
50
51
52
|
# File 'lib/sus/output/text.rb', line 47
def indented
self.indent
yield
ensure
self.outdent
end
|
#interactive? ⇒ Boolean
54
55
56
|
# File 'lib/sus/output/text.rb', line 54
def interactive?
@io.tty?
end
|
#outdent ⇒ Object
43
44
45
|
# File 'lib/sus/output/text.rb', line 43
def outdent
@indent.slice!(INDENTATION)
end
|
#puts(*arguments) ⇒ Object
Print out the arguments as per #print, followed by the reset sequence and a newline.
108
109
110
111
|
# File 'lib/sus/output/text.rb', line 108
def puts(*arguments)
write(*arguments)
@io.puts(self.reset)
end
|
#reset ⇒ Object
83
84
|
# File 'lib/sus/output/text.rb', line 83
def reset
end
|
#size ⇒ Object
68
69
70
|
# File 'lib/sus/output/text.rb', line 68
def size
[24, 80]
end
|
#style(foreground, background = nil, *attributes) ⇒ Object
80
81
|
# File 'lib/sus/output/text.rb', line 80
def style(foreground, background = nil, *attributes)
end
|
#width ⇒ Object
72
73
74
|
# File 'lib/sus/output/text.rb', line 72
def width
size.last
end
|
#write(*arguments) ⇒ Object
Print out the given arguments. When the argument is a symbol, look up the style and inject it into the io stream. When the argument is a proc/lambda, call it with self as the argument. When the argument is anything else, write it directly to the io.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/sus/output/text.rb', line 90
def write(*arguments)
arguments.each do |argument|
case argument
when Symbol
@io.write(self[argument])
when Proc
argument.call(self)
else
if argument.respond_to?(:print)
argument.print(self)
else
@io.write(argument)
end
end
end
end
|