Class: Infobar::Display

Inherits:
Object show all
Extended by:
Tins::Delegate
Includes:
Term::ANSIColor
Defined in:
lib/infobar/display.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDisplay

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

#frequencyObject

Returns the value of attribute frequency.



34
35
36
# File 'lib/infobar/display.rb', line 34

def frequency
  @frequency
end

#inputObject



57
58
59
60
61
62
63
# File 'lib/infobar/display.rb', line 57

def input
  if show?
    @input
  else
    NULL
  end
end

#showObject

Returns the value of attribute show.



36
37
38
# File 'lib/infobar/display.rb', line 36

def show
  @show
end

#styleObject

Returns the value of attribute style.



65
66
67
# File 'lib/infobar/display.rb', line 65

def style
  @style
end

Class Method Details

.default_styleObject



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_stylesObject



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_returnObject



142
143
144
145
# File 'lib/infobar/display.rb', line 142

def carriage_return
  output << ?\r
  self
end

#clearObject



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

#newlineObject



147
148
149
150
# File 'lib/infobar/display.rb', line 147

def newline
  output << $/
  self
end

#outputObject



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/infobar/display.rb', line 38

def show?
  @show
end

#update(message:, counter:, force: false, **options) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/infobar/display.rb', line 81

def update(message:, counter:, force: false, **options)
  force and @frequency.reset
  @frequency.call do
    message = Infobar.convert_to_message(message)
    carriage_return
    self.style = options
    layout_bar(message, counter)
  end
end