1 // Copyright (c) 2011-2016 Ryan Prichard
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 #ifndef AGENT_SCRAPER_H
22 #define AGENT_SCRAPER_H
31 #include "ConsoleLine.h"
33 #include "LargeConsoleRead.h"
34 #include "SmallRect.h"
37 class ConsoleScreenBufferInfo;
39 class Win32ConsoleBuffer;
41 // We must be able to issue a single ReadConsoleOutputW call of
42 // MAX_CONSOLE_WIDTH characters, and a single read of approximately several
43 // hundred fewer characters than BUFFER_LINE_COUNT.
44 const int BUFFER_LINE_COUNT = 3000;
45 const int MAX_CONSOLE_WIDTH = 2500;
46 const int MAX_CONSOLE_HEIGHT = 2000;
47 const int SYNC_MARKER_LEN = 16;
48 const int SYNC_MARKER_MARGIN = 200;
53 Win32Console &console,
54 Win32ConsoleBuffer &buffer,
55 std::unique_ptr<Terminal> terminal,
58 void resizeWindow(Win32ConsoleBuffer &buffer,
60 ConsoleScreenBufferInfo &finalInfoOut);
61 void scrapeBuffer(Win32ConsoleBuffer &buffer,
62 ConsoleScreenBufferInfo &finalInfoOut);
63 Terminal &terminal() { return *m_terminal; }
66 void resetConsoleTracking(
67 Terminal::SendClearFlag sendClear, int64_t scrapedLineCount);
68 void markEntireWindowDirty(const SmallRect &windowRect);
69 void scanForDirtyLines(const SmallRect &windowRect);
70 void clearBufferLines(int firstRow, int count);
71 void resizeImpl(const ConsoleScreenBufferInfo &origInfo);
72 void syncConsoleContentAndSize(bool forceResize,
73 ConsoleScreenBufferInfo &finalInfoOut);
74 WORD attributesMask();
75 void directScrapeOutput(const ConsoleScreenBufferInfo &info,
76 bool consoleCursorVisible);
77 bool scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
78 bool consoleCursorVisible,
80 void syncMarkerText(CHAR_INFO (&output)[SYNC_MARKER_LEN]);
82 void createSyncMarker(int row);
85 Win32Console &m_console;
86 Win32ConsoleBuffer *m_consoleBuffer = nullptr;
87 std::unique_ptr<Terminal> m_terminal;
90 unsigned int m_syncCounter = 0;
92 bool m_directMode = false;
94 int64_t m_scrapedLineCount = 0;
95 int64_t m_scrolledCount = 0;
96 int64_t m_maxBufferedLine = -1;
97 LargeConsoleReadBuffer m_readBuffer;
98 std::vector<ConsoleLine> m_bufferData;
99 int m_dirtyWindowTop = -1;
100 int m_dirtyLineCount = 0;
103 #endif // AGENT_SCRAPER_H