installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / src / agent / LargeConsoleRead.h
1 // Copyright (c) 2015 Ryan Prichard
2 //
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:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
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
19 // IN THE SOFTWARE.
20
21 #ifndef LARGE_CONSOLE_READ_H
22 #define LARGE_CONSOLE_READ_H
23
24 #include <windows.h>
25 #include <stdlib.h>
26
27 #include <vector>
28
29 #include "SmallRect.h"
30 #include "../shared/DebugClient.h"
31 #include "../shared/WinptyAssert.h"
32
33 class Win32ConsoleBuffer;
34
35 class LargeConsoleReadBuffer {
36 public:
37     LargeConsoleReadBuffer();
38     const SmallRect &rect() const { return m_rect; }
39     const CHAR_INFO *lineData(int line) const {
40         validateLineNumber(line);
41         return &m_data[(line - m_rect.Top) * m_rectWidth];
42     }
43
44 private:
45     CHAR_INFO *lineDataMut(int line) {
46         validateLineNumber(line);
47         return &m_data[(line - m_rect.Top) * m_rectWidth];
48     }
49
50     void validateLineNumber(int line) const {
51         if (line < m_rect.Top || line > m_rect.Bottom) {
52             trace("Fatal error: LargeConsoleReadBuffer: invalid line %d for "
53                   "read rect %s", line, m_rect.toString().c_str());
54             abort();
55         }
56     }
57
58     SmallRect m_rect;
59     int m_rectWidth;
60     std::vector<CHAR_INFO> m_data;
61
62     friend void largeConsoleRead(LargeConsoleReadBuffer &out,
63                                  Win32ConsoleBuffer &buffer,
64                                  const SmallRect &readArea,
65                                  WORD attributesMask);
66 };
67
68 #endif // LARGE_CONSOLE_READ_H