tty: hide cursor unless waiting for user input

Use vi (cursor_invisible) and ve (cursor_normal) to hide and show
cursor, if the terminal supports those.  This way on a slower
connection the cursor doesn't jump all over the place when doing
map or menu updates.
This commit is contained in:
Pasi Kallinen
2024-04-02 10:25:32 +03:00
parent de69dd750b
commit 7030b0b9fe
5 changed files with 28 additions and 0 deletions

View File

@@ -79,7 +79,9 @@ hooked_tty_getlin(
for (;;) {
(void) fflush(stdout);
Strcat(strcat(strcpy(gt.toplines, query), " "), obufp);
tty_curs_set(1);
c = pgetchar();
tty_curs_set(0);
if (c == '\033' || c == EOF) {
if (c == '\033' && obufp[0] != '\0') {
obufp[0] = '\0';

View File

@@ -36,6 +36,10 @@ static void kill_hilite(void);
/* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE, ul_hack */
struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE };
static char *nh_VI = (char *) 0; /* cursor_invisible */
static char *nh_VE = (char *) 0; /* cursor_normal */
/*static char *nh_VS = (char *) 0;*/ /* cursor_visible (highlighted cursor) */
static char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE;
static char *VS, *VE;
static char *ME, *MR, *MB, *MH, *MD;
@@ -280,6 +284,12 @@ tty_startup(int *wid, int *hgt)
if (!ME)
ME = SE ? SE : nullstr; /* default to SE value */
nh_VI = Tgetstr(nhStr("vi"));
nh_VE = Tgetstr(nhStr("ve"));
/*nh_VS = Tgetstr(nhStr("vs"));*/
if (!nh_VI || !nh_VE /*|| !nh_VS*/ )
nh_VI = nh_VE = /*nh_VS =*/ (char *) 0;
/* Get rid of padding numbers for nh_HI and nh_HE. Hope they
* aren't really needed!!! nh_HI and nh_HE are outputted to the
* pager as a string - so how can you send it NULs???
@@ -737,6 +747,16 @@ tty_nhbell(void)
(void) fflush(stdout);
}
/* hide or show cursor */
void
tty_curs_set(int visibility)
{
if (!visibility && nh_VI)
xputs(nh_VI);
else if (visibility && nh_VE)
xputs(nh_VE);
}
#ifdef ASCIIGRAPH
void
graph_on(void)

View File

@@ -542,6 +542,7 @@ tty_init_nhwindows(int *argcp UNUSED, char **argv UNUSED)
/* to port dependant tty setup */
tty_startup(&wid, &hgt);
setftty(); /* calls start_screen */
tty_curs_set(0);
/* set up tty descriptor */
ttyDisplay = (struct DisplayDesc *) alloc(sizeof (struct DisplayDesc));
@@ -807,6 +808,7 @@ tty_exit_nhwindows(const char *str)
{
winid i;
tty_curs_set(1);
tty_suspend_nhwindows(str);
/*
* Disable windows to avoid calls to window routines.
@@ -3985,6 +3987,7 @@ tty_nhgetch(void)
HUPSKIP_RESULT('\033');
print_vt_code1(AVTC_INLINE_SYNC);
tty_curs_set(1);
(void) fflush(stdout);
/* Note: if raw_print() and wait_synch() get called to report terminal
* initialization problems, then wins[] and ttyDisplay might not be
@@ -4018,6 +4021,7 @@ tty_nhgetch(void)
}
#endif
}
tty_curs_set(0);
if (!i)
i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
else if (i == EOF)