From: nethack.allison Date: Sun, 27 Jul 2003 03:22:15 +0000 (+0000) Subject: fix display problem with tabs on win32tty X-Git-Tag: MOVE2GIT~1886 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b750eee32a66126810a0269ec3cfa3ed66a60a2f;p=nethack fix display problem with tabs on win32tty --- diff --git a/include/extern.h b/include/extern.h index 1572986d3..976bb1b8c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1324,6 +1324,7 @@ E void NDECL(nttty_open); E void NDECL(nttty_rubout); E int NDECL(tgetch); E int FDECL(ntposkey,(int *, int *, int *)); +E void FDECL(set_output_mode, (int)); #endif /* ### o_init.c ### */ diff --git a/include/flag.h b/include/flag.h index f494b44d2..8b5c6e05d 100644 --- a/include/flag.h +++ b/include/flag.h @@ -193,6 +193,8 @@ struct instance_flags { #endif #ifdef MICRO boolean BIOS; /* use IBM or ST BIOS calls when appropriate */ +#endif +#if defined(MICRO) || defined(WIN32) boolean rawio; /* whether can use rawio (IOCTL call) */ #endif #ifdef MAC_GRAPHICS_ENV diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index 8ccec94b6..a5aea36b7 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -291,8 +291,19 @@ char *argv[]; # endif #endif - if (!*plname) + if (!*plname) { +#ifdef WIN32CON + boolean revert = FALSE; + if (!iflags.rawio) { + set_output_mode(1); + revert = TRUE; + } +#endif askname(); +#ifdef WIN32CON + if (revert && iflags.rawio) set_output_mode(0); +#endif + } plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ /* accepts any suffix */ diff --git a/sys/share/pcsys.c b/sys/share/pcsys.c index 9c3f76284..2100d086a 100644 --- a/sys/share/pcsys.c +++ b/sys/share/pcsys.c @@ -416,6 +416,9 @@ msmsg VA_DECL(const char *, fmt) if (iflags.grmode) gr_finish(); # endif +#ifdef WIN32CON + if (iflags.rawio) set_output_mode(0); +#endif Vprintf(fmt, VA_ARGS); flushout(); VA_END(); diff --git a/sys/share/pctty.c b/sys/share/pctty.c index 5dd3d0023..0307082d1 100644 --- a/sys/share/pctty.c +++ b/sys/share/pctty.c @@ -75,6 +75,9 @@ error VA_DECL(const char *,s) VA_INIT(s, const char *); /* error() may get called before tty is initialized */ if (iflags.window_inited) end_screen(); +#ifdef WIN32CON + if (iflags.rawio) set_output_mode(0); +#endif putchar('\n'); Vprintf(s,VA_ARGS); putchar('\n'); diff --git a/sys/share/pcunix.c b/sys/share/pcunix.c index fe73d6a3d..79ff656f7 100644 --- a/sys/share/pcunix.c +++ b/sys/share/pcunix.c @@ -263,6 +263,9 @@ gotlock: # if defined(MSDOS) && defined(NO_TERMS) if (grmode) gr_init(); # endif +#ifdef WIN32CON + if (!iflags.rawio) set_output_mode(1); +#endif } #endif /* PC_LOCKING */ diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 70374b378..292617881 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -153,6 +153,38 @@ const char *s; if(s) raw_print(s); } +/* + * mode == 0 set processed console output mode. + * mode == 1 set raw console output mode (no control character expansion). + */ +void +set_output_mode(mode) +int mode; +{ + static DWORD save_output_cmode = 0; + static boolean initmode = FALSE; + DWORD cmode, mask = ENABLE_PROCESSED_OUTPUT; + if (!initmode) { + /* fetch original output mode */ + GetConsoleMode(hConOut,&save_output_cmode); + initmode = TRUE; + } + if (mode == 0) { + cmode = save_output_cmode; + /* Turn ON the settings specified in the mask */ + cmode |= mask; + SetConsoleMode(hConOut,cmode); + iflags.rawio = 0; + } else { + cmode = save_output_cmode; + /* Turn OFF the settings specified in the mask */ + cmode &= ~mask; + SetConsoleMode(hConOut,cmode); + iflags.rawio = 1; + } +} + + /* called by init_nhwindows() and resume_nhwindows() */ void setftty() @@ -219,6 +251,7 @@ DWORD ctrltype; case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: + set_output_mode(0); /* Allow processed output */ getreturn_disable = TRUE; #ifndef NOSAVEONHANGUP hangup(0); @@ -285,6 +318,8 @@ nttty_open() cmode |= ENABLE_MOUSE_INPUT; #endif SetConsoleMode(hConIn,cmode); + + set_output_mode(1); /* raw output mode; no tab expansion */ if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE)) { /* Unable to set control handler */ cmode = 0; /* just to have a statement to break on for debugger */ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 15b124976..1be353751 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -707,7 +707,7 @@ tty_askname() if(c < 'A' || (c > 'Z' && c < 'a') || c > 'z') c = '_'; #endif if (ct < (int)(sizeof plname) - 1) { -#if defined(MICRO) || defined(WIN32CON) +#if defined(MICRO) # if defined(MSDOS) if (iflags.grmode) { (void) putchar(c);