Skip to content

Commit

Permalink
supersedes #276, #278 where the discussion is (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Oct 4, 2023
1 parent be99bac commit 9c16db9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
6 changes: 4 additions & 2 deletions pdcurses/initscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
if (!SP)
return NULL;

/* output_fd, input_fd should be initialized before PDC_src_open */
SP->output_fd = outfd ? outfd : stdout;
SP->input_fd = infd ? infd : stdin;

if (PDC_scr_open() == ERR)
{
fprintf(stderr, "initscr(): Unable to create SP\n");
Expand Down Expand Up @@ -286,8 +290,6 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
return NULL;
SP->c_ungind = 0;
SP->c_ungmax = NUNGETCH;
SP->output_fd = outfd;
SP->input_fd = infd;

return SP;
}
Expand Down
19 changes: 4 additions & 15 deletions vt/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,13 @@ static bool check_key( int *c)
{
bool rval;
#ifndef USE_CONIO
const int STDIN = 0;
struct timeval timeout;
fd_set rdset;
extern int PDC_n_ctrl_c;

if( PDC_resize_occurred)
return( TRUE);
if( SP->input_fd && SP->input_fd != stdin)
{
rval = !feof( SP->input_fd);
if( rval && c)
{
*c = fgetc( SP->input_fd);
if( *c == EOF)
rval = FALSE;
}
return( rval);
}

#ifdef LINUX_FRAMEBUFFER_PORT
PDC_check_for_blinking( );
#endif
Expand All @@ -69,14 +58,14 @@ static bool check_key( int *c)
return( TRUE);
}
FD_ZERO( &rdset);
FD_SET( STDIN, &rdset);
FD_SET( fileno( SP->input_fd), &rdset);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if( select( STDIN + 1, &rdset, NULL, NULL, &timeout) > 0)
if( select( fileno( SP->input_fd) + 1, &rdset, NULL, NULL, &timeout) > 0)
{
rval = TRUE;
if( c)
*c = getchar( );
*c = fgetc( SP->input_fd);
}
else
rval = FALSE;
Expand Down
9 changes: 4 additions & 5 deletions vt/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static int set_win10_for_vt_codes( const bool setting_mode)
#endif

bool PDC_resize_occurred = FALSE;
const int STDIN = 0;
static mmask_t _stored_trap_mbe;

/* COLOR_PAIR to attribute encoding table. */
Expand All @@ -125,14 +124,14 @@ void PDC_reset_prog_mode( void)
#ifdef USE_TERMIOS
struct termios term;

tcgetattr( STDIN, &orig_term);
tcgetattr( fileno( SP->input_fd), &orig_term);
memcpy( &term, &orig_term, sizeof( term));
term.c_lflag &= ~(ICANON | ECHO);
term.c_iflag &= ~ICRNL;
term.c_cc[VSUSP] = _POSIX_VDISABLE; /* disable Ctrl-Z */
term.c_cc[VSTOP] = _POSIX_VDISABLE; /* disable Ctrl-S */
term.c_cc[VSTART] = _POSIX_VDISABLE; /* disable Ctrl-Q */
tcsetattr( STDIN, TCSANOW, &term);
tcsetattr( fileno( SP->input_fd), TCSANOW, &term);
#endif
#ifndef _WIN32
if( !PDC_is_ansi)
Expand Down Expand Up @@ -204,7 +203,7 @@ void PDC_scr_close( void)
set_win10_for_vt_codes( FALSE);
#else
#if !defined( DOS)
tcsetattr( STDIN, TCSANOW, &orig_term);
tcsetattr( fileno( SP->input_fd), TCSANOW, &orig_term);
#endif
#endif
PDC_doupdate( );
Expand Down Expand Up @@ -302,7 +301,7 @@ int PDC_scr_open(void)
if (!SP || PDC_init_palette( ))
return ERR;

setbuf( stdin, NULL);
setbuf( SP->input_fd, NULL);
#ifdef USE_TERMIOS
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
Expand Down

0 comments on commit 9c16db9

Please sign in to comment.