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

Inherits:
Screen
  • Object
show all
Defined in:
lib/osctl/cli/top/tui/help.rb

Instance Method Summary collapse

Constructor Details

#initialize(main_screen) ⇒ Help

Returns a new instance of Help



6
7
8
# File 'lib/osctl/cli/top/tui/help.rb', line 6

def initialize(main_screen)
  @main_screen = main_screen
end

Instance Method Details

#openObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/osctl/cli/top/tui/help.rb', line 10

def open
  loop do
    render

    case Curses.getch
    when 'q', '?', 27 # Escape
      return @main_screen

    when Curses::Key::RESIZE
      Curses.clear
    end
  end
end

#renderObject (protected)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/osctl/cli/top/tui/help.rb', line 25

def render
  Curses.setpos(0, 0)
  Curses.addstr('Key bindings:')

  pos = 0

  [
    ['q', 'Quit'],
    ['<, >, left, right', 'Change sort column'],
    ['r, R', 'Reverse sort order'],
    ['up, down', 'Select containers'],
    ['space', 'Highlight selected container'],
    ['enter', 'Open htop and filter container processes'],
    ['m', 'Toggle between realtime and cumulative mode'],
    ['p', 'Pause/unpause resource tracking'],
    ['?', 'Show/hide this help message'],
  ].each_with_index do |arr, i|
    key, desc = arr

    Curses.setpos(i+2, 4)
    Curses.addstr(sprintf('%20s - %s', key, desc))

    pos = i+2
  end

  Curses.setpos(pos+2, 0)
  Curses.addstr("Press 'q', '?' or <Esc> to continue")
end