Commit a3516e72 authored by deuce's avatar deuce
Browse files

Add suspendciolib() function. This function temporarily undoes anything

that initciolib() did to stdout so normal stdio stuff can be used.  To
resume ciolib mode, call initciolib() again, or use any ciolib function.

Currently, the state of the screen after a susped and after the resume is
undefined...
parent 7b13ff19
......@@ -105,7 +105,7 @@ CIOLIBEXPORT char * CIOLIBCALL ciolib_getpass(const char *prompt);
CIOLIBEXPORT void CIOLIBCALL ciolib_copytext(const char *text, size_t buflen);
CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void);
#define CIOLIB_INIT() { if(!initialized) initciolib(CIOLIB_MODE_AUTO); }
#define CIOLIB_INIT() { if(initialized != 1) initciolib(CIOLIB_MODE_AUTO); }
#ifdef WITH_SDL
int try_sdl_init(int mode)
......@@ -194,6 +194,8 @@ int try_curses_init(int mode)
cio_api.textmode=curs_textmode;
cio_api.showmouse=curs_showmouse;
cio_api.hidemouse=curs_hidemouse;
cio_api.suspend=curs_suspend;
cio_api.resume=curs_resume;
return(1);
}
return(0);
......@@ -254,16 +256,33 @@ int try_conio_init(int mode)
cio_api.settitle=win32_settitle;
cio_api.copytext=win32_copytext;
cio_api.getcliptext=win32_getcliptext;
cio_api.suspend=win32_suspend;
cio_api.resume=win32_resume;
return(1);
}
return(0);
}
#endif
CIOLIBEXPORT void CIOLIBCALL suspendciolib(void)
{
if(cio_api.suspend != NULL)
cio_api.suspend();
initialized=-1;
}
CIOLIBEXPORT int CIOLIBCALL initciolib(int mode)
{
if(initialized)
return(0);
switch(initialized) {
case 1:
return(0);
case -1:
if(cio_api.resume != NULL)
cio_api.resume();
initialized=1;
return(0);
}
memset(&cio_api,0,sizeof(cio_api));
switch(mode) {
......
......@@ -239,6 +239,8 @@ typedef struct {
void (*setname) (const char *);
void (*copytext) (const char *, size_t);
char *(*getcliptext) (void);
void (*suspend) (void);
void (*resume) (void);
} cioapi_t;
CIOLIBEXPORTVAR cioapi_t cio_api;
......@@ -252,6 +254,7 @@ CIOLIBEXPORTVAR int hold_update;
extern "C" {
#endif
CIOLIBEXPORT int CIOLIBCALL initciolib(int mode);
CIOLIBEXPORT void CIOLIBCALL suspendciolib(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy);
CIOLIBEXPORT char * CIOLIBCALL ciolib_cgets(char *str);
......
......@@ -660,6 +660,16 @@ void call_endwin(void)
endwin();
}
void curs_suspend(void)
{
refresh();
}
void curs_resume(void)
{
}
int curs_initciolib(long inmode)
{
short fg, bg, pair=0;
......
......@@ -68,6 +68,8 @@ int curs_getche(void);
void curs_textmode(int mode);
int curs_showmouse(void);
int curs_hidemouse(void);
void curs_suspend(void);
void curs_resume(void);
#ifdef __cplusplus
}
#endif
......
......@@ -381,6 +381,27 @@ int win32_getche(void)
#define ENABLE_AUTO_POSITION 0x0100
#endif
static DWORD orig_in_conmode=0;
static DWORD orig_out_conmode=0;
void win32_suspend(void)
{
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), orig_in_conmode);
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), orig_out_conmode);
}
void win32_resume(void)
{
conmode=orig_in_conmode;
conmode&=~(ENABLE_PROCESSED_INPUT|ENABLE_QUICK_EDIT_MODE);
conmode|=ENABLE_MOUSE_INPUT;
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), conmode);
conmode=orig_out_conmode;
conmode&=~ENABLE_PROCESSED_OUTPUT;
conmode&=~ENABLE_WRAP_AT_EOL_OUTPUT;
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), conmode);
}
int win32_initciolib(long inmode)
{
DWORD conmode;
......@@ -392,15 +413,17 @@ int win32_initciolib(long inmode)
return(0);
}
if(!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &conmode))
if(!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &orig_in_conmode))
return(0);
conmode=orig_in_conmode;
conmode&=~(ENABLE_PROCESSED_INPUT|ENABLE_QUICK_EDIT_MODE);
conmode|=ENABLE_MOUSE_INPUT;
if(!SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), conmode))
return(0);
if(!GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &conmode))
if(!GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &orig_out_conmode))
return(0);
conmode=orig_out_conmode;
conmode&=~ENABLE_PROCESSED_OUTPUT;
conmode&=~ENABLE_WRAP_AT_EOL_OUTPUT;
if(!SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), conmode))
......
......@@ -67,6 +67,8 @@ void win32_settitle(const char *title);
int win32_initciolib(long inmode);
void win32_copytext(const char *text, size_t buflen);
char *win32_getcliptext(void);
void win32_suspend(void);
void win32_resume(void);
#ifdef __cplusplus
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment