Bind ^S to search, as in Emacs, with a trick

We heavily depend on ncurses anyway, so no worries about portability.
This commit is contained in:
Přemysl Eric Janouch 2021-10-18 11:23:17 +02:00
parent 536aa57761
commit aeffe40efc
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 10 additions and 1 deletions

11
sdn.cpp
View File

@ -51,6 +51,11 @@
#include <acl/libacl.h> #include <acl/libacl.h>
#include <ncurses.h> #include <ncurses.h>
// To implement cbreak() with disabled ^S that gets reënabled on endwin()
#define NCURSES_INTERNALS
#include <term.h>
#undef CTRL // term.h -> termios.h -> sys/ttydefaults.h, too simplistic
// Unicode is complex enough already and we might make assumptions // Unicode is complex enough already and we might make assumptions
#ifndef __STDC_ISO_10646__ #ifndef __STDC_ISO_10646__
#error Unicode required for wchar_t #error Unicode required for wchar_t
@ -439,7 +444,7 @@ static map<wint_t, action> g_normal_actions {
{CTRL ('Y'), ACTION_SCROLL_UP}, {CTRL ('E'), ACTION_SCROLL_DOWN}, {CTRL ('Y'), ACTION_SCROLL_UP}, {CTRL ('E'), ACTION_SCROLL_DOWN},
{'c', ACTION_CHDIR}, {ALT | KEY (UP), ACTION_PARENT}, {'c', ACTION_CHDIR}, {ALT | KEY (UP), ACTION_PARENT},
{'&', ACTION_GO_START}, {'~', ACTION_GO_HOME}, {'&', ACTION_GO_START}, {'~', ACTION_GO_HOME},
{'/', ACTION_SEARCH}, {'s', ACTION_SEARCH}, {'/', ACTION_SEARCH}, {'s', ACTION_SEARCH}, {CTRL ('S'), ACTION_SEARCH},
{ALT | 'e', ACTION_RENAME_PREFILL}, {'e', ACTION_RENAME}, {ALT | 'e', ACTION_RENAME_PREFILL}, {'e', ACTION_RENAME},
{KEY (F (6)), ACTION_RENAME_PREFILL}, {KEY (F (7)), ACTION_MKDIR}, {KEY (F (6)), ACTION_RENAME_PREFILL}, {KEY (F (7)), ACTION_MKDIR},
{'t', ACTION_TOGGLE_FULL}, {ALT | 't', ACTION_TOGGLE_FULL}, {'t', ACTION_TOGGLE_FULL}, {ALT | 't', ACTION_TOGGLE_FULL},
@ -1832,6 +1837,10 @@ int main (int argc, char *argv[]) {
pop_levels (g.cwd); pop_levels (g.cwd);
update (); update ();
// This gets applied along with the following halfdelay()
cur_term->Nttyb.c_cc[VSTOP] =
cur_term->Nttyb.c_cc[VSTART] = _POSIX_VDISABLE;
// Invoking keypad() earlier would make ncurses flush its output buffer, // Invoking keypad() earlier would make ncurses flush its output buffer,
// which would worsen start-up flickering // which would worsen start-up flickering
if (halfdelay (1) == ERR || keypad (stdscr, TRUE) == ERR) { if (halfdelay (1) == ERR || keypad (stdscr, TRUE) == ERR) {