mirror of
https://github.com/reactos/reactos.git
synced 2025-05-31 23:18:39 +00:00
[CMD] Fix CTRL-C handling.
Using CTRL-C to cancel command line input would leave the prompt in a state where the next command would be ignored. For example: dir<CTRL-C> dir would cause cmd.exe to ignore the second dir command.
This commit is contained in:
parent
23de2099e0
commit
d7e71357dc
3 changed files with 24 additions and 6 deletions
|
@ -151,7 +151,7 @@ typedef NTSTATUS (WINAPI *NtReadVirtualMemoryProc)(HANDLE, PVOID, PVOID, ULONG,
|
||||||
|
|
||||||
BOOL bExit = FALSE; /* indicates EXIT was typed */
|
BOOL bExit = FALSE; /* indicates EXIT was typed */
|
||||||
BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
|
BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
|
||||||
BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
|
volatile BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
|
||||||
BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
|
BOOL bIgnoreEcho = FALSE; /* Set this to TRUE to prevent a newline, when executing a command */
|
||||||
static BOOL bWaitForCommand = FALSE; /* When we are executing something passed on the commandline after /c or /k */
|
static BOOL bWaitForCommand = FALSE; /* When we are executing something passed on the commandline after /c or /k */
|
||||||
INT nErrorLevel = 0; /* Errorlevel of last launched external program */
|
INT nErrorLevel = 0; /* Errorlevel of last launched external program */
|
||||||
|
@ -1423,6 +1423,12 @@ ReadLine(TCHAR *commandline, BOOL bMore)
|
||||||
ConOutChar(_T('\n'));
|
ConOutChar(_T('\n'));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (readline[0] == L'\0')
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
ip = readline;
|
ip = readline;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1476,6 +1482,8 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
|
||||||
LeaveCriticalSection(&ChildProcessRunningLock);
|
LeaveCriticalSection(&ChildProcessRunningLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bCtrlBreak = TRUE;
|
||||||
|
|
||||||
rec.EventType = KEY_EVENT;
|
rec.EventType = KEY_EVENT;
|
||||||
rec.Event.KeyEvent.bKeyDown = TRUE;
|
rec.Event.KeyEvent.bKeyDown = TRUE;
|
||||||
rec.Event.KeyEvent.wRepeatCount = 1;
|
rec.Event.KeyEvent.wRepeatCount = 1;
|
||||||
|
@ -1490,7 +1498,6 @@ BOOL WINAPI BreakHandler(DWORD dwCtrlType)
|
||||||
1,
|
1,
|
||||||
&dwWritten);
|
&dwWritten);
|
||||||
|
|
||||||
bCtrlBreak = TRUE;
|
|
||||||
/* FIXME: Handle batch files */
|
/* FIXME: Handle batch files */
|
||||||
|
|
||||||
//ConOutPrintf(_T("^C"));
|
//ConOutPrintf(_T("^C"));
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
extern LPTSTR lpOriginalEnvironment;
|
extern LPTSTR lpOriginalEnvironment;
|
||||||
extern WORD wColor;
|
extern WORD wColor;
|
||||||
extern WORD wDefColor;
|
extern WORD wDefColor;
|
||||||
extern BOOL bCtrlBreak;
|
extern volatile BOOL bCtrlBreak;
|
||||||
extern BOOL bIgnoreEcho;
|
extern BOOL bIgnoreEcho;
|
||||||
extern BOOL bExit;
|
extern BOOL bExit;
|
||||||
extern BOOL bDisableBatchEcho;
|
extern BOOL bDisableBatchEcho;
|
||||||
|
|
|
@ -450,12 +450,23 @@ BOOL ReadCommand(LPTSTR str, INT maxlen)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('C'):
|
case _T('C'):
|
||||||
bCharInput = TRUE;
|
if ((ir.Event.KeyEvent.dwControlKeyState &
|
||||||
if (!(ir.Event.KeyEvent.dwControlKeyState &
|
|
||||||
(RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)))
|
(RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)))
|
||||||
{
|
{
|
||||||
break;
|
/* A CTRL-C. Don't clear the the command line,
|
||||||
|
* but return an empty string in str. */
|
||||||
|
str[0] = L'\0';
|
||||||
|
curx = orgx;
|
||||||
|
cury = orgy;
|
||||||
|
current = charcount = 0;
|
||||||
|
bReturn = TRUE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Just a normal 'C' character */
|
||||||
|
bCharInput = TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case VK_RETURN:
|
case VK_RETURN:
|
||||||
/* end input, return to main */
|
/* end input, return to main */
|
||||||
|
|
Loading…
Reference in a new issue