Module: Menuboy

Defined in:
lib/menuboy.rb,
lib/menuboy/version.rb

Defined Under Namespace

Modules: DSL, UnbufferedKeyboardHandler Classes: Menu, Option

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.fix_stdinObject

Use this if you need to re-enable buffering as menuboy disables this by default on STDIN You don’t need this when using #system but you’ll want it if you get user input directly



48
49
50
51
52
# File 'lib/menuboy.rb', line 48

def self.fix_stdin
  self.normal_terminal
  yield
  self.raw_terminal
end

.keyboard_input(k) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/menuboy.rb', line 21

def self.keyboard_input k
  puts k
  menu = Menuboy.menus.last
  if k == "q"
    Menuboy.menus.pop
    if next_menu = Menuboy.menus.last
      next_menu.print_help
    else
      exit # no more menus
    end
  else
    menu.handle_input(k)
  end
  Menuboy.menus.last.prompt
end


54
55
56
# File 'lib/menuboy.rb', line 54

def self.menus
  @menus ||= []
end

.normal_terminalObject



17
18
19
# File 'lib/menuboy.rb', line 17

def self.normal_terminal
  Termios::tcsetattr($stdin, Termios::TCSANOW, @termios_normal_attributes)
end

.raw_terminalObject



10
11
12
13
14
15
# File 'lib/menuboy.rb', line 10

def self.raw_terminal
  attributes = @termios_normal_attributes.dup
  attributes.lflag &= ~Termios::ECHO
  attributes.lflag &= ~Termios::ICANON
  Termios::tcsetattr($stdin, Termios::TCSANOW, attributes)
end