fix up PDCurses cursor placement for prompts

This commit is contained in:
nhmall
2018-12-14 23:08:41 -05:00
parent 1be3ad0ddc
commit 16cda0882c
7 changed files with 222 additions and 43 deletions

View File

@@ -9,15 +9,15 @@
#include "wintty.h"
#include <sys/stat.h>
#if defined(WIN32) || defined(MSDOS)
#if defined(MSDOS)
#include <errno.h>
#endif
#if defined(WIN32) || defined(MSDOS)
#if defined(MSDOS)
extern char orgdir[];
#endif
#if defined(WIN32) && defined(TTY_GRAPHICS)
#if defined(TTY_GRAPHICS)
extern void NDECL(backsp);
extern void NDECL(clear_screen);
#endif
@@ -49,7 +49,7 @@ int fd;
return(0);
}
#else
#if (defined(MICRO) || defined(WIN32)) && !defined(NO_FSTAT)
#if (defined(MICRO)) && !defined(NO_FSTAT)
if(fstat(fd, &buf)) {
if(moves > 1) pline("Cannot get status of saved level? ");
else pline("Cannot get status of saved game.");
@@ -126,28 +126,7 @@ getlock()
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
#if defined(WIN32) || defined(HOLD_LOCKFILE_OPEN)
#if defined(HOLD_LOCKFILE_OPEN)
if (errno == EACCES) {
#define OOPS_BUFSZ 512
char oops[OOPS_BUFSZ];
Strcpy(
oops,
"\nThere are files from a game in progress under your name.");
Strcat(oops, "\nThe files are locked or inaccessible.");
Strcat(oops, " Is the other game still running?\n");
if (strlen(fq_lock) < ((OOPS_BUFSZ - 16) - strlen(oops)))
Sprintf(eos(oops), "Cannot open %s", fq_lock);
Strcat(oops, "\n");
unlock_file(HLOCK);
error(oops);
} else
#endif
error("Bad directory or name: %s\n%s\n", fq_lock,
strerror(errno));
#else
perror(fq_lock);
#endif
unlock_file(HLOCK);
error("Cannot open %s", fq_lock);
}
@@ -197,10 +176,6 @@ getlock()
if (c == 'y' || c == 'Y')
#ifndef SELF_RECOVER
if (eraseoldlocks()) {
#if defined(WIN32) && defined(TTY_GRAPHICS)
if (WINDOWPORT("tty"))
clear_screen(); /* display gets fouled up otherwise */
#endif
goto gotlock;
} else {
unlock_file(HLOCK);
@@ -211,7 +186,7 @@ getlock()
}
#else /*SELF_RECOVER*/
if (recover_savefile()) {
#if defined(WIN32) && defined(TTY_GRAPHICS)
#if defined(TTY_GRAPHICS)
if (WINDOWPORT("tty"))
clear_screen(); /* display gets fouled up otherwise */
#endif
@@ -241,13 +216,7 @@ gotlock:
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
#if defined(WIN32)
error("cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock,
strerror(ern), " Are you sure that the directory",
fqn_prefix[LEVELPREFIX]);
#else
error("cannot creat file (%s.)", fq_lock);
#endif
} else {
if (write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)) {
@@ -270,7 +239,6 @@ gotlock:
}
#endif /* PC_LOCKING */
#ifndef WIN32
void
regularize(s)
/*
@@ -290,7 +258,6 @@ register char *s;
*lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']'))
*lp = '_';
}
#endif /* WIN32 */
#ifdef __EMX__
void

View File

@@ -9,6 +9,11 @@
#include "dlb.h"
#include <ctype.h>
#include <sys\stat.h>
#include <errno.h>
#if 0
#include "wintty.h"
#endif
#if !defined(SAFEPROCS)
#error You must #define SAFEPROCS to build windmain.c
@@ -26,8 +31,15 @@ E char chosen_windowtype[WINTYPELEN]; /* flag.h */
#if defined(MSWIN_GRAPHICS)
E void NDECL(mswin_destroy_reg);
#endif
#ifdef TTY_GRAPHICS
extern void NDECL(backsp);
extern void NDECL(clear_screen);
#endif
#undef E
#ifdef PC_LOCKING
static int NDECL(eraseoldlocks);
#endif
int NDECL(windows_nhgetch);
void NDECL(windows_nhbell);
int FDECL(windows_nh_poskey, (int *, int *, int *));
@@ -45,6 +57,14 @@ HANDLE hStdOut;
#if defined(MSWIN_GRAPHICS)
char default_window_sys[] = "mswin";
#endif
#ifdef WANT_GETHDATE
static struct stat hbuf;
#endif
#include <sys/stat.h>
#if defined(WIN32) || defined(MSDOS)
#endif
extern char orgdir[];
/*
* __MINGW32__ Note
@@ -724,4 +744,181 @@ char *outbuf;
Strcpy(outbuf, "\033");
}
/*pcmain.c*/
#ifdef PC_LOCKING
static int
eraseoldlocks()
{
register int i;
/* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
#endif
if (unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
void
getlock()
{
register int fd, c, ci, ct, ern;
int fcmask = FCMASK;
char tbuf[BUFSZ];
const char *fq_lock;
#define OOPS_BUFSZ 512
char oops[OOPS_BUFSZ];
/* we ignore QUIT and INT at this point */
if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
wait_synch();
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("Quitting.");
}
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
#if defined(HOLD_LOCKFILE_OPEN)
if (errno == EACCES) {
Strcpy(
oops,
"\nThere are files from a game in progress under your name.");
Strcat(oops, "\nThe files are locked or inaccessible.");
Strcat(oops, " Is the other game still running?\n");
if (strlen(fq_lock) < ((OOPS_BUFSZ - 16) - strlen(oops)))
Sprintf(eos(oops), "Cannot open %s", fq_lock);
Strcat(oops, "\n");
unlock_file(HLOCK);
raw_print(oops);
} else
#endif
error("Bad directory or name: %s\n%s\n", fq_lock,
strerror(errno));
unlock_file(HLOCK);
Sprintf(oops, "Cannot open %s", fq_lock);
raw_print(oops);
nethack_exit(EXIT_FAILURE);
}
(void) nhclose(fd);
if (iflags.window_inited || WINDOWPORT("curses")) {
#ifdef SELF_RECOVER
c = yn("There are files from a game in progress under your name. "
"Recover?");
#else
pline("There is already a game in progress under your name.");
pline("You may be able to use \"recover %s\" to get it back.\n",
tbuf);
c = yn("Do you want to destroy the old game?");
#endif
} else {
c = 'n';
ct = 0;
#ifdef SELF_RECOVER
raw_print("There are files from a game in progress under your name. "
"Recover? [yn]");
#else
raw_print("\nThere is already a game in progress under your name.\n");
raw_print("If this is unexpected, you may be able to use \n");
raw_print("\"recover %s\" to get it back.", tbuf);
raw_print("\nDo you want to destroy the old game? [yn] ");
#endif
while ((ci = nhgetch()) != '\n') {
if (ct > 0) {
raw_print("\b \b");
ct = 0;
c = 'n';
}
if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
ct = 1;
c = ci;
}
}
}
if (c == 'y' || c == 'Y')
#ifndef SELF_RECOVER
if (eraseoldlocks()) {
if (WINDOWPORT("tty"))
clear_screen(); /* display gets fouled up otherwise */
goto gotlock;
} else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
raw_print("Couldn't destroy old game.");
}
#else /*SELF_RECOVER*/
if (recover_savefile()) {
if (WINDOWPORT("tty"))
clear_screen(); /* display gets fouled up otherwise */
goto gotlock;
} else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
raw_print("Couldn't recover old game.");
}
#endif /*SELF_RECOVER*/
else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
Sprintf(oops, "%s", "Cannot start a new game.");
raw_print(oops);
}
gotlock:
fd = creat(fq_lock, fcmask);
if (fd == -1)
ern = errno;
unlock_file(HLOCK);
if (fd == -1) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
Sprintf(oops, "cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock,
strerror(ern), " Are you sure that the directory",
fqn_prefix[LEVELPREFIX]);
raw_print(oops);
} else {
if (write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("cannot write lock (%s)", fq_lock);
}
if (nhclose(fd) == -1) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("cannot close lock (%s)", fq_lock);
}
}
}
#endif /* PC_LOCKING */
/*windmain.c*/

View File

@@ -164,6 +164,7 @@ curses_character_input_dialog(const char *prompt, const char *choices,
CHAR_P def)
{
WINDOW *askwin = NULL;
WINDOW *message_window;
int answer, count, maxwidth, map_height, map_width;
char *linestr;
char askstr[BUFSZ + QBUFSZ];
@@ -180,6 +181,9 @@ curses_character_input_dialog(const char *prompt, const char *choices,
map_width = term_cols;
}
#ifdef PDCURSES
message_window = curses_get_nhwin(MESSAGE_WIN);
#endif
maxwidth = map_width - 2;
if (choices != NULL) {
@@ -241,8 +245,11 @@ curses_character_input_dialog(const char *prompt, const char *choices,
/*curses_stupid_hack = 0; */
while (1) {
#ifdef PDCURSES
answer = wgetch(message_window);
#else
answer = getch();
#endif
if (answer == ERR) {
answer = def;
break;

View File

@@ -619,7 +619,13 @@ raw_print(str) -- Print directly to a screen, or otherwise guarantee that
void
curses_raw_print(const char *str)
{
#ifdef PDCURSES
WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
curses_message_win_puts(str, FALSE);
#else
puts(str);
#endif
}
/*

View File

@@ -143,7 +143,7 @@ curses_block(boolean noscroll)
{
int height, width, ret = 0;
WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
char *resp = " \n\033"; /* space, enter, esc */
char *resp = " \r\n\033"; /* space, enter, esc */
curses_get_window_size(MESSAGE_WIN, &height, &width);
@@ -429,7 +429,11 @@ curses_message_win_getline(const char *prompt, char *answer, int buffer)
wmove(win, my, mx);
curs_set(1);
wrefresh(win);
#ifdef PDCURSES
ch = wgetch(win);
#else
ch = getch();
#endif
curs_set(0);
switch(ch) {
case '\033': /* DOESCAPE */

View File

@@ -152,7 +152,6 @@
<ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)pcsys.c" />
<ClCompile Include="$(SysShareDir)pcunix.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)nttty.c" />

View File

@@ -147,7 +147,6 @@
<ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)pcsys.c" />
<ClCompile Include="$(SysShareDir)pcunix.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)stubs.c">