Fix a bug involving the Terminal::finishOutput call.

Before the Qt removal, Terminal::finishOutput accepted a QPoint object with
a 32-bit line number.  Changing it to accept Coord introduced a bug because
the Coord line number is only 16-bits.  The moveTerminalToLine and sendLine
methods still accepted a 32-bit line number, though.

The result was, after 32768 lines of output, the
Terminal::moveTerminalToLine function would be called alternately with
truncated and untruncated line numbers (e.g. -32000 and 33536), and the
function would generate massive amounts of "cursor up" and "newline"
output.
This commit is contained in:
Ryan Prichard 2012-03-15 02:11:03 -07:00
parent 81dcc5efe7
commit affceb9ffd
3 changed files with 10 additions and 7 deletions

View File

@ -12,6 +12,7 @@
#include <windows.h>
#include <vector>
#include <string>
#include <utility>
const int SC_CONSOLE_MARK = 0xFFF2;
const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
@ -405,7 +406,8 @@ void Agent::scrapeOutput()
createSyncMarker(windowRect.top() - 200);
}
m_terminal->finishOutput(cursor + Coord(0, m_scrolledCount));
m_terminal->finishOutput(std::pair<int, int>(cursor.X,
cursor.Y + m_scrolledCount));
unfreezeConsole();
}

View File

@ -43,7 +43,7 @@ void Terminal::reset(bool sendClearFirst, int newLine)
m_output->write(CSI"1;1H"CSI"2J");
m_remoteLine = newLine;
m_cursorHidden = false;
m_cursorPos = Coord(0, newLine);
m_cursorPos = std::pair<int, int>(0, newLine);
m_remoteColor = -1;
}
@ -96,14 +96,14 @@ void Terminal::sendLine(int line, CHAR_INFO *lineData, int width)
m_output->write(termLine.data(), termLine.size());
}
void Terminal::finishOutput(const Coord &newCursorPos)
void Terminal::finishOutput(const std::pair<int, int> &newCursorPos)
{
if (newCursorPos != m_cursorPos)
hideTerminalCursor();
if (m_cursorHidden) {
moveTerminalToLine(newCursorPos.Y);
moveTerminalToLine(newCursorPos.second);
char buffer[32];
sprintf(buffer, CSI"%dG"CSI"?25h", newCursorPos.X + 1);
sprintf(buffer, CSI"%dG"CSI"?25h", newCursorPos.first + 1);
m_output->write(buffer);
m_cursorHidden = false;
}

View File

@ -3,6 +3,7 @@
#include <windows.h>
#include "Coord.h"
#include <utility>
class NamedPipe;
@ -12,7 +13,7 @@ public:
explicit Terminal(NamedPipe *output);
void reset(bool sendClearFirst, int newLine);
void sendLine(int line, CHAR_INFO *lineData, int width);
void finishOutput(const Coord &newCursorPos);
void finishOutput(const std::pair<int, int> &newCursorPos);
private:
void hideTerminalCursor();
@ -22,7 +23,7 @@ private:
NamedPipe *m_output;
int m_remoteLine;
bool m_cursorHidden;
Coord m_cursorPos;
std::pair<int, int> m_cursorPos;
int m_remoteColor;
};