generated from athena-framework/component-template
/
io.cr
29 lines (23 loc) · 816 Bytes
/
io.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
# An `ACON::Output::Interface` implementation that wraps an [IO](https://crystal-lang.org/api/IO.html).
class Athena::Console::Output::IO < Athena::Console::Output
property io : ::IO
delegate :to_s, to: @io
def initialize(
@io : ::IO,
verbosity : ACON::Output::Verbosity? = :normal,
decorated : Bool? = nil,
formatter : ACON::Formatter::Interface? = nil
)
decorated = self.has_color_support? if decorated.nil?
super verbosity, decorated, formatter
end
protected def do_write(message : String, new_line : Bool) : Nil
new_line ? @io.puts(message) : @io.print(message)
end
private def has_color_support? : Bool
# Respect https://no-color.org.
return false if "false" == ENV["NO_COLOR"]?
return true if "Hyper" == ENV["TERM_PROGRAM"]?
@io.tty?
end
end