can insert ctrl+z into prompt
This commit is contained in:
parent
2ea9ebba2f
commit
87f1ca432e
|
@ -131,9 +131,6 @@ CommandLine& CommandLine::Instance()
|
|||
|
||||
bool CommandLine::IsEditLineEmpty() const
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
/*
|
||||
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
|
||||
|
||||
if (!gci.HasPendingCookedRead())
|
||||
|
@ -151,34 +148,26 @@ bool CommandLine::IsEditLineEmpty() const
|
|||
{
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void CommandLine::Hide(const bool fUpdateFields)
|
||||
{
|
||||
// TODO
|
||||
fUpdateFields;
|
||||
/*
|
||||
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
|
||||
if (!IsEditLineEmpty())
|
||||
{
|
||||
DeleteCommandLine(gci.CookedReadData(), fUpdateFields);
|
||||
}
|
||||
*/
|
||||
_isVisible = false;
|
||||
}
|
||||
|
||||
void CommandLine::Show()
|
||||
{
|
||||
_isVisible = true;
|
||||
return;
|
||||
/*
|
||||
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
|
||||
if (!IsEditLineEmpty())
|
||||
{
|
||||
RedrawCommandLine(gci.CookedReadData());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
@ -234,85 +223,19 @@ void CommandLine::EndAllPopups()
|
|||
|
||||
void DeleteCommandLine(CookedRead& cookedReadData, const bool fUpdateFields)
|
||||
{
|
||||
/*
|
||||
size_t CharsToWrite = cookedReadData.VisibleCharCount();
|
||||
COORD coordOriginalCursor = cookedReadData.OriginalCursorPosition();
|
||||
const COORD coordBufferSize = cookedReadData.ScreenInfo().GetBufferSize().Dimensions();
|
||||
|
||||
// catch the case where the current command has scrolled off the top of the screen.
|
||||
if (coordOriginalCursor.Y < 0)
|
||||
{
|
||||
CharsToWrite += coordBufferSize.X * coordOriginalCursor.Y;
|
||||
CharsToWrite += cookedReadData.OriginalCursorPosition().X; // account for prompt
|
||||
cookedReadData.OriginalCursorPosition().X = 0;
|
||||
cookedReadData.OriginalCursorPosition().Y = 0;
|
||||
coordOriginalCursor.X = 0;
|
||||
coordOriginalCursor.Y = 0;
|
||||
}
|
||||
|
||||
if (!CheckBisectStringW(cookedReadData.BufferStartPtr(),
|
||||
CharsToWrite,
|
||||
coordBufferSize.X - cookedReadData.OriginalCursorPosition().X))
|
||||
{
|
||||
CharsToWrite++;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cookedReadData.ScreenInfo().Write(OutputCellIterator(UNICODE_SPACE, CharsToWrite), coordOriginalCursor);
|
||||
}
|
||||
CATCH_LOG();
|
||||
|
||||
if (fUpdateFields)
|
||||
{
|
||||
cookedReadData.Erase();
|
||||
}
|
||||
|
||||
LOG_IF_FAILED(cookedReadData.ScreenInfo().SetCursorPosition(cookedReadData.OriginalCursorPosition(), true));
|
||||
*/
|
||||
cookedReadData;
|
||||
fUpdateFields;
|
||||
else
|
||||
{
|
||||
cookedReadData.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
void RedrawCommandLine(CookedRead& cookedReadData)
|
||||
{
|
||||
/*
|
||||
if (cookedReadData.IsEchoInput())
|
||||
{
|
||||
// Draw the command line
|
||||
cookedReadData.OriginalCursorPosition() = cookedReadData.ScreenInfo().GetTextBuffer().GetCursor().GetPosition();
|
||||
|
||||
SHORT ScrollY = 0;
|
||||
#pragma prefast(suppress:28931, "Status is not unused. It's used in debug assertions.")
|
||||
NTSTATUS Status = WriteCharsLegacy(cookedReadData.ScreenInfo(),
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.BufferStartPtr(),
|
||||
&cookedReadData.BytesRead(),
|
||||
&cookedReadData.VisibleCharCount(),
|
||||
cookedReadData.OriginalCursorPosition().X,
|
||||
WC_DESTRUCTIVE_BACKSPACE | WC_KEEP_CURSOR_VISIBLE | WC_ECHO,
|
||||
&ScrollY);
|
||||
FAIL_FAST_IF_NTSTATUS_FAILED(Status);
|
||||
|
||||
cookedReadData.OriginalCursorPosition().Y += ScrollY;
|
||||
|
||||
// Move the cursor back to the right position
|
||||
COORD CursorPosition = cookedReadData.OriginalCursorPosition();
|
||||
CursorPosition.X += (SHORT)RetrieveTotalNumberOfSpaces(cookedReadData.OriginalCursorPosition().X,
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.InsertionPoint());
|
||||
if (CheckBisectStringW(cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.InsertionPoint(),
|
||||
cookedReadData.ScreenInfo().GetBufferSize().Width() - cookedReadData.OriginalCursorPosition().X))
|
||||
{
|
||||
CursorPosition.X++;
|
||||
}
|
||||
Status = AdjustCursorPosition(cookedReadData.ScreenInfo(), CursorPosition, TRUE, nullptr);
|
||||
FAIL_FAST_IF_NTSTATUS_FAILED(Status);
|
||||
}
|
||||
*/
|
||||
cookedReadData;
|
||||
cookedReadData.Show();
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
@ -765,31 +688,7 @@ COORD CommandLine::_moveCursorRight(CookedRead& cookedReadData) noexcept
|
|||
// - cookedReadData - The cooked read data to operate on
|
||||
void CommandLine::_insertCtrlZ(CookedRead& cookedReadData) noexcept
|
||||
{
|
||||
cookedReadData;
|
||||
/*
|
||||
size_t NumSpaces = 0;
|
||||
|
||||
*cookedReadData.BufferCurrentPtr() = (WCHAR)0x1a; // ctrl-z
|
||||
cookedReadData.BytesRead() += sizeof(WCHAR);
|
||||
cookedReadData.InsertionPoint()++;
|
||||
if (cookedReadData.IsEchoInput())
|
||||
{
|
||||
short ScrollY = 0;
|
||||
size_t CharsToWrite = sizeof(WCHAR);
|
||||
FAIL_FAST_IF_NTSTATUS_FAILED(WriteCharsLegacy(cookedReadData.ScreenInfo(),
|
||||
cookedReadData.BufferStartPtr(),
|
||||
cookedReadData.BufferCurrentPtr(),
|
||||
cookedReadData.BufferCurrentPtr(),
|
||||
&CharsToWrite,
|
||||
&NumSpaces,
|
||||
cookedReadData.OriginalCursorPosition().X,
|
||||
WC_DESTRUCTIVE_BACKSPACE | WC_KEEP_CURSOR_VISIBLE | WC_ECHO,
|
||||
&ScrollY));
|
||||
cookedReadData.OriginalCursorPosition().Y += ScrollY;
|
||||
cookedReadData.VisibleCharCount() += NumSpaces;
|
||||
}
|
||||
cookedReadData.SetBufferCurrentPtr(cookedReadData.BufferCurrentPtr() + 1);
|
||||
*/
|
||||
cookedReadData.InsertCtrlZ();
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
|
|
@ -58,7 +58,10 @@ CommandHistory& CookedRead::History() noexcept
|
|||
|
||||
void CookedRead::Erase()
|
||||
{
|
||||
_clearPromptCells();
|
||||
_prompt.erase();
|
||||
_insertionIndex = 0;
|
||||
_writeToScreen(true);
|
||||
}
|
||||
|
||||
bool CookedRead::IsInsertMode() const noexcept
|
||||
|
@ -395,6 +398,25 @@ bool CookedRead::Notify(const WaitTerminationReason TerminationReason,
|
|||
}
|
||||
}
|
||||
|
||||
void CookedRead::Hide()
|
||||
{
|
||||
_clearPromptCells();
|
||||
}
|
||||
|
||||
void CookedRead::Show()
|
||||
{
|
||||
_writeToScreen(true);
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - inserts a ctrl+z character into the prompt at the insertion index
|
||||
void CookedRead::InsertCtrlZ()
|
||||
{
|
||||
std::deque<wchar_t> chars = { UNICODE_CTRL_Z };
|
||||
_writeToPrompt(chars);
|
||||
_writeToScreen(true);
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
// - Reads characters from user input
|
||||
// Arguments:
|
||||
|
@ -615,7 +637,6 @@ void CookedRead::_clearPromptCells()
|
|||
_status = WriteCharsLegacy(_screenInfo,
|
||||
spaces.c_str(),
|
||||
spaces.c_str(),
|
||||
|
||||
spaces.c_str(),
|
||||
&bytesToWrite,
|
||||
nullptr,
|
||||
|
@ -697,7 +718,6 @@ void CookedRead::_writeToScreen(const bool resetCursor)
|
|||
_status = WriteCharsLegacy(_screenInfo,
|
||||
_prompt.c_str(),
|
||||
_prompt.c_str(),
|
||||
|
||||
_prompt.c_str(),
|
||||
&bytesToWrite,
|
||||
nullptr,
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
ULONG& controlKeyState) noexcept;
|
||||
|
||||
void Erase();
|
||||
void Hide();
|
||||
void Show();
|
||||
|
||||
|
||||
bool IsInsertMode() const noexcept;
|
||||
|
@ -48,6 +50,8 @@ public:
|
|||
size_t MoveInsertionIndexLeftByWord();
|
||||
size_t MoveInsertionIndexRightByWord();
|
||||
|
||||
void InsertCtrlZ();
|
||||
|
||||
SCREEN_INFORMATION& ScreenInfo();
|
||||
|
||||
CommandHistory& History() noexcept;
|
||||
|
|
|
@ -52,6 +52,7 @@ const wchar_t UNICODE_BOX_DRAW_LIGHT_VERTICAL = 0x2502;
|
|||
const wchar_t UNICODE_BOX_DRAW_LIGHT_UP_AND_RIGHT = 0x2514;
|
||||
const wchar_t UNICODE_BOX_DRAW_LIGHT_UP_AND_LEFT = 0x2518;
|
||||
const wchar_t UNICODE_INVALID = 0xFFFF;
|
||||
const wchar_t UNICODE_CTRL_Z = 0x1a;
|
||||
|
||||
// This is the "Ctrl+C" character.
|
||||
// With VKey='C', it generates a CTRL_C_EVENT
|
||||
|
|
|
@ -73,7 +73,7 @@ std::string ConvertToA(const UINT codepage, const std::wstring_view source)
|
|||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
int iSource; // convert to int because Wc2Mb requires it.
|
||||
THROW_IF_FAILED(SizeTToInt(source.size(), &iSource));
|
||||
|
||||
|
@ -347,7 +347,12 @@ std::deque<std::unique_ptr<KeyEvent>> SynthesizeNumpadEvents(const wchar_t wch,
|
|||
CodepointWidth GetQuickCharWidth(const wchar_t wch) noexcept
|
||||
{
|
||||
// 0x00-0x1F is ambiguous by font
|
||||
if (0x20 <= wch && wch <= 0x7e)
|
||||
// ... but we render ctrl+z wide
|
||||
if (wch == 0x1a)
|
||||
{
|
||||
return CodepointWidth::Wide;
|
||||
}
|
||||
else if (0x20 <= wch && wch <= 0x7e)
|
||||
{
|
||||
/* ASCII */
|
||||
return CodepointWidth::Narrow;
|
||||
|
|
Loading…
Reference in a new issue