Module: TuiTui::StatusBar

Defined in:
lib/tui_tui/status_bar.rb

Overview

A one-row status/footer bar. It draws left text from the start and optional right text flush right.

Class Method Summary collapse

Class Method Details

.draw(canvas, rect, left: "", right: nil, style: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tui_tui/status_bar.rb', line 11

def draw(canvas, rect, left: "", right: nil, style: nil)
  canvas.fill(rect, style)

  right_width = right ? DisplayText.new(right).width : 0
  fits_right = right && right_width < rect.cols
  left_max = fits_right ? rect.cols - right_width : rect.cols

  canvas.text(rect.row, rect.col, DisplayText.new(left).truncate(left_max), style)
  canvas.text(rect.row, rect.col + rect.cols - right_width, right, style) if fits_right
  canvas
end