Skip to content

Commit

Permalink
enable redirection of stdin to cp/m apps
Browse files Browse the repository at this point in the history
  • Loading branch information
davidly committed Jul 26, 2024
1 parent d73d70f commit c28cef9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions djl_con.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class ConsoleConfiguration
printf( "\x1b[?25l" );
else
printf( "\x1b[?25h" );
fflush( stdout );
}
#endif
} //SetCursorInfo
Expand Down Expand Up @@ -578,28 +579,35 @@ class ConsoleConfiguration

int portable_kbhit()
{
int result = 0;
if ( !isatty( fileno( stdin ) ) )
return ( 0 == feof( stdin) );

#ifdef _WIN32
if ( 0 != aReady[ 0 ] )
return true;
result = _kbhit();
return _kbhit();
#else
fd_set set;
FD_ZERO( &set );
FD_SET( STDIN_FILENO, &set );
struct timeval timeout = {0};
result = ( select( 1, &set, NULL, NULL, &timeout ) > 0 );
return ( select( 1, &set, NULL, NULL, &timeout ) > 0 );
#endif

return result;
} //portable_kbhit

#ifdef _WIN32
// behave like getch() on linux -- extended characters have escape sequences

int linux_getch()
{
if ( !isatty( fileno( stdin ) ) )
{
char data;
if ( 1 == read( 0, &data, 1 ) )
return data;
return EOF;
}

size_t cReady = strlen( aReady );
if ( 0 != cReady )
{
Expand Down Expand Up @@ -646,6 +654,18 @@ class ConsoleConfiguration

static int portable_getch()
{
if ( !isatty( fileno( stdin ) ) )
{
char data;
if ( 1 == read( 0, &data, 1 ) )
{
if ( 0x0a == data )
data = 0x0d;
return data;
}
return EOF;
}

#ifdef _WIN32
return _getch();
#else
Expand Down

0 comments on commit c28cef9

Please sign in to comment.