generated from athena-framework/component-template
/
console_output.cr
66 lines (54 loc) · 1.57 KB
/
console_output.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
63
64
65
66
abstract class Athena::Console::Output; end
require "./console_output_interface"
require "./io"
# An `ACON::Output::ConsoleOutputInterface` that wraps `STDOUT` and `STDERR`.
class Athena::Console::Output::ConsoleOutput < Athena::Console::Output::IO
include Athena::Console::Output::ConsoleOutputInterface
# Sets the `ACON::Output::Interface` that represents `STDERR`.
setter stderr : ACON::Output::Interface
@console_section_outputs = Array(ACON::Output::Section).new
def initialize(
verbosity : ACON::Output::Verbosity = :normal,
decorated : Bool? = nil,
formatter : ACON::Formatter::Interface? = nil
)
super STDOUT, verbosity, decorated, formatter
@stderr = ACON::Output::IO.new STDERR, verbosity, decorated, @formatter
actual_decorated = self.decorated?
if decorated.nil?
self.decorated = actual_decorated && @stderr.decorated?
end
end
# :inherit:
def section : ACON::Output::Section
ACON::Output::Section.new(
self.io,
@console_section_outputs,
self.verbosity,
self.decorated?,
self.formatter
)
end
# :inherit:
def error_output : ACON::Output::Interface
@stderr
end
# :inherit:
def error_output=(@stderr : ACON::Output::Interface) : Nil
end
# :inherit:
def decorated=(decorated : Bool) : Nil
super
@stderr.decorated = decorated
end
# :inherit:
def formatter=(formatter : Bool) : Nil
super
@stderr.formatter = formatter
end
# :inherit:
def verbosity=(verbosity : ACON::Output::Verbosity) : Nil
super
@stderr.verbosity = verbosity
end
end