キーボード型ランチャーの試作

キーボード型ランチャーというか登録したRubyのメソッドを呼び出すランチャーをVisualuRubyで試作してみました。補完機能付きです。この機能の実装にabbrevモジュールは便利です。エンターとかエスケープを押したときにポーンって音が鳴る(Beep?)のですが、これなんとか消せないのかな。。。
ファイル: cl.rb

#!/usr/bin/env ruby

require 'abbrev'
require "vr/vrcontrol"
require "vr/vrlayout"
require "vr/vrhandler"

class Command
  def Command.match(s)
    COMMANDS[s]
  end

  def Command.launch(s, *args)
    m = Command.match(s)
    raise "Command not found. #{s}" unless m
    new().send(m, *args)
  end

  meths = new().methods

  def quit
    exit
  end

  Dir.glob('plugin/*.rb') do |file|
    eval(File.read(file))
  end

  COMMANDS = (new().methods - meths).abbrev
end

class VRHookedEdit < VREdit
  include VRKeyFeasible

  def vrinit
    super
    add_parentcall('char')
  end
end

module CLForm
  include VRVertLayoutManager
  include VRCtlColor

  def construct
    self.caption = 'cl'
    addControl(VRHookedEdit, 'edit1', '')
    addCtlColor(@edit1)
    edit1_ng_color

    @press_valid_command_key_f = false
  end

  def edit1_char(ansi, keydata)
    case ansi.chr
    when "\r" # Enter
      begin
        m = Command.match(@edit1.text)
        Command.launch(@edit1.text) if m
      rescue Exception => ex
        raise ex if ex.class == SystemExit
        messageBox(ex)
      end
    when "\e" # Escape
      @edit1.text = ''
      edit1_ng_color
    when "\b" # BackSpace
      m = Command.match(@edit1.text[0 .. -2])
      setChildBkColor(@edit1, RGB(0xff, 0xcc, 0xcc)) unless m
    when /\w/ # Command Chars
      @press_valid_command_key_f = true
    end
  end

  def edit1_changed
    return unless @press_valid_command_key_f
    @press_valid_command_key_f = false

    s = @edit1.text
    m = Command.match(s)
    if m
      @edit1.text = m
      @edit1.setSel(s.size, m.size)
      edit1_ok_color
    else
      edit1_ng_color
    end
    refresh
  end

  def edit1_ok_color
    setChildBkColor(@edit1, RGB(0xcc, 0xff, 0xcc))
  end

  def edit1_ng_color
    setChildBkColor(@edit1, RGB(0xff, 0xcc, 0xcc))
  end
end

VRLocalScreen.showForm(CLForm, 500, 500, 200, 50)
VRLocalScreen.messageloop

ファイル: plugin/sample.rb

def notepad
  `notepad.exe`
end