@@ -18,7 +18,6 @@ internal class WindowsConsole {
18
18
public const int STD_ERROR_HANDLE = - 12 ;
19
19
20
20
internal IntPtr InputHandle , OutputHandle ;
21
- IntPtr ScreenBuffer ;
22
21
readonly uint originalConsoleMode ;
23
22
CursorVisibility ? initialCursorVisibility = null ;
24
23
CursorVisibility ? currentCursorVisibility = null ;
@@ -40,47 +39,47 @@ public WindowsConsole ()
40
39
41
40
public bool WriteToConsole ( Size size , CharInfo [ ] charInfoBuffer , Coord coords , SmallRect window )
42
41
{
43
- if ( ScreenBuffer == IntPtr . Zero ) {
44
- ReadFromConsoleOutput ( size , coords , ref window ) ;
45
- }
42
+ // if (OutputHandle == IntPtr.Zero) {
43
+ // ReadFromConsoleOutput (size, coords, ref window);
44
+ // }
46
45
47
- return WriteConsoleOutput ( ScreenBuffer , charInfoBuffer , coords , new Coord ( ) { X = window . Left , Y = window . Top } , ref window ) ;
46
+ return WriteConsoleOutput ( OutputHandle , charInfoBuffer , coords , new Coord ( ) { X = window . Left , Y = window . Top } , ref window ) ;
48
47
}
49
48
50
- public void ReadFromConsoleOutput ( Size size , Coord coords , ref SmallRect window )
51
- {
52
- ScreenBuffer = CreateConsoleScreenBuffer (
53
- DesiredAccess . GenericRead | DesiredAccess . GenericWrite ,
54
- ShareMode . FileShareRead | ShareMode . FileShareWrite ,
55
- IntPtr . Zero ,
56
- 1 ,
57
- IntPtr . Zero
58
- ) ;
59
- if ( ScreenBuffer == INVALID_HANDLE_VALUE ) {
60
- var err = Marshal . GetLastWin32Error ( ) ;
49
+ // public void ReadFromConsoleOutput (Size size, Coord coords, ref SmallRect window)
50
+ // {
51
+ // OutputHandle = CreateConsoleScreenBuffer (
52
+ // DesiredAccess.GenericRead | DesiredAccess.GenericWrite,
53
+ // ShareMode.FileShareRead | ShareMode.FileShareWrite,
54
+ // IntPtr.Zero,
55
+ // 1,
56
+ // IntPtr.Zero
57
+ // );
58
+ // if (ScreenBuffer == INVALID_HANDLE_VALUE) {
59
+ // var err = Marshal.GetLastWin32Error ();
61
60
62
- if ( err != 0 )
63
- throw new System . ComponentModel . Win32Exception ( err ) ;
64
- }
61
+ // if (err != 0)
62
+ // throw new System.ComponentModel.Win32Exception (err);
63
+ // }
65
64
66
- if ( ! initialCursorVisibility . HasValue && GetCursorVisibility ( out CursorVisibility visibility ) ) {
67
- initialCursorVisibility = visibility ;
68
- }
65
+ // if (!initialCursorVisibility.HasValue && GetCursorVisibility (out CursorVisibility visibility)) {
66
+ // initialCursorVisibility = visibility;
67
+ // }
69
68
70
- if ( ! SetConsoleActiveScreenBuffer ( ScreenBuffer ) ) {
71
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
72
- }
69
+ // if (!SetConsoleActiveScreenBuffer (ScreenBuffer)) {
70
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
71
+ // }
73
72
74
- OriginalStdOutChars = new CharInfo [ size . Height * size . Width ] ;
73
+ // OriginalStdOutChars = new CharInfo [size.Height * size.Width];
75
74
76
- if ( ! ReadConsoleOutput ( ScreenBuffer , OriginalStdOutChars , coords , new Coord ( ) { X = 0 , Y = 0 } , ref window ) ) {
77
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
78
- }
79
- }
75
+ // if (!ReadConsoleOutput (ScreenBuffer, OriginalStdOutChars, coords, new Coord () { X = 0, Y = 0 }, ref window)) {
76
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
77
+ // }
78
+ // }
80
79
81
80
public bool SetCursorPosition ( Coord position )
82
81
{
83
- return SetConsoleCursorPosition ( ScreenBuffer , position ) ;
82
+ return SetConsoleCursorPosition ( OutputHandle , position ) ;
84
83
}
85
84
86
85
public void SetInitialCursorVisibility ( )
@@ -92,11 +91,11 @@ public void SetInitialCursorVisibility ()
92
91
93
92
public bool GetCursorVisibility ( out CursorVisibility visibility )
94
93
{
95
- if ( ScreenBuffer == IntPtr . Zero ) {
94
+ if ( OutputHandle == IntPtr . Zero ) {
96
95
visibility = CursorVisibility . Invisible ;
97
96
return false ;
98
97
}
99
- if ( ! GetConsoleCursorInfo ( ScreenBuffer , out ConsoleCursorInfo info ) ) {
98
+ if ( ! GetConsoleCursorInfo ( OutputHandle , out ConsoleCursorInfo info ) ) {
100
99
var err = Marshal . GetLastWin32Error ( ) ;
101
100
if ( err != 0 ) {
102
101
throw new System . ComponentModel . Win32Exception ( err ) ;
@@ -149,7 +148,7 @@ public bool SetCursorVisibility (CursorVisibility visibility)
149
148
bVisible = ( ( uint ) visibility & 0xFF00 ) != 0
150
149
} ;
151
150
152
- if ( ! SetConsoleCursorInfo ( ScreenBuffer , ref info ) )
151
+ if ( ! SetConsoleCursorInfo ( OutputHandle , ref info ) )
153
152
return false ;
154
153
155
154
currentCursorVisibility = visibility ;
@@ -165,28 +164,28 @@ public void Cleanup ()
165
164
}
166
165
167
166
ConsoleMode = originalConsoleMode ;
168
- if ( ! SetConsoleActiveScreenBuffer ( OutputHandle ) ) {
169
- var err = Marshal . GetLastWin32Error ( ) ;
170
- Console . WriteLine ( "Error: {0}" , err ) ;
171
- }
167
+ // if (!SetConsoleActiveScreenBuffer (OutputHandle)) {
168
+ // var err = Marshal.GetLastWin32Error ();
169
+ // Console.WriteLine ("Error: {0}", err);
170
+ // }
172
171
173
- if ( ScreenBuffer != IntPtr . Zero ) {
174
- CloseHandle ( ScreenBuffer ) ;
175
- }
172
+ // if (ScreenBuffer != IntPtr.Zero) {
173
+ // CloseHandle (ScreenBuffer);
174
+ // }
176
175
177
- ScreenBuffer = IntPtr . Zero ;
176
+ // ScreenBuffer = IntPtr.Zero;
178
177
}
179
178
180
179
internal Size GetConsoleBufferWindow ( out Point position )
181
180
{
182
- if ( ScreenBuffer == IntPtr . Zero ) {
181
+ if ( OutputHandle == IntPtr . Zero ) {
183
182
position = Point . Empty ;
184
183
return Size . Empty ;
185
184
}
186
185
187
186
var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX ( ) ;
188
187
csbi . cbSize = ( uint ) Marshal . SizeOf ( csbi ) ;
189
- if ( ! GetConsoleScreenBufferInfoEx ( ScreenBuffer , ref csbi ) ) {
188
+ if ( ! GetConsoleScreenBufferInfoEx ( OutputHandle , ref csbi ) ) {
190
189
//throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
191
190
position = Point . Empty ;
192
191
return Size . Empty ;
@@ -212,65 +211,65 @@ internal Size GetConsoleOutputWindow (out Point position)
212
211
return sz ;
213
212
}
214
213
215
- internal Size SetConsoleWindow ( short cols , short rows )
216
- {
217
- var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX ( ) ;
218
- csbi . cbSize = ( uint ) Marshal . SizeOf ( csbi ) ;
219
-
220
- if ( ! GetConsoleScreenBufferInfoEx ( ScreenBuffer , ref csbi ) ) {
221
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
222
- }
223
- var maxWinSize = GetLargestConsoleWindowSize ( ScreenBuffer ) ;
224
- var newCols = Math . Min ( cols , maxWinSize . X ) ;
225
- var newRows = Math . Min ( rows , maxWinSize . Y ) ;
226
- csbi . dwSize = new Coord ( newCols , Math . Max ( newRows , ( short ) 1 ) ) ;
227
- csbi . srWindow = new SmallRect ( 0 , 0 , newCols , newRows ) ;
228
- csbi . dwMaximumWindowSize = new Coord ( newCols , newRows ) ;
229
- if ( ! SetConsoleScreenBufferInfoEx ( ScreenBuffer , ref csbi ) ) {
230
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
231
- }
232
- var winRect = new SmallRect ( 0 , 0 , ( short ) ( newCols - 1 ) , ( short ) Math . Max ( newRows - 1 , 0 ) ) ;
233
- if ( ! SetConsoleWindowInfo ( OutputHandle , true , ref winRect ) ) {
234
- //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
235
- return new Size ( cols , rows ) ;
236
- }
237
- SetConsoleOutputWindow ( csbi ) ;
238
- return new Size ( winRect . Right + 1 , newRows - 1 < 0 ? 0 : winRect . Bottom + 1 ) ;
239
- }
240
-
241
- void SetConsoleOutputWindow ( CONSOLE_SCREEN_BUFFER_INFOEX csbi )
242
- {
243
- if ( ScreenBuffer != IntPtr . Zero && ! SetConsoleScreenBufferInfoEx ( ScreenBuffer , ref csbi ) ) {
244
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
245
- }
246
- }
247
-
248
- internal Size SetConsoleOutputWindow ( out Point position )
249
- {
250
- if ( ScreenBuffer == IntPtr . Zero ) {
251
- position = Point . Empty ;
252
- return Size . Empty ;
253
- }
254
-
255
- var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX ( ) ;
256
- csbi . cbSize = ( uint ) Marshal . SizeOf ( csbi ) ;
257
- if ( ! GetConsoleScreenBufferInfoEx ( ScreenBuffer , ref csbi ) ) {
258
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
259
- }
260
- var sz = new Size ( csbi . srWindow . Right - csbi . srWindow . Left + 1 ,
261
- Math . Max ( csbi . srWindow . Bottom - csbi . srWindow . Top + 1 , 0 ) ) ;
262
- position = new Point ( csbi . srWindow . Left , csbi . srWindow . Top ) ;
263
- SetConsoleOutputWindow ( csbi ) ;
264
- var winRect = new SmallRect ( 0 , 0 , ( short ) ( sz . Width - 1 ) , ( short ) Math . Max ( sz . Height - 1 , 0 ) ) ;
265
- if ( ! SetConsoleScreenBufferInfoEx ( OutputHandle , ref csbi ) ) {
266
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
267
- }
268
- if ( ! SetConsoleWindowInfo ( OutputHandle , true , ref winRect ) ) {
269
- throw new System . ComponentModel . Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
270
- }
271
-
272
- return sz ;
273
- }
214
+ // internal Size SetConsoleWindow (short cols, short rows)
215
+ // {
216
+ // var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX ();
217
+ // csbi.cbSize = (uint)Marshal.SizeOf (csbi);
218
+
219
+ // if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) {
220
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
221
+ // }
222
+ // var maxWinSize = GetLargestConsoleWindowSize (ScreenBuffer);
223
+ // var newCols = Math.Min (cols, maxWinSize.X);
224
+ // var newRows = Math.Min (rows, maxWinSize.Y);
225
+ // csbi.dwSize = new Coord (newCols, Math.Max (newRows, (short)1));
226
+ // csbi.srWindow = new SmallRect (0, 0, newCols, newRows);
227
+ // csbi.dwMaximumWindowSize = new Coord (newCols, newRows);
228
+ // if (!SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) {
229
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
230
+ // }
231
+ // var winRect = new SmallRect (0, 0, (short)(newCols - 1), (short)Math.Max (newRows - 1, 0));
232
+ // if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) {
233
+ // //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
234
+ // return new Size (cols, rows);
235
+ // }
236
+ // SetConsoleOutputWindow (csbi);
237
+ // return new Size (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1);
238
+ // }
239
+
240
+ // void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi)
241
+ // {
242
+ // if (ScreenBuffer != IntPtr.Zero && !SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) {
243
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
244
+ // }
245
+ // }
246
+
247
+ // internal Size SetConsoleOutputWindow (out Point position)
248
+ // {
249
+ // if (ScreenBuffer == IntPtr.Zero) {
250
+ // position = Point.Empty;
251
+ // return Size.Empty;
252
+ // }
253
+
254
+ // var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX ();
255
+ // csbi.cbSize = (uint)Marshal.SizeOf (csbi);
256
+ // if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) {
257
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
258
+ // }
259
+ // var sz = new Size (csbi.srWindow.Right - csbi.srWindow.Left + 1,
260
+ // Math.Max (csbi.srWindow.Bottom - csbi.srWindow.Top + 1, 0));
261
+ // position = new Point (csbi.srWindow.Left, csbi.srWindow.Top);
262
+ // SetConsoleOutputWindow (csbi);
263
+ // var winRect = new SmallRect (0, 0, (short)(sz.Width - 1), (short)Math.Max (sz.Height - 1, 0));
264
+ // if (!SetConsoleScreenBufferInfoEx (OutputHandle, ref csbi)) {
265
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
266
+ // }
267
+ // if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) {
268
+ // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
269
+ // }
270
+
271
+ // return sz;
272
+ // }
274
273
275
274
//bool ContinueListeningForConsoleEvents = true;
276
275
@@ -734,7 +733,7 @@ public WindowsDriver ()
734
733
WinConsole = new WindowsConsole ( ) ;
735
734
clipboard = new WindowsClipboard ( ) ;
736
735
737
- isWindowsTerminal = Environment . GetEnvironmentVariable ( "WT_SESSION" ) != null ;
736
+ isWindowsTerminal = Environment . GetEnvironmentVariable ( "WT_SESSION" ) != null || Environment . GetEnvironmentVariable ( "VSAPPIDNAME" ) != null ;
738
737
}
739
738
740
739
public override void PrepareToRun ( MainLoop mainLoop , Action < KeyEvent > keyHandler , Action < KeyEvent > keyDownHandler , Action < KeyEvent > keyUpHandler , Action < MouseEvent > mouseHandler )
@@ -748,28 +747,28 @@ public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandle
748
747
749
748
mLoop . ProcessInput = ( e ) => ProcessInput ( e ) ;
750
749
751
- mLoop . WinChanged = ( e ) => {
752
- ChangeWin ( e ) ;
753
- } ;
754
- }
755
-
756
- private void ChangeWin ( Size e )
757
- {
758
- var w = e . Width ;
759
- if ( w == cols - 3 && e . Height < rows ) {
760
- w += 3 ;
761
- }
762
- var newSize = WinConsole . SetConsoleWindow (
763
- ( short ) Math . Max ( w , 16 ) , ( short ) Math . Max ( e . Height , 0 ) ) ;
764
-
765
- left = 0 ;
766
- top = 0 ;
767
- cols = newSize . Width ;
768
- rows = newSize . Height ;
769
- ResizeScreen ( ) ;
770
- UpdateOffScreen ( ) ;
771
- TerminalResized . Invoke ( ) ;
772
- }
750
+ // mLoop.WinChanged = (e) => {
751
+ // ChangeWin (e);
752
+ // };
753
+ }
754
+
755
+ // private void ChangeWin (Size e)
756
+ // {
757
+ // var w = e.Width;
758
+ // if (w == cols - 3 && e.Height < rows) {
759
+ // w += 3;
760
+ // }
761
+ // var newSize = WinConsole.SetConsoleWindow (
762
+ // (short)Math.Max (w, 16), (short)Math.Max (e.Height, 0));
763
+
764
+ // left = 0;
765
+ // top = 0;
766
+ // cols = newSize.Width;
767
+ // rows = newSize.Height;
768
+ // ResizeScreen ();
769
+ // UpdateOffScreen ();
770
+ // TerminalResized.Invoke ();
771
+ // }
773
772
774
773
void ProcessInput ( WindowsConsole . InputRecord inputEvent )
775
774
{
@@ -893,6 +892,14 @@ void ProcessInput (WindowsConsole.InputRecord inputEvent)
893
892
case WindowsConsole . EventType . Focus :
894
893
keyModifiers = null ;
895
894
break ;
895
+
896
+ case WindowsConsole . EventType . WindowBufferSize :
897
+ cols = inputEvent . WindowBufferSizeEvent . size . X ;
898
+ rows = inputEvent . WindowBufferSizeEvent . size . Y ;
899
+
900
+ ResizeScreen ( ) ;
901
+ TerminalResized . Invoke ( ) ;
902
+ break ;
896
903
}
897
904
}
898
905
0 commit comments