Class: TerminalNotes::InfoBar

Inherits:
Widget
  • Object
show all
Defined in:
lib/terminal-notes/info_bar.rb

Constant Summary collapse

HEIGHT =
3

Constants inherited from Widget

Widget::TITLE_PADDING

Instance Attribute Summary

Attributes inherited from Widget

#height, #width, #window

Instance Method Summary collapse

Methods inherited from Widget

#focus, #redraw, #resize

Constructor Details

#initialize(config: {}, parent:, &block) ⇒ InfoBar

Returns a new instance of InfoBar.



5
6
7
8
9
10
11
# File 'lib/terminal-notes/info_bar.rb', line 5

def initialize(config: {}, parent:, &block)
    super(parent: parent, title: "", height: HEIGHT,
          y: (parent.size[:lines] - HEIGHT), border: false)

    @get_context = block
    draw
end

Instance Method Details

#drawObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/terminal-notes/info_bar.rb', line 13

def draw
    super do
        context = @get_context.call
        title = "Mode: #{context[:mode].to_s.capitalize}"

        cursor = Cursor.new(x: (@parent.size[:columns] - title.size) / 2,
                            y: 0)
        @window.move_cursor(cursor)
        @window.draw_string(title)
    end
end