Class: Flumtter::Window::Dialog
- Defined in:
- lib/flumtter/app/core/windows/dialog.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call(str) ⇒ Object
- #command(command, help = "", &blk) ⇒ Object
-
#initialize(*args) ⇒ Dialog
constructor
A new instance of Dialog.
- #show(recall = false, help = true) ⇒ Object
Methods included from Dispel::Util
#add_multiline_str, #addstr, #getstr
Constructor Details
#initialize(*args) ⇒ Dialog
6 7 8 9 |
# File 'lib/flumtter/app/core/windows/dialog.rb', line 6 def initialize(*args) super @commands = [] end |
Instance Method Details
#call(str) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flumtter/app/core/windows/dialog.rb', line 15 def call(str) if str == "?" Window::Popup.new("Command List", " \#{Command.list(@commands)}\n EOF\n raise Dispel::Recall\n else\n @commands.each do |command|\n if m = str.match(command.command)\n return command.call(m)\n end\n end\n raise Dispel::NoCommandError\n end\nend\n").show |
#command(command, help = "", &blk) ⇒ Object
11 12 13 |
# File 'lib/flumtter/app/core/windows/dialog.rb', line 11 def command(command, help="", &blk) @commands << Command.new(command, help, &blk) end |
#show(recall = false, help = true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/flumtter/app/core/windows/dialog.rb', line 31 def show(recall=false, help=true) Dispel::Screen.open do |screen| Dispel::Window.open(@hight, @width, 0, 0) do |win| win.box(?|,?-,?*) win.setpos(win.cury+2, win.curx+1) win.addstr @title.title win.setpos(win.cury+1, 1) win.addstr "¯"*(@title.title.size+2) add_multiline_str(win, @body) if block_given? yield win else win.setpos(win.cury+2, 1) if help win.addstr "help: ?".rjust(win.maxx - 2) win.setpos(win.cury+1, 1) end call getstr(win) end end end rescue Dispel::Recall show(recall, help) rescue Dispel::NoCommandError => e Window::Popup::Error.new(e.class.to_s).show show(recall, help) if recall end |