/* ================== CON_Input ================== */ char *CON_Input( void ) { // we use this when sending back commands static char text[MAX_EDIT_LINE]; int avail; char key; field_t *history; size_t UNUSED_VAR size; if(ttycon_on) { avail = read(STDIN_FILENO, &key, 1); if (avail != -1) { // we have something // backspace? // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere if ((key == TTY_erase) || (key == 127) || (key == 8)) { if (TTY_con.cursor > 0) { TTY_con.cursor--; TTY_con.buffer[TTY_con.cursor] = '\0'; CON_Back(); } return NULL; } // check if this is a control char if ((key) && (key) < ' ') { if (key == '\n') { #ifndef DEDICATED if (TTY_con.buffer[0] == '/' || TTY_con.buffer[0] == '\\') { Q_strncpyz(text, TTY_con.buffer + 1, sizeof(text)); } else if (TTY_con.cursor) { Q_strncpyz(text, TTY_con.buffer, sizeof(text)); } else { text[0] = '\0'; } // push it in history Hist_Add(&TTY_con); CON_Hist_Save(); CON_Hide(); Com_Printf("%s%s\n", TTY_CONSOLE_PROMPT, TTY_con.buffer); Field_Clear(&TTY_con); CON_Show(); #else // push it in history Hist_Add(&TTY_con); CON_Hist_Save(); Q_strncpyz(text, TTY_con.buffer, sizeof(text)); Field_Clear(&TTY_con); key = '\n'; size = write(STDOUT_FILENO, &key, 1); size = write(STDOUT_FILENO, TTY_CONSOLE_PROMPT, strlen(TTY_CONSOLE_PROMPT)); #endif return text; } if (key == '\t') { CON_Hide(); Field_AutoComplete( &TTY_con ); CON_Show(); return NULL; } avail = read(STDIN_FILENO, &key, 1); if (avail != -1) { // VT 100 keys if (key == '[' || key == 'O') { avail = read(STDIN_FILENO, &key, 1); if (avail != -1) { switch (key) { case 'A': history = Hist_Prev(); if (history) { CON_Hide(); TTY_con = *history; CON_Show(); } CON_FlushIn(); return NULL; break; case 'B': history = Hist_Next(); CON_Hide(); if (history) { TTY_con = *history; } else { Field_Clear(&TTY_con); } CON_Show(); CON_FlushIn(); return NULL; break; case 'C': return NULL; case 'D': return NULL; } } } } Com_DPrintf("droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase); CON_FlushIn(); return NULL; } if (TTY_con.cursor >= (int)sizeof(text) - 1) return NULL; // push regular character TTY_con.buffer[TTY_con.cursor] = key; TTY_con.cursor++; // next char will always be '\0' // print the current line (this is differential) size = write(STDOUT_FILENO, &key, 1); } return NULL; } else if (stdin_active) { int len; fd_set fdset; struct timeval timeout; FD_ZERO(&fdset); FD_SET(STDIN_FILENO, &fdset); // stdin timeout.tv_sec = 0; timeout.tv_usec = 0; if(select (STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(STDIN_FILENO, &fdset)) return NULL; len = read(STDIN_FILENO, text, sizeof(text)); if (len == 0) { // eof! stdin_active = qfalse; return NULL; } if (len < 1) return NULL; text[len-1] = 0; // rip off the /n and terminate return text; } return NULL; }
/* ================== CON_Input ================== */ char *CON_Input( void ) { // we use this when sending back commands static char text[ MAX_EDIT_LINE ]; int avail; char key; const char *history; // size_t size; if ( ttycon_on ) { avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { // we have something // backspace? // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere if ( ( key == TTY_erase ) || ( key == 127 ) || ( key == 8 ) ) { if ( TTY_con.cursor > 0 ) { TTY_con.cursor--; TTY_con.buffer[ TTY_con.cursor ] = '\0'; CON_Back(); } return NULL; } // check if this is a control char if ( ( key ) && ( key ) < ' ' ) { if ( key == '\n' ) { // push it in history Q_snprintf( text, sizeof(text), "\\%s", TTY_con.buffer + ( TTY_con.buffer[ 0 ] == '\\' || TTY_con.buffer[ 0 ] == '/' ) ); Hist_Add( text ); Field_Clear( &TTY_con ); key = '\n'; write( STDOUT_FILENO, &key, 1 ); write( STDOUT_FILENO, "]", 1 ); return text + 1; } if ( key == '\t' ) { CON_Hide(); field_t *edit = &TTY_con; Cmd_TokenizeString( edit->buffer ); Field_AutoComplete( edit, "]" ); CON_Show(); return NULL; } avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { // VT 100 keys if ( key == '[' || key == 'O' ) { avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { switch ( key ) { case 'A': CON_Hide(); Q_strncpyz( TTY_con.buffer, Hist_Prev(), sizeof( TTY_con.buffer ) ); TTY_con.cursor = strlen( TTY_con.buffer ); CON_Show(); CON_FlushIn(); return NULL; case 'B': history = Hist_Next(); CON_Hide(); if ( history ) { Q_strncpyz( TTY_con.buffer, history, sizeof( TTY_con.buffer ) ); TTY_con.cursor = strlen( TTY_con.buffer ); } else if ( TTY_con.buffer[ 0 ] ) { Hist_Add( TTY_con.buffer ); Field_Clear( &TTY_con ); } CON_Show(); CON_FlushIn(); return NULL; case 'C': return NULL; case 'D': return NULL; } } } } Com_DPrintf( "droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase ); CON_FlushIn(); return NULL; } if ( TTY_con.cursor >= sizeof( text ) - 1 ) { return NULL; } // push regular character TTY_con.buffer[ TTY_con.cursor ] = key; TTY_con.cursor++; // print the current line (this is differential) write( STDOUT_FILENO, &key, 1 ); } return NULL; } else if ( stdin_active ) { int len; fd_set fdset; struct timeval timeout; FD_ZERO( &fdset ); FD_SET( STDIN_FILENO, &fdset ); // stdin timeout.tv_sec = 0; timeout.tv_usec = 0; if ( select( STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout ) == -1 || !FD_ISSET( STDIN_FILENO, &fdset ) ) { return NULL; } len = read( STDIN_FILENO, text, sizeof( text ) ); if ( len == 0 ) { // eof! stdin_active = qfalse; return NULL; } if ( len < 1 ) { return NULL; } text[ len - 1 ] = 0; // rip off the /n and terminate return text; } return NULL; }
/* ================== CON_Input ================== */ char *CON_Input( void ) { // we use this when sending back commands static char text[256]; int avail; char key; field_t *history; if( ttycon_on ) { avail = read(0, &key, 1); if (avail == -1) { avail = read(urtpipe_fd, &key, 1); } else if (avail != -1) { // we have something // backspace? // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere if ((key == TTY_erase) || (key == 127) || (key == 8)) { if (TTY_con.cursor > 0) { TTY_con.cursor--; TTY_con.buffer[TTY_con.cursor] = '\0'; CON_Back(); } return NULL; } // check if this is a control char if ((key) && (key) < ' ') { if (key == '\n') { // push it in history Hist_Add(&TTY_con); strcpy(text, TTY_con.buffer); Field_Clear(&TTY_con); key = '\n'; write(1, &key, 1); write( 1, "]", 1 ); return text; } if (key == '\t') { CON_Hide(); Field_AutoComplete( &TTY_con ); CON_Show(); return NULL; } avail = read(0, &key, 1); if (avail != -1) { // VT 100 keys if (key == '[' || key == 'O') { avail = read(0, &key, 1); if (avail != -1) { switch (key) { case 'A': history = Hist_Prev(); if (history) { CON_Hide(); TTY_con = *history; CON_Show(); } CON_FlushIn(); return NULL; break; case 'B': history = Hist_Next(); CON_Hide(); if (history) { TTY_con = *history; } else { Field_Clear(&TTY_con); } CON_Show(); CON_FlushIn(); return NULL; break; case 'C': return NULL; case 'D': return NULL; } } } } Com_DPrintf("droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase); CON_FlushIn(); return NULL; } // push regular character TTY_con.buffer[TTY_con.cursor] = key; TTY_con.cursor++; // print the current line (this is differential) write(1, &key, 1); } return NULL; } else { Com_Printf("fd sets...\n"); int len; fd_set fdset; struct timeval timeout; static qboolean stdin_active; if (!com_dedicated || !com_dedicated->value) return NULL; if (!stdin_active) return NULL; FD_ZERO(&fdset); FD_SET(0, &fdset); // stdin FD_SET(urtpipe_fd, &fdset); // urtpipe timeout.tv_sec = 0; timeout.tv_usec = 0; if (select (urtpipe_fd + 1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset) || !FD_ISSET(urtpipe_fd, &fdset)) { return NULL; } if (FD_ISSET(0, &fdset)) { Com_Printf("0 is set\n"); len = read (0, text, sizeof(text)); } else { Com_Printf("pipe is set\n"); len = read (urtpipe_fd, text, sizeof(text)); } if (len == 0) { // eof! stdin_active = qfalse; return NULL; } if (len < 1) return NULL; text[len-1] = 0; // rip off the /n and terminate return text; } }
/* ================== CON_Input_TTY ================== */ char *CON_Input_TTY() { // we use this when sending back commands static char text[ MAX_EDIT_LINE ]; int avail; char key; if ( ttycon_on ) { avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { // we have something // backspace? // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere if ( ( key == TTY_erase ) || ( key == 127 ) || ( key == 8 ) ) { CON_Hide(); TTY_field.DeletePrev(); CON_Show(); CON_FlushIn(); return nullptr; } // check if this is a control char if ( ( key ) && ( key ) < ' ' ) { if ( key == '\n' ) { TTY_field.RunCommand(com_consoleCommand.Get()); WriteToStdout("\n]"); return nullptr; } if ( key == '\t' ) { CON_Hide(); TTY_field.AutoComplete(); CON_Show(); return nullptr; } if ( key == '\x15' ) // ^U { CON_Hide(); TTY_field.Clear(); CON_Show(); return nullptr; } avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { // VT 100 keys if ( key == '[' || key == 'O' ) { avail = read( STDIN_FILENO, &key, 1 ); if ( avail != -1 ) { switch ( key ) { case 'A': CON_Hide(); TTY_field.HistoryPrev(); CON_Show(); CON_FlushIn(); return nullptr; case 'B': CON_Hide(); TTY_field.HistoryNext(); CON_Show(); CON_FlushIn(); return nullptr; case 'C': return nullptr; case 'D': return nullptr; } } } } CON_FlushIn(); return nullptr; } CON_Hide(); TTY_field.AddChar(key); CON_Show(); } return nullptr; } else if ( stdin_active ) { int len; fd_set fdset; struct timeval timeout; FD_ZERO( &fdset ); FD_SET( STDIN_FILENO, &fdset ); // stdin timeout.tv_sec = 0; timeout.tv_usec = 0; if ( select( STDIN_FILENO + 1, &fdset, nullptr, nullptr, &timeout ) == -1 || !FD_ISSET( STDIN_FILENO, &fdset ) ) { return nullptr; } len = read( STDIN_FILENO, text, sizeof( text ) ); if ( len == 0 ) { // eof! stdin_active = false; return nullptr; } if ( len < 1 ) { return nullptr; } text[ len - 1 ] = 0; // rip off the /n and terminate return text; } return nullptr; }