class HandyToolbox::Screen

Constants

SPACE

Attributes

screen[R]
scroll[R]

Public Class Methods

new(default_colors: false) click to toggle source
# File lib/handy_toolbox/screen.rb, line 10
def initialize(default_colors: false)
  @default_colors = default_colors
end

Public Instance Methods

clear() click to toggle source
# File lib/handy_toolbox/screen.rb, line 27
def clear
  scroll.reset
  Curses.clear
end
close() click to toggle source
# File lib/handy_toolbox/screen.rb, line 58
def close
  Curses.close_screen
end
draw() { || ... } click to toggle source
# File lib/handy_toolbox/screen.rb, line 32
def draw
  @max_y = 0
  yield
  @scroll.update(@max_y)
  Curses.refresh
end
header(title) click to toggle source
# 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
init() click to toggle source
# 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) click to toggle source
# 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