Class: HandyToolbox::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/handy_toolbox/screen.rb

Constant Summary collapse

SPACE =
' '.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_colors: false) ⇒ Screen

Returns a new instance of Screen.



10
11
12
# File 'lib/handy_toolbox/screen.rb', line 10

def initialize(default_colors: false)
  @default_colors = default_colors
end

Instance Attribute Details

#scrollObject (readonly)

Returns the value of attribute scroll.



8
9
10
# File 'lib/handy_toolbox/screen.rb', line 8

def scroll
  @scroll
end

Instance Method Details

#clearObject



27
28
29
30
# File 'lib/handy_toolbox/screen.rb', line 27

def clear
  scroll.reset
  Curses.clear
end

#closeObject



58
59
60
# File 'lib/handy_toolbox/screen.rb', line 58

def close
  Curses.close_screen
end

#drawObject



32
33
34
35
36
37
# File 'lib/handy_toolbox/screen.rb', line 32

def draw
  @max_y = 0
  yield
  @scroll.update(@max_y)
  Curses.refresh
end

#header(title) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/handy_toolbox/screen.rb', line 39

def header(title)
  title = " #{title}"[0, Curses.cols - 1]
  title = title.ljust(Curses.cols, SPACE)

  Ui.reverse do
    if scroll.fits_into_pane?(-scroll.top)
      Ui.text_at(0, -scroll.top, title)
    end
  end
end

#initObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/handy_toolbox/screen.rb', line 14

def init
  Curses.init_screen
  Curses.start_color
  Curses.use_default_colors if @default_colors
  Ui.hide_cursor
  Curses.cbreak
  Curses.crmode
  Curses.noecho
  Curses.nonl
  Curses.stdscr.keypad(true)
  @scroll = Scroll.new
end

#text_at(x, y, str) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/handy_toolbox/screen.rb', line 50

def text_at(x, y, str)
  if scroll.fits_into_pane?(y)
    str = str[0, Curses.cols - x - 1]
    Ui.text_at(x, y - scroll.top, str)
  end
  @max_y = y if @max_y < y
end