Class: Infobar::Display
- Extended by:
- Tins::Delegate
- Includes:
- Term::ANSIColor
- Defined in:
- lib/infobar/display.rb
Instance Attribute Summary collapse
-
#frequency ⇒ Object
Returns the value of attribute frequency.
- #input ⇒ Object
-
#show ⇒ Object
Returns the value of attribute show.
-
#style ⇒ Object
Returns the value of attribute style.
Class Method Summary collapse
Instance Method Summary collapse
- #as_styles ⇒ Object
- #as_styles=(styles) ⇒ Object
- #carriage_return ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Display
constructor
A new instance of Display.
- #newline ⇒ Object
- #output ⇒ Object
- #output=(io) ⇒ Object
- #reset(clear: true) ⇒ Object
- #show? ⇒ Boolean
- #update(message: nil, counter: nil, force: false, **options) ⇒ Object
Constructor Details
#initialize ⇒ Display
Returns a new instance of Display.
22 23 24 25 26 27 28 |
# File 'lib/infobar/display.rb', line 22 def initialize self.output = $stdout self.input = $stdin self.frequency = 0.05 @show = true @style = self.class.default_style.dup end |
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
34 35 36 |
# File 'lib/infobar/display.rb', line 34 def frequency @frequency end |
#input ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/infobar/display.rb', line 57 def input if show? @input else NULL end end |
#show ⇒ Object
Returns the value of attribute show.
36 37 38 |
# File 'lib/infobar/display.rb', line 36 def show @show end |
#style ⇒ Object
Returns the value of attribute style.
65 66 67 |
# File 'lib/infobar/display.rb', line 65 def style @style end |
Class Method Details
.default_style ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/infobar/display.rb', line 11 def self.default_style { done_fill: ?░, done_fg_color: 22, done_bg_color: 40, todo_fill: ' ', todo_fg_color: 40, todo_bg_color: 22, } end |
Instance Method Details
#as_styles ⇒ Object
71 72 73 74 |
# File 'lib/infobar/display.rb', line 71 def as_styles defined? @as_styles or self.as_styles = {} @as_styles end |
#as_styles=(styles) ⇒ Object
76 77 78 79 |
# File 'lib/infobar/display.rb', line 76 def as_styles=(styles) @as_styles = styles.to_h.symbolize_keys_recursive @as_styles.default_proc = proc { style.subhash(/\Adone_/) } end |
#carriage_return ⇒ Object
142 143 144 145 |
# File 'lib/infobar/display.rb', line 142 def carriage_return output << ?\r self end |
#clear ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/infobar/display.rb', line 134 def clear carriage_return output << ' ' * columns carriage_return @frequency.reset self end |
#newline ⇒ Object
147 148 149 150 |
# File 'lib/infobar/display.rb', line 147 def newline output << $/ self end |
#output ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/infobar/display.rb', line 47 def output if show? @output else NULL end end |
#output=(io) ⇒ Object
42 43 44 45 |
# File 'lib/infobar/display.rb', line 42 def output=(io) @output = io @output.ask_and_send(:respond_to?, :sync=, true) end |
#reset(clear: true) ⇒ Object
128 129 130 131 132 |
# File 'lib/infobar/display.rb', line 128 def reset(clear: true) clear && self.clear self.style = self.class.default_style self end |
#show? ⇒ Boolean
38 39 40 |
# File 'lib/infobar/display.rb', line 38 def show? @show end |
#update(message: nil, counter: nil, force: false, **options) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/infobar/display.rb', line 81 def update(message: nil, counter: nil, force: false, **) force and @frequency.reset @frequency.call do carriage_return self.style = = .() (, counter) end end |