summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libunix.cc
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2013-05-25 20:52:22 -0400
committerNeil Moore <neil@s-z.org>2013-05-25 20:52:22 -0400
commita797ddd80afb1e0cee4e4c84e61a58efc3a3202d (patch)
treec7dd0a3e7ecfbbfe0b38743ec1ad16d062647073 /crawl-ref/source/libunix.cc
parent3f17ee72a6259543f5200a1f1b06103f65c359ca (diff)
downloadcrawl-ref-a797ddd80afb1e0cee4e4c84e61a58efc3a3202d.tar.gz
crawl-ref-a797ddd80afb1e0cee4e4c84e61a58efc3a3202d.zip
Fix ctrl-h on terminals where that is the same as backspace (hhkb)
If the terminfo "kbs" (key_backspace) attribute is ctrl-h, curses will treat any occurence of ctrl-h as KEY_BACKSPACE. Work around that by converting back to CK_BKSP == 0x8 (ctrl-h) if kbs is set ctrl-h. However, on sane terminals where backspace generates ctrl-?, don't smash the two. Fixes #7013.
Diffstat (limited to 'crawl-ref/source/libunix.cc')
-rw-r--r--crawl-ref/source/libunix.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc
index 3060c48039..eeb8419d55 100644
--- a/crawl-ref/source/libunix.cc
+++ b/crawl-ref/source/libunix.cc
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <stdarg.h>
#include <ctype.h>
+#include <term.h>
#define _LIBUNIX_IMPLEMENTATION
#include "libunix.h"
#include "defines.h"
@@ -384,6 +385,14 @@ int unixcurses_get_vi_key(int keyin)
case KEY_SLEFT: return 'H';
case KEY_SRIGHT: return 'L';
case KEY_BTAB: return CK_SHIFT_TAB;
+ case KEY_BACKSPACE:
+ // If key_backspace (kbs) is ctrl-h, curses generates KEY_BACKSPACE
+ // for the ctrl-h key. Work around that by converting back to CK_BKSP.
+ static const char * const kbs = tigetstr("kbs");
+ static const int bskey = (kbs && kbs != (const char *) -1
+ && kbs == string("\010")) ? CK_BKSP
+ : KEY_BACKSPACE;
+ return bskey;
}
return keyin;
}