diff options
author | Xycaleth <alex@acslo.com> | 2015-01-17 22:11:35 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2015-03-17 11:43:04 +0000 |
commit | f5382657cf96e2fe71e33b531ec197856825b51d (patch) | |
tree | 25511fc8f1c78507de960ba06c103f597fcf8eda /src | |
parent | d9580d71cd7e5edcd57eed506454c67db35db211 (diff) |
Add arrow key support for win32 console
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/con_win32.c | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/src/sys/con_win32.c b/src/sys/con_win32.c index 1ef0c9a7..758fed79 100644 --- a/src/sys/con_win32.c +++ b/src/sys/con_win32.c @@ -45,6 +45,7 @@ static int qconsole_history_oldest = 0; static char qconsole_line[ MAX_EDIT_LINE ]; static int qconsole_linelen = 0; static qboolean qconsole_drawinput = qtrue; +static int qconsole_cursor; static HANDLE qconsole_hout; static HANDLE qconsole_hin; @@ -140,6 +141,7 @@ static void CON_HistPrev( void ) Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ], sizeof( qconsole_line ) ); qconsole_linelen = strlen( qconsole_line ); + qconsole_cursor = qconsole_linelen; } /* @@ -164,6 +166,7 @@ static void CON_HistNext( void ) qconsole_history_pos = pos; qconsole_line[ 0 ] = '\0'; qconsole_linelen = 0; + qconsole_cursor = qconsole_linelen; return; } @@ -171,6 +174,7 @@ static void CON_HistNext( void ) Q_strncpyz( qconsole_line, qconsole_history[ qconsole_history_pos ], sizeof( qconsole_line ) ); qconsole_linelen = strlen( qconsole_line ); + qconsole_cursor = qconsole_linelen; } @@ -234,7 +238,11 @@ static void CON_Show( void ) // set curor position cursorPos.Y = binfo.dwCursorPosition.Y; - cursorPos.X = qconsole_linelen > binfo.srWindow.Right ? binfo.srWindow.Right : qconsole_linelen; + cursorPos.X = qconsole_cursor < qconsole_linelen + ? qconsole_cursor + : qconsole_linelen > binfo.srWindow.Right + ? binfo.srWindow.Right + : qconsole_linelen; SetConsoleCursorPosition( qconsole_hout, cursorPos ); } @@ -359,6 +367,7 @@ char *CON_Input( void ) if( key == VK_RETURN ) { newlinepos = i; + qconsole_cursor = 0; break; } else if( key == VK_UP ) @@ -371,6 +380,34 @@ char *CON_Input( void ) CON_HistNext(); break; } + else if( key == VK_LEFT ) + { + qconsole_cursor--; + if ( qconsole_cursor < 0 ) + { + qconsole_cursor = 0; + } + break; + } + else if( key == VK_RIGHT ) + { + qconsole_cursor++; + if ( qconsole_cursor > qconsole_linelen ) + { + qconsole_cursor = qconsole_linelen; + } + break; + } + else if( key == VK_HOME ) + { + qconsole_cursor = 0; + break; + } + else if( key == VK_END ) + { + qconsole_cursor = qconsole_linelen; + break; + } else if( key == VK_TAB ) { field_t f; @@ -381,6 +418,7 @@ char *CON_Input( void ) Q_strncpyz( qconsole_line, f.buffer, sizeof( qconsole_line ) ); qconsole_linelen = strlen( qconsole_line ); + qconsole_cursor = qconsole_linelen; break; } @@ -390,15 +428,33 @@ char *CON_Input( void ) if( key == VK_BACK ) { - int pos = ( qconsole_linelen > 0 ) ? - qconsole_linelen - 1 : 0; - - qconsole_line[ pos ] = '\0'; - qconsole_linelen = pos; + if ( qconsole_cursor > 0 ) + { + int newlen = ( qconsole_linelen > 0 ) ? qconsole_linelen - 1 : 0; + if ( qconsole_cursor < qconsole_linelen ) + { + memmove( qconsole_line + qconsole_cursor - 1, + qconsole_line + qconsole_cursor, + qconsole_linelen - qconsole_cursor ); + } + + qconsole_line[ newlen ] = '\0'; + qconsole_linelen = newlen; + qconsole_cursor--; + } } else if( c ) { - qconsole_line[ qconsole_linelen++ ] = c; + if ( qconsole_linelen > qconsole_cursor ) + { + memmove( qconsole_line + qconsole_cursor + 1, + qconsole_line + qconsole_cursor, + qconsole_linelen - qconsole_cursor ); + } + + qconsole_line[ qconsole_cursor++ ] = c; + + qconsole_linelen++; qconsole_line[ qconsole_linelen ] = '\0'; } } |