Class: Async::Terminal
- Inherits:
-
Object
- Object
- Async::Terminal
- Defined in:
- lib/async/terminal.rb
Overview
Styled terminal output. Internal Use Only
Defined Under Namespace
Modules: Attributes, Colors
Instance Method Summary collapse
- #color(foreground, background = nil, attributes = nil) ⇒ Object
-
#initialize(output) ⇒ Terminal
constructor
A new instance of Terminal.
- #reset ⇒ Object
- #tty? ⇒ Boolean
Constructor Details
#initialize(output) ⇒ Terminal
Returns a new instance of Terminal.
47 48 49 |
# File 'lib/async/terminal.rb', line 47 def initialize(output) @output = output end |
Instance Method Details
#color(foreground, background = nil, attributes = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/async/terminal.rb', line 55 def color(foreground, background = nil, attributes = nil) return nil unless tty? buffer = String.new buffer << "\e[" first = true if attributes buffer << (attributes).to_s first = false end if foreground if !first buffer << ";" else first = false end buffer << (30 + foreground).to_s end if background if !first buffer << ";" else first = false end buffer << (40 + background).to_s end buffer << 'm' return buffer end |
#reset ⇒ Object
93 94 95 96 97 |
# File 'lib/async/terminal.rb', line 93 def reset return nil unless tty? return "\e[0m" end |
#tty? ⇒ Boolean
51 52 53 |
# File 'lib/async/terminal.rb', line 51 def tty? @output.isatty end |