Skip to content

Commit

Permalink
NCursesUI: Add support for shifted function keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mawww committed Apr 11, 2018
1 parent 50e4226 commit 5fa19f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/pages/options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,7 @@ are exclusively available to built-in options.

*ncurses_wheel_down_button*, *ncurses_wheel_up_button*:::
specify which button send for wheel down/up events

*ncurses_shift_function_key*:::
Function key from which shifted function key start, if th

This comment has been minimized.

Copy link
@lenormf

lenormf Apr 11, 2018

Contributor

"if th" :)

terminal sends F13 for <s-F1>, this should be set to 12.
3 changes: 2 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/ncurses_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using std::max;

struct NCursesWin : WINDOW {};

constexpr int NCursesUI::default_shift_function_key;

static constexpr StringView assistant_cat[] =
{ R"( ___ )",
R"( (__ \ )",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1082,6 +1086,13 @@ void NCursesUI::set_ui_options(const Options& options)
(it->value == "yes" or it->value == "true");
}

{
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
Expand Down
3 changes: 3 additions & 0 deletions src/ncurses_ui.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5fa19f4

Please sign in to comment.