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

Debug console improvements #26

Merged
merged 2 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
167 changes: 153 additions & 14 deletions Transcendence/CCommandLineDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,47 @@ int CCommandLineDisplay::GetOutputCount (void)
return ((m_iOutputEnd + MAX_LINES + 1 - m_iOutputStart) % (MAX_LINES + 1));
}

void CCommandLineDisplay::AppendHistory(const CString &sLine)

// AppendHistory
//
// Append a line of input to the history buffer

{
if (!(sLine == GetHistory(0)))
{
m_iHistoryStart = (m_iHistoryStart + (MAX_LINES + 1) - 1) % (MAX_LINES + 1);
if (m_iHistoryStart == m_iHistoryEnd)
m_iHistoryEnd = (m_iHistoryEnd + (MAX_LINES + 1) - 1) % (MAX_LINES + 1);

m_History[m_iHistoryStart] = sLine;
}
m_iHistoryIndex = -1;
}

const CString &CCommandLineDisplay::GetHistory(int iLine)

// GetHistory
//
// Returns the history line

{
return m_History[(m_iHistoryStart + iLine) % (MAX_LINES + 1)];
}

int CCommandLineDisplay::GetHistoryCount(void)

// GetHistoryCount
//
// Returns the number of lines in the history buffer

{
if (m_iHistoryStart == m_iHistoryEnd)
return 0;
else
return ((m_iHistoryEnd + MAX_LINES + 1 - m_iHistoryStart) % (MAX_LINES + 1));
}

ALERROR CCommandLineDisplay::Init (CTranscendenceWnd *pTrans, const RECT &rcRect)

// Init
Expand All @@ -105,6 +146,10 @@ ALERROR CCommandLineDisplay::Init (CTranscendenceWnd *pTrans, const RECT &rcRect
m_rcRect = rcRect;
m_iOutputStart = 0;
m_iOutputEnd = 0;
m_iHistoryStart = 0;
m_iHistoryEnd = 0;
m_iHistoryIndex = -1;
m_iCursorPos = 0;
m_sInput = NULL_STR;
m_bInvalid = true;

Expand All @@ -118,7 +163,19 @@ void CCommandLineDisplay::Input (const CString &sInput)
// Add characters to input buffer

{
m_sInput.Append(sInput);
if (m_iCursorPos < m_sInput.GetLength())
{
CString sCat;
sCat = strSubString(m_sInput, 0, m_iCursorPos);
sCat.Append(sInput);
sCat.Append(strSubString(m_sInput, m_iCursorPos, -1));
m_sInput = sCat;
}
else
{
m_sInput.Append(sInput);
}
m_iCursorPos++;
m_bInvalid = true;
}

Expand All @@ -131,37 +188,81 @@ void CCommandLineDisplay::InputBackspace (void)
{
if (m_sInput.GetLength() > 0)
{
m_sInput = strSubString(m_sInput, 0, m_sInput.GetLength() - 1);
if (m_iCursorPos == m_sInput.GetLength())
m_sInput = strSubString(m_sInput, 0, m_sInput.GetLength() - 1);
else
m_sInput = strCat(strSubString(m_sInput, 0, m_iCursorPos - 1), strSubString(m_sInput, m_iCursorPos, -1));
m_iCursorPos--;
m_bInvalid = true;
}
}

void CCommandLineDisplay::InputDelete(void)

// InputDelete
//
// Delete characters from input buffer

{
if (m_sInput.GetLength() > 0 && m_iCursorPos < m_sInput.GetLength())
{
if (m_iCursorPos == 0)
m_sInput = strSubString(m_sInput, 1, -1);
else
m_sInput = strCat(strSubString(m_sInput, 0, m_iCursorPos), strSubString(m_sInput, m_iCursorPos+1, -1));
m_bInvalid = true;
}
}

void CCommandLineDisplay::InputEnter (void)

// InputEnter
//
// Invoke input

{
m_sLastLine = m_sInput;
AppendHistory(m_sInput);
Output(m_sInput, INPUT_COLOR);
ClearInput();
}

void CCommandLineDisplay::InputLastLine (void)
void CCommandLineDisplay::InputHistoryUp (void)

// InputLastLine
// InputHistoryUp
//
// Recalls the last line
// Recalls a line from the history buffer

{
if (!m_sLastLine.IsBlank())
if (m_iHistoryIndex < (GetHistoryCount()-1))
{
m_sInput = m_sLastLine;
m_iHistoryIndex++;
m_sInput = GetHistory(m_iHistoryIndex);
m_iCursorPos = m_sInput.GetLength();
m_bInvalid = true;
}
}

void CCommandLineDisplay::InputHistoryDown(void)

// InputHistoryDown
//
// Recalls a line from the history buffer

{
if (m_iHistoryIndex > 0)
{
m_iHistoryIndex--;
m_sInput = GetHistory(m_iHistoryIndex);
m_iCursorPos = m_sInput.GetLength();
m_bInvalid = true;
}
else
{
m_iHistoryIndex = -1;
ClearInput();
}
}

void CCommandLineDisplay::OnKeyDown (int iVirtKey, DWORD dwKeyState)

// OnKeyDown
Expand All @@ -175,6 +276,10 @@ void CCommandLineDisplay::OnKeyDown (int iVirtKey, DWORD dwKeyState)
InputBackspace();
break;

case VK_DELETE:
InputDelete();
break;

case VK_RETURN:
{
CString sInput = GetInput();
Expand Down Expand Up @@ -203,7 +308,31 @@ void CCommandLineDisplay::OnKeyDown (int iVirtKey, DWORD dwKeyState)
}

case VK_UP:
InputLastLine();
InputHistoryUp();
break;

case VK_DOWN:
InputHistoryDown();
break;

case VK_LEFT:
if (m_iCursorPos > 0) m_iCursorPos--;
m_bInvalid = true;
break;

case VK_RIGHT:
if (m_iCursorPos < m_sInput.GetLength()) m_iCursorPos++;
m_bInvalid = true;
break;

case VK_HOME:
m_iCursorPos = 0;
m_bInvalid = true;
break;

case VK_END:
m_iCursorPos = m_sInput.GetLength();
m_bInvalid = true;
break;
}
}
Expand Down Expand Up @@ -262,6 +391,13 @@ void CCommandLineDisplay::Paint (CG32bitImage &Dest)
RectHeight(m_rcCursor),
(((m_iCounter % 30) < 20) ? INPUT_COLOR : BACK_COLOR));

// Redraw character under cursor
if ((m_iCounter % 30) >= 20 && m_iCursorPos < m_sInput.GetLength())
{
CString sLine(m_sInput.GetASCIIZPointer() + m_iCursorPos, 1);
m_Buffer.DrawText(m_rcCursor.left, m_rcCursor.top, m_pFonts->Console, INPUT_COLOR, sLine);
}

// Blt

Dest.Blt(0,
Expand Down Expand Up @@ -344,17 +480,20 @@ void CCommandLineDisplay::Update (void)
int iRemainder = iInputCols % iCols;
int iRemainderText = (iRemainder == 0 ? iCols : iRemainder) - 1;

m_rcCursor.left = x + iRemainderText * cxCol;
m_rcCursor.top = y;
m_rcCursor.right = m_rcCursor.left + cxCol;
m_rcCursor.bottom = m_rcCursor.top + cyLine;

int iStart = m_sInput.GetLength() - iRemainderText;
while (y >= yMin && iStart >= 0)
{
CString sLine(m_sInput.GetASCIIZPointer() + iStart, iRemainderText);
m_Buffer.DrawText(x, y, m_pFonts->Console, INPUT_COLOR, sLine);

// Work out where the cursor should be
if (m_iCursorPos >= iStart && (m_iCursorPos - iStart) < iCols)
{
m_rcCursor.left = x + (m_iCursorPos-iStart) * cxCol;
m_rcCursor.top = y;
m_rcCursor.right = m_rcCursor.left + cxCol;
m_rcCursor.bottom = m_rcCursor.top + cyLine;
}
y -= cyLine;
iStart -= iCols;
iRemainderText = iCols;
Expand Down
16 changes: 13 additions & 3 deletions Transcendence/Transcendence.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,15 +819,17 @@ class CCommandLineDisplay
~CCommandLineDisplay (void);

void CleanUp (void);
inline void ClearInput (void) { m_sInput = NULL_STR; m_bInvalid = true; }
inline void ClearInput (void) { m_sInput = NULL_STR; m_iCursorPos = 0; m_bInvalid = true; }
inline const CString &GetInput (void) { return m_sInput; }
inline int GetOutputLineCount (void) { return GetOutputCount(); }
inline const RECT &GetRect (void) { return m_rcRect; }
ALERROR Init (CTranscendenceWnd *pTrans, const RECT &rcRect);
void Input (const CString &sInput);
void InputBackspace (void);
void InputDelete (void);
void InputEnter (void);
void InputLastLine (void);
void InputHistoryUp(void);
void InputHistoryDown(void);
void OnKeyDown (int iVirtKey, DWORD dwKeyState);
void Output (const CString &sOutput, CG32bitPixel rgbColor = CG32bitPixel::Null());
void Paint (CG32bitImage &Dest);
Expand All @@ -843,6 +845,9 @@ class CCommandLineDisplay
const CString &GetOutput (int iLine);
CG32bitPixel GetOutputColor (int iLine);
int GetOutputCount (void);
void AppendHistory(const CString &sLine);
const CString &GetHistory(int iLine);
int GetHistoryCount(void);
void Update (void);

CTranscendenceWnd *m_pTrans;
Expand All @@ -854,7 +859,12 @@ class CCommandLineDisplay
int m_iOutputStart;
int m_iOutputEnd;
CString m_sInput;
CString m_sLastLine;
CString m_History[MAX_LINES + 1];
int m_iHistoryStart;
int m_iHistoryEnd;
int m_iHistoryIndex;
int m_iCursorPos;


CG32bitImage m_Buffer;
bool m_bInvalid;
Expand Down