Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting ANSI compatibility #553

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions minichlink/minichlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,32 @@ int main( int argc, char ** argv )
#if TERMINAL_INPUT_BUFFER
char pline_buf[256]; // Buffer that contains current line that is being printed to
char input_buf[128]; // Buffer that contains user input until it is sent out
memset( pline_buf, 0, sizeof( pline_buf ) );
memset( input_buf, 0, sizeof( input_buf ) );
memset( pline_buf, 0, sizeof(pline_buf) );
memset( input_buf, 0, sizeof(input_buf) );
uint8_t input_pos = 0;
uint8_t to_send = 0;
uint8_t nice_terminal = isatty(1);
uint8_t nice_terminal = isatty( fileno(stdout) );
#if defined(WINDOWS) || defined(WIN32) || defined(_WIN32)
unsigned long console_mode;
void* handle_output = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(handle_output, &console_mode);
console_mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
uint8_t set_result = SetConsoleMode(handle_output, console_mode);
if ( set_result == 0 ) nice_terminal = 0;
#else
if( nice_terminal > 0 )
{
fflush( stdin );
fprintf( stdout, "\x1b[6n" );
fflush( stdout );
read( fileno(stdin), input_buf, 10 );
if (input_buf[0] != 27)
{
nice_terminal = 0;
}
memset( input_buf, 0, sizeof(input_buf) );
}
#endif
#endif
printf( "Terminal started\n\n" );
uint32_t appendword = 0;
Expand Down Expand Up @@ -2675,7 +2696,4 @@ void TestFunction(void * dev )
printf( "%02x ", buffer[i] );
if( (i & 0xf) == 0xf ) printf( "\n" );
}
}



}
2 changes: 1 addition & 1 deletion minichlink/minichlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct InternalState
#endif

#ifndef TERMINAL_INPUT_BUFFER
#define TERMINAL_INPUT_BUFFER 0
#define TERMINAL_INPUT_BUFFER 1
#endif

#define TERMINAL_BUFFER_SIZE 512
Expand Down
Loading