Make width/height limits consistent and cap out-of-bounds values
When resizing, ensure that the replacement sync marker does not become visible if the buffer height is increased by more than the marker's margin (currently 200 rows).
This commit is contained in:
parent
fa6ba9c725
commit
3388c5449f
@ -153,6 +153,10 @@ Agent::Agent(LPCWSTR controlPipeName,
|
||||
{
|
||||
trace("Agent::Agent entered");
|
||||
|
||||
ASSERT(initialCols >= 1 && initialRows >= 1);
|
||||
initialCols = std::min(initialCols, MAX_CONSOLE_WIDTH);
|
||||
initialRows = std::min(initialRows, MAX_CONSOLE_HEIGHT);
|
||||
|
||||
const bool outputColor =
|
||||
!m_plainMode || (agentFlags & WINPTY_FLAG_COLOR_ESCAPES);
|
||||
const Coord initialSize(initialCols, initialRows);
|
||||
@ -413,8 +417,8 @@ void Agent::handleStartProcessPacket(ReadBuffer &packet)
|
||||
|
||||
void Agent::handleSetSizePacket(ReadBuffer &packet)
|
||||
{
|
||||
int cols = packet.getInt32();
|
||||
int rows = packet.getInt32();
|
||||
const int cols = packet.getInt32();
|
||||
const int rows = packet.getInt32();
|
||||
packet.assertEof();
|
||||
resizeWindow(cols, rows);
|
||||
auto reply = newPacket();
|
||||
@ -515,15 +519,12 @@ std::unique_ptr<Win32ConsoleBuffer> Agent::openPrimaryBuffer()
|
||||
}
|
||||
}
|
||||
|
||||
void Agent::resizeWindow(const int cols, const int rows)
|
||||
void Agent::resizeWindow(int cols, int rows)
|
||||
{
|
||||
if (cols < 1 ||
|
||||
cols > MAX_CONSOLE_WIDTH ||
|
||||
rows < 1 ||
|
||||
rows > BUFFER_LINE_COUNT - 1) {
|
||||
trace("resizeWindow: invalid size: cols=%d,rows=%d", cols, rows);
|
||||
return;
|
||||
}
|
||||
ASSERT(cols >= 1 && rows >= 1);
|
||||
cols = std::min(cols, MAX_CONSOLE_WIDTH);
|
||||
rows = std::min(rows, MAX_CONSOLE_HEIGHT);
|
||||
|
||||
Win32Console::FreezeGuard guard(m_console, m_console.frozen());
|
||||
const Coord newSize(cols, rows);
|
||||
ConsoleScreenBufferInfo info;
|
||||
|
@ -209,7 +209,11 @@ void Scraper::resizeImpl(const ConsoleScreenBufferInfo &origInfo)
|
||||
m_consoleBuffer->clearLines(0, origWindowRect.Top, origInfo);
|
||||
clearBufferLines(0, origWindowRect.Top, origInfo.wAttributes);
|
||||
if (m_syncRow != -1) {
|
||||
createSyncMarker(m_syncRow);
|
||||
createSyncMarker(std::min(
|
||||
m_syncRow,
|
||||
BUFFER_LINE_COUNT - rows
|
||||
- SYNC_MARKER_LEN
|
||||
- SYNC_MARKER_MARGIN));
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,8 +456,10 @@ bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
|
||||
// Creating a new sync row requires clearing part of the console buffer, so
|
||||
// avoid doing it if there's already a sync row that's good enough.
|
||||
// TODO: replace hard-coded constants
|
||||
const int newSyncRow = static_cast<int>(windowRect.top()) - 200;
|
||||
const bool shouldCreateSyncRow = newSyncRow >= m_syncRow + 200;
|
||||
const int newSyncRow =
|
||||
static_cast<int>(windowRect.top()) - SYNC_MARKER_LEN - SYNC_MARKER_MARGIN;
|
||||
const bool shouldCreateSyncRow =
|
||||
newSyncRow >= m_syncRow + SYNC_MARKER_LEN + SYNC_MARKER_MARGIN;
|
||||
if (tentative && shouldCreateSyncRow) {
|
||||
// It's difficult even in principle to put down a new marker if the
|
||||
// console can scroll an arbitrarily amount while we're writing.
|
||||
|
@ -43,7 +43,9 @@ class Win32ConsoleBuffer;
|
||||
// hundred fewer characters than BUFFER_LINE_COUNT.
|
||||
const int BUFFER_LINE_COUNT = 3000;
|
||||
const int MAX_CONSOLE_WIDTH = 2500;
|
||||
const int MAX_CONSOLE_HEIGHT = 2000;
|
||||
const int SYNC_MARKER_LEN = 16;
|
||||
const int SYNC_MARKER_MARGIN = 200;
|
||||
|
||||
class Scraper {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user