Skip to content

Add ncurses extended key support#1048

Closed
mckellyln wants to merge 1 commit intojonas:masterfrom
mckellyln:extended_keys
Closed

Add ncurses extended key support#1048
mckellyln wants to merge 1 commit intojonas:masterfrom
mckellyln:extended_keys

Conversation

@mckellyln
Copy link
Copy Markdown
Contributor

@mckellyln mckellyln commented Nov 9, 2020

Keys added, if terminfo reports feature -

    { "kUP3",   "Alt-Up",              "A-Up"          },
    { "kUP4",   "Alt-Shift-Up",        "A-S-Up"        },
    { "kUP5",   "Ctrl-Up",             "C-Up"          },
    { "kUP6",   "Ctrl-Shift-Up",       "C-S-Up"        },
    { "kUP7",   "Alt-Ctrl-Up",         "A-C-Up"        },
    { "kDN3",   "Alt-Down",            "A-Down"        },
    { "kDN4",   "Alt-Shift-Down",      "A-S-Down"      },
    { "kDN5",   "Ctrl-Down",           "C-Down"        },
    { "kDN6",   "Ctrl-Shift-Down" ,    "C-S-Down"      },
    { "kDN7",   "Alt-Ctrl-Down",       "A-C-Down"      },
    { "kRIT3",  "Alt-Right",           "A-Right"       },
    { "kRIT4",  "Alt-Shift-Right",     "A-S-Right"     },
    { "kRIT5",  "Ctrl-Right",          "C-Right"       },
    { "kRIT6",  "Ctrl-Shift-Right",    "C-S-Right"     },
    { "kRIT7",  "Alt-Ctrl-Right",      "A-C-Right"     },
    { "kLFT3",  "Alt-Left",            "A-Left"        },
    { "kLFT4",  "Alt-Shift-Left",      "A-S-Left"      },
    { "kLFT5",  "Ctrl-Left",           "C-Left"        },
    { "kLFT6",  "Ctrl-Shift-Left",     "C-S-Left"      },
    { "kLFT7",  "Alt-Ctrl-Left",       "A-C-Left"      },
    { "kIC3",   "Alt-Insert",          "A-Insert"      },
    { "kIC4",   "Alt-Shift-Insert",    "A-S-Insert"    },
    { "kIC5",   "Ctrl-Insert",         "C-Insert"      },
    { "kIC6",   "Ctrl-Shift-Insert",   "C-S-Insert"    },
    { "kIC7",   "Alt-Ctrl-Insert",     "A-C-Insert"    },
    { "kDC3",   "Alt-Delete",          "A-Delete"      },
    { "kDC4",   "Alt-Shift-Delete",    "A-S-Delete"    },
    { "kDC5",   "Ctrl-Delete",         "C-Delete"      },
    { "kDC6",   "Ctrl-Shift-Delete",   "C-S-Delete"    },
    { "kDC7",   "Alt-Ctrl-Delete",     "A-C-Delete"    },
    { "kHOM3",  "Alt-Home",            "A-Home"        },
    { "kHOM4",  "Alt-Shift-Home",      "A-S-Home"      },
    { "kHOM5",  "Ctrl-Home",           "C-Home"        },
    { "kHOM6",  "Ctrl-Shift-Home",     "C-S-Home"      },
    { "kHOM7",  "Alt-Ctrl-Home",       "A-C-Home"      },
    { "kEND3",  "Alt-End",             "A-End"         },
    { "kEND4",  "Alt-Shift-End",       "A-S-End"       },
    { "kEND5",  "Ctrl-End",            "C-End"         },
    { "kEND6",  "Ctrl-Shift-End",      "C-S-End"       },
    { "kEND7",  "Alt-Ctrl-End",        "A-C-End"       },
    { "kNXT3",  "Alt-PageDown",        "A-PageDown"    },
    { "kNXT4",  "Alt-Shift-PageDown",  "A-S-PageDown"  },
    { "kNXT5",  "Ctrl-PageDown",       "C-PageDown"    },
    { "kNXT6",  "Ctrl-Shift-PageDown", "C-S-PageDown"  },
    { "kNXT7",  "Alt-Ctrl-PageDown",   "A-C-PageDown"  },
    { "kPRV3",  "Alt-PageUp",          "A-PageUp"      },
    { "kPRV4",  "Alt-Shift-PageUp",    "A-S-PageUp"    },
    { "kPRV5",  "Ctrl-PageUp",         "C-PageUp"      },
    { "kPRV6",  "Ctrl-Shift-PageUp",   "C-S-PageUp"    },
    { "kPRV7",  "Alt-Ctrl-PageUp",     "A-C-PageUp"    }

@mckellyln
Copy link
Copy Markdown
Contributor Author

First attempt at adding ncurses extended key support.
There are some interesting routines such as:
use_extended_names()
keyok()
keybound()
define_key()
key_defined()
which may be a better way to go, but either way the effort here is only because the option bind work comes before initscr() is called so at that moment we do not know the correct ncurses values for the extended keys.

@mckellyln
Copy link
Copy Markdown
Contributor Author

mckellyln commented Nov 9, 2020

I bind:

bind generic   <Ctrl-Down>  scroll-line-down
bind generic   <Ctrl-Up>    scroll-line-up

And for that to work nicely imho I also made some changes in another branch scroll_updates.
All my recent changes are in all_updates.

@mckellyln
Copy link
Copy Markdown
Contributor Author

I'll look into a commit tomorrow that prints a warning at exit if a key used in a binding is not supported by the terminal.

@mckellyln
Copy link
Copy Markdown
Contributor Author

Added exit print of warnings if binding an extended key that is not supported by terminfo.
Added as a second commit. I can squash if you want, just let me know.
@koutcher let me know if you find any of this helpful.
thx,
-m

@mckellygit
Copy link
Copy Markdown
Contributor

mckellygit commented Nov 11, 2020

We could add <C-*> and <A-*> entries also.

@mckellygit
Copy link
Copy Markdown
Contributor

An easier way might be to just add -

    int i;
    for (i=KEY_MAX; i<2000; i++)
        keyok(i, false);

at the end of init_display(). And then use the explicit mappings:

bind generic   <Esc>[1;5B    scroll-line-down
bind generic   <Esc>[1;5A    scroll-line-up

What do you think ?

@mckellygit
Copy link
Copy Markdown
Contributor

Added support for the abbreviated <C-*> and <A-*> bindings and made exit print to stderr

@mckellygit
Copy link
Copy Markdown
Contributor

mckellygit commented Nov 12, 2020

Alt (3) and Control (5) are supported here. We could also try to add these (if supported and not already mapped) -
``
4 - Shift + Alt
6 - Shift + Control
7 - Alt + Control

@mckellygit
Copy link
Copy Markdown
Contributor

I've added support for the additional extended keys.
I'll also submit a PR for the opposite, disabling all extended keys so the explicit mappings work, and leave it at that.
thx again for tig,
-m

@mckellygit
Copy link
Copy Markdown
Contributor

squashed commits

@Lenbok
Copy link
Copy Markdown

Lenbok commented Dec 8, 2020

Would you expect that with this PR I could:

bind generic <Alt-V> move-page-up

and have it work?

@mckellyln
Copy link
Copy Markdown
Contributor Author

mckellyln commented Dec 8, 2020

Hi.
No, Alt-V is nothing special, what kind of system/terminal do you use ?
For most linux terminals, that should work as an Esc-V, so something like:

bind generic <Ctrl-[>v move-page-up

I dont know if you meant to type an upper-case 'V' or a lower-case 'v' ? My example above uses a lower-case 'v'. If you changed it to upper-case in the binding then it would be Alt+Shift+V pressed all at once.

@Lenbok
Copy link
Copy Markdown

Lenbok commented Dec 8, 2020

Thanks - it looks like it's mostly a case of the binding syntax being a bit idiosyncratic / undescribed. I worked out the bindings I was trying to get, see: #131 (comment)

@mckellyln
Copy link
Copy Markdown
Contributor Author

mckellyln commented Dec 8, 2020

ok, sure.

<Esc>v
<Ctrl-[>v

are the same :-)

@mckellyln
Copy link
Copy Markdown
Contributor Author

Closing for now.
Happy to re-work this as needed.
Note we can now use esc-codes to get this same functionality.
thx for tig,
-m

@mckellyln mckellyln closed this Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants