summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-11-09 11:12:55 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-11-09 11:12:55 +0000
commit4b518ee6b97d0db39f5daf8a327f3515ce6e92a5 (patch)
treec49d384bddab1e41677b592ac415a46ec26ce147 /src
parenta7ed017ef384cce66f60b986282521a8380ea58f (diff)
Add support for function keys F1-F12
Diffstat (limited to 'src')
-rw-r--r--src/keys.cc28
-rw-r--r--src/keys.hh12
-rw-r--r--src/ncurses.cc6
3 files changed, 46 insertions, 0 deletions
diff --git a/src/keys.cc b/src/keys.cc
index 98909029..17789ccd 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -80,6 +80,29 @@ KeyList parse_keys(const String& str)
pos = end_pos;
continue;
}
+ if ((keyname[0] == 'f' or keyname[0] == 'F') and
+ keyname.length() <= 3)
+ {
+
+ int val = 0;
+ for (auto i = 1_byte; i < keyname.length(); ++i)
+ {
+ char c = keyname[i];
+ if (c >= '0' and c <= '9')
+ val = val*10 + c - '0';
+ else
+ {
+ val = -1;
+ break;
+ }
+ }
+ if (val >= 1 and val <= 12)
+ {
+ result.push_back(Key{ modifier, Key::F1 + (val - 1) });
+ pos = end_pos;
+ continue;
+ }
+ }
}
}
result.push_back({Key::Modifiers::None, Codepoint(str[pos])});
@@ -98,6 +121,11 @@ String key_to_str(Key key)
named = true;
res = it->first;
}
+ else if (key.key >= Key::F1 and key.key < Key::F12)
+ {
+ named = true;
+ res = "F" + to_string((int)(Codepoint)key.key - (int)(Codepoint)Key::F1 + 1);
+ }
else
res = codepoint_to_str(key.key);
diff --git a/src/keys.hh b/src/keys.hh
index 05254f62..10cb3c5d 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -32,6 +32,18 @@ struct Key
Home,
End,
BackTab,
+ F1,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
Invalid,
};
diff --git a/src/ncurses.cc b/src/ncurses.cc
index 4bd1b3b0..fc1560a5 100644
--- a/src/ncurses.cc
+++ b/src/ncurses.cc
@@ -354,6 +354,12 @@ Key NCursesUI::get_key()
case KEY_BTAB: return Key::BackTab;
}
+ for (int i = 0; i < 12; ++i)
+ {
+ if (c == KEY_F(i+1))
+ return Key::F1 + i;
+ }
+
if (c >= 0 and c < 256)
{
ungetch(c);