Skip to content

Commit 56e99d6

Browse files
committed
Add keybindings to config file.
1 parent 399746c commit 56e99d6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

hatterrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ maildir_format = maildir
1313
termbox_library_path = /usr/lib/libtermbox.so
1414

1515
# All the colors i Hatter can be customized:
16-
colors = {foreground => green, background => black}
16+
colors = { foreground => green, background => black }
17+
18+
# The keybindings for Hatter can be changed here:
19+
keys = { q => quit, r => reply, f => forward }

lib/command_factory.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ def initialize(terminal)
1010
# @param key [Symbol] the key the user pressed on the keyboard.
1111
# @return [Command] the command the user wishes to execute.
1212
def command(key)
13-
case key
14-
when :q
13+
keys = configuration.instance.keys
14+
cmd = eval "#{keys}.#{key}"
15+
cmd.capitalize! << "Command"
16+
case cmd
17+
when /QuitCommand/
1518
QuitCommand.new(@terminal)
1619
else
1720
NoOpCommand.new

lib/configuration.rb

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class Colors < ConfigToolkit::BaseConfig
1818
add_required_param(:background, String)
1919
end
2020

21+
class Keys < ConfigToolkit::BaseConfig
22+
add_required_param(:q, String)
23+
add_required_param(:r, String)
24+
add_required_param(:f, String)
25+
end
26+
2127
add_required_param(:maildir, String)
2228
add_required_param(:maildir_format, String)
2329
add_required_param(:termbox_library_path, String)

0 commit comments

Comments
 (0)