Class: MyMenu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMyMenu

Returns a new instance of MyMenu.



17
18
19
20
21
22
23
24
25
26
# File 'lib/mymenu.rb', line 17

def initialize
  @mymenuname = "MyMenu"
  @prompt = "MyPrompt"
  @promptcolor = "\e[1;32m\ ".strip
  @menuitems = Array.new
  @menuitemnumbercolor = "\e[1;36m"
  @mymenugreeting = "Welcome to MyMenu"
  @mymenutoggle = true
  @debug = 0
end

Instance Attribute Details

#debug=(value) ⇒ Object (writeonly)

Sets the attribute debug

Parameters:

  • value

    the value to set the attribute debug to.



14
15
16
# File 'lib/mymenu.rb', line 14

def debug=(value)
  @debug = value
end

Returns the value of attribute menuitems.



15
16
17
# File 'lib/mymenu.rb', line 15

def menuitems
  @menuitems
end

Sets the attribute menutitlecolour

Parameters:

  • value

    the value to set the attribute menutitlecolour to.



14
15
16
# File 'lib/mymenu.rb', line 14

def menutitlecolour=(value)
  @menutitlecolour = value
end

#mymenugreeting=(value) ⇒ Object (writeonly)

Sets the attribute mymenugreeting

Parameters:

  • value

    the value to set the attribute mymenugreeting to.



14
15
16
# File 'lib/mymenu.rb', line 14

def mymenugreeting=(value)
  @mymenugreeting = value
end

#mymenuname=(value) ⇒ Object (writeonly)

Sets the attribute mymenuname

Parameters:

  • value

    the value to set the attribute mymenuname to.



14
15
16
# File 'lib/mymenu.rb', line 14

def mymenuname=(value)
  @mymenuname = value
end

#mymenushow=(value) ⇒ Object (writeonly)

Sets the attribute mymenushow

Parameters:

  • value

    the value to set the attribute mymenushow to.



14
15
16
# File 'lib/mymenu.rb', line 14

def mymenushow=(value)
  @mymenushow = value
end

#prompt=(value) ⇒ Object (writeonly)

Sets the attribute prompt

Parameters:

  • value

    the value to set the attribute prompt to.



14
15
16
# File 'lib/mymenu.rb', line 14

def prompt=(value)
  @prompt = value
end

#promptcolor=(value) ⇒ Object (writeonly)

Sets the attribute promptcolor

Parameters:

  • value

    the value to set the attribute promptcolor to.



14
15
16
# File 'lib/mymenu.rb', line 14

def promptcolor=(value)
  @promptcolor = value
end

Instance Method Details

#additemtolist(number, name, func) ⇒ Object



30
31
32
# File 'lib/mymenu.rb', line 30

def additemtolist(number, name, func)
  @menuitems << [number, "#{name}", "#{func}"]
end

#definemenuitem(func, readlineprompt = false, args = nil, &codeeval) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mymenu.rb', line 61

def definemenuitem(func, readlineprompt=false, args=nil, &codeeval)
  func_name = func.to_sym
  if args == nil
    Kernel.send :define_method, func_name do
      evalreadline?(readlineprompt) do
        puts "Without args" if @debug >= 2
        codeeval.call
      end
    end
  else
    Kernel.send :define_method, func_name do |args|
      evalreadline?(readlineprompt) do
        puts "With args" if @debug >= 2
        codeeval.call
      end
    end    
  end
end


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mymenu.rb', line 44

def menu!
  menubuilder
  createmenu("0")
  showmenu
  while buf = Readline.readline("#{@promptcolor}#{@prompt}>\e[0m\ ", true)
    trap("INT") {
      puts "\nGoodbye see yall later!!!"
      exit
    }
    begin
      showmenu
      createmenu(buf)
    rescue NoMethodError
    end
  end
end

#settitle(title) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/mymenu.rb', line 34

def settitle(title)
  @mymenugreeting = title
  @menutitlecolor = "\e[1;38m"    
  @menutitle = %Q{\n
/=========================\e[0m\ 
\e[1;38m|   #{@mymenugreeting}    |\e[0m\ 
\e[1;38m\=========================/\e[0m\ \n
}
end