Class: Console::Terminal::Text
- Inherits:
-
Object
- Object
- Console::Terminal::Text
- Defined in:
- lib/console/terminal/text.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(output) ⇒ Text
constructor
A new instance of Text.
- #puts(*args, style: nil) ⇒ Object
- #reset ⇒ Object
- #style(foreground, background = nil, *attributes) ⇒ Object
- #write(*args, style: nil) ⇒ Object
Constructor Details
#initialize(output) ⇒ Text
Returns a new instance of Text.
27 28 29 30 |
# File 'lib/console/terminal/text.rb', line 27 def initialize(output) @output = output @styles = {} end |
Instance Method Details
#[](key) ⇒ Object
32 33 34 |
# File 'lib/console/terminal/text.rb', line 32 def [] key @styles[key] end |
#[]=(key, value) ⇒ Object
36 37 38 |
# File 'lib/console/terminal/text.rb', line 36 def []= key, value @styles[key] = value end |
#puts(*args, style: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/console/terminal/text.rb', line 56 def puts(*args, style: nil) if style and prefix = self[style] @output.write(prefix) @output.puts(*args) @output.write(self.reset) else @output.puts(*args) end end |
#reset ⇒ Object
43 44 |
# File 'lib/console/terminal/text.rb', line 43 def reset end |
#style(foreground, background = nil, *attributes) ⇒ Object
40 41 |
# File 'lib/console/terminal/text.rb', line 40 def style(foreground, background = nil, *attributes) end |
#write(*args, style: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/console/terminal/text.rb', line 46 def write(*args, style: nil) if style and prefix = self[style] @output.write(prefix) @output.write(*args) @output.write(self.reset) else @output.write(*args) end end |