Class: OsCtl::Cli::Top::Tui

Inherits:
View
  • Object
show all
Defined in:
lib/osctl/cli/top/tui.rb,
lib/osctl/cli/top/tui/screen.rb

Defined Under Namespace

Modules: Key Classes: Help, Main, ModelThread, ProcessThread, Screen

Constant Summary collapse

SELECTED =
1
HIGHLIGHTED =
2
SELECTED_HIGHLIGHTED =
3

Instance Attribute Summary

Attributes inherited from View

#model, #rate

Instance Method Summary collapse

Constructor Details

#initialize(model, rate, enable_procs: true) ⇒ Tui

Returns a new instance of Tui.



10
11
12
13
# File 'lib/osctl/cli/top/tui.rb', line 10

def initialize(model, rate, enable_procs: true)
  super(model, rate)
  @enable_procs = enable_procs
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osctl/cli/top/tui.rb', line 15

def start
  Curses.init_screen
  Curses.start_color
  Curses.crmode
  Curses.stdscr.keypad = true
  Curses.curs_set(0) # hide cursor
  Curses.use_default_colors
  Curses.init_pair(SELECTED, Curses::COLOR_BLACK, Curses::COLOR_WHITE)
  Curses.init_pair(HIGHLIGHTED, Curses::COLOR_YELLOW, Curses::COLOR_BLACK)
  Curses.init_pair(SELECTED_HIGHLIGHTED, Curses::COLOR_RED, Curses::COLOR_WHITE)

  screen = Top::Tui::Main.new(model, rate, enable_procs: @enable_procs)

  loop do
    screen = screen.open
    break unless screen

    Curses.clear
  end
rescue Interrupt
  # stop
ensure
  Curses.close_screen
end