summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-04-11 20:29:35 +1000
committerMaxime Coste <mawww@kakoune.org>2018-04-11 20:39:57 +1000
commit5fa19f4d7f51cde9b06a435aba8ca13859b6e80c (patch)
treeb08ed9a20111dd4ddf7b30334c1abaee11876c33 /src
parent50e422659bb1533da2d5f04bbd17de062dcad84b (diff)
NCursesUI: Add support for shifted function keys
Shifted function keys are not well standardized around terminals, Shift F(N) usually returns F(X) + N, with X=12 on xterm, X=10 on rxvt-unicode... Default to X=12 and make it configuable through the ncurses_shift_function_key ui_option. This fixes what #1898 tried to.
Diffstat (limited to 'src')
-rw-r--r--src/main.cc3
-rw-r--r--src/ncurses_ui.cc13
-rw-r--r--src/ncurses_ui.hh3
3 files changed, 17 insertions, 2 deletions
diff --git a/src/main.cc b/src/main.cc
index e152fa94..26cb1ebf 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -360,7 +360,8 @@ void register_options()
" ncurses_enable_mouse bool\n"
" ncurses_change_colors bool\n"
" ncurses_wheel_up_button int\n"
- " ncurses_wheel_down_button int\n",
+ " ncurses_wheel_down_button int\n"
+ " ncurses_shift_function_key int\n",
UserInterface::Options{});
reg.declare_option("modelinefmt", "format string used to generate the modeline",
"%val{bufname} %val{cursor_line}:%val{cursor_char_column} {{context_info}} {{mode_info}} - %val{client}@[%val{session}]"_str);
diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc
index e6863945..9514af07 100644
--- a/src/ncurses_ui.cc
+++ b/src/ncurses_ui.cc
@@ -29,6 +29,8 @@ using std::max;
struct NCursesWin : WINDOW {};
+constexpr int NCursesUI::default_shift_function_key;
+
static constexpr StringView assistant_cat[] =
{ R"( ___ )",
R"( (__ \ )",
@@ -615,8 +617,10 @@ Optional<Key> NCursesUI::get_next_key()
for (int i = 0; i < 12; ++i)
{
- if (c == KEY_F(i+1))
+ if (c == KEY_F(i + 1))
return {Key::F1 + i};
+ if (c == KEY_F(m_shift_function_key + i + 1))
+ return shift(Key::F1 + i);
}
if (c >= 0 and c < 256)
@@ -1083,6 +1087,13 @@ void NCursesUI::set_ui_options(const Options& options)
}
{
+ auto it = options.find("ncurses_shift_function_key"_sv);
+ m_shift_function_key = it != options.end() ?
+ str_to_int_ifp(it->value).value_or(default_shift_function_key)
+ : default_shift_function_key;
+ }
+
+ {
auto it = options.find("ncurses_change_colors"_sv);
auto value = it == options.end() or
(it->value == "yes" or it->value == "true");
diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh
index 35889193..d2449d59 100644
--- a/src/ncurses_ui.hh
+++ b/src/ncurses_ui.hh
@@ -140,6 +140,9 @@ private:
int m_wheel_up_button = 4;
int m_wheel_down_button = 5;
+ static constexpr int default_shift_function_key = 12;
+ int m_shift_function_key = default_shift_function_key;
+
bool m_set_title = true;
bool m_change_colors = true;