Register key bindings in the env with RunControl

This commit is contained in:
Thibault Jouan
2015-04-14 21:26:29 +00:00
parent b1aa430ef3
commit 2a1a1f1185
5 changed files with 31 additions and 4 deletions

View File

@@ -13,12 +13,13 @@ module Uh
def_delegator :logger, :debug, :log_debug
def_delegator :@output, :print
attr_reader :output
attr_reader :output, :keybinds
attr_accessor :verbose, :debug, :rc_path, :layout_class
def initialize output
@output = output
@rc_path = RC_PATH
@keybinds = {}
end
def verbose?

View File

@@ -16,6 +16,10 @@ module Uh
def evaluate code
instance_eval code
end
def key keysym, &block
@env.keybinds[keysym] = block
end
end
end
end

View File

@@ -44,6 +44,9 @@ module Uh
def connect_manager
@manager.connect
@manager.grab_key :q
@env.keybinds.each do |keysym, _|
@manager.grab_key *keysym
end
end
def run_until &block
@@ -70,6 +73,9 @@ module Uh
def register_key_bindings_hooks
@events.on(:key, :q) { stop! }
@env.keybinds.each do |keysym, code|
@events.on :key, keysym, &code
end
end
end
end