summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-10-25 14:28:20 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-10-25 14:28:20 +0000
commit97a279e22975aa71fdf67c7e6157b175e0eeb20b (patch)
tree5edad3b67933f511d804b9299a7710db33ae0ae6 /src
parent57b55a58242c806869eb1e8c1b08c6f7f6f69d32 (diff)
add alt-key binding support
bind alt-[tTfF] to backward version of [tTfF]
Diffstat (limited to 'src')
-rw-r--r--src/main.cc27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/main.cc b/src/main.cc
index 92d26a52..0750ffc8 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -542,6 +542,14 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'U', [](Window& window, int count) { do { if (not window.redo()) { print_status("nothing left to redo"); break; } } while(--count > 0); } },
};
+std::unordered_map<char, std::function<void (Window& window, int count)>> alt_keymap =
+{
+ { 't', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false)); } },
+ { 'f', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true)); } },
+ { 'T', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false), true); } },
+ { 'F', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true), true); } },
+};
+
int main(int argc, char* argv[])
{
init_ncurses();
@@ -571,6 +579,7 @@ int main(int argc, char* argv[])
try
{
char c = getch();
+
std::ostringstream oss;
oss << "key " << int(c) << " (" << c << ")\n";
write_debug(oss.str());
@@ -579,9 +588,23 @@ int main(int argc, char* argv[])
count = count * 10 + c - '0';
else
{
- if (keymap.find(c) != keymap.end())
+ bool is_alt = false;
+ if (c == 27)
+ {
+ timeout(0);
+ char new_c = getch();
+ timeout(-1);
+ if (new_c != ERR)
+ {
+ c = new_c;
+ is_alt = true;
+ }
+ }
+ auto& active_keymap = is_alt ? alt_keymap : keymap;
+
+ if (active_keymap.find(c) != active_keymap.end())
{
- keymap[c](*current_window, count);
+ active_keymap[c](*current_window, count);
draw_window(*current_window);
}
count = 0;