2
0

NetDriver.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. #nullable enable
  2. //
  3. // NetDriver.cs: The System.Console-based .NET driver, works on Windows and Unix, but is not particularly efficient.
  4. //
  5. using System.Runtime.InteropServices;
  6. using static Terminal.Gui.Drivers.NetEvents;
  7. namespace Terminal.Gui.Drivers;
  8. internal class NetDriver : ConsoleDriver
  9. {
  10. public bool IsWinPlatform { get; private set; }
  11. public NetWinVTConsole? NetWinConsole { get; private set; }
  12. public override void Suspend ()
  13. {
  14. if (Environment.OSVersion.Platform != PlatformID.Unix)
  15. {
  16. return;
  17. }
  18. StopReportingMouseMoves ();
  19. if (!RunningUnitTests)
  20. {
  21. Console.ResetColor ();
  22. Console.Clear ();
  23. //Disable alternative screen buffer.
  24. Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll);
  25. //Set cursor key to cursor.
  26. Console.Out.Write (EscSeqUtils.CSI_ShowCursor);
  27. Platform.Suspend ();
  28. //Enable alternative screen buffer.
  29. Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
  30. SetContentsAsDirty ();
  31. Refresh ();
  32. }
  33. StartReportingMouseMoves ();
  34. }
  35. public override bool UpdateScreen ()
  36. {
  37. bool updated = false;
  38. if (RunningUnitTests
  39. || _winSizeChanging
  40. || Console.WindowHeight < 1
  41. || Contents?.Length != Rows * Cols
  42. || Rows != Console.WindowHeight)
  43. {
  44. return updated;
  45. }
  46. var top = 0;
  47. var left = 0;
  48. int rows = Rows;
  49. int cols = Cols;
  50. var output = new StringBuilder ();
  51. Attribute? redrawAttr = null;
  52. int lastCol = -1;
  53. CursorVisibility? savedVisibility = _cachedCursorVisibility;
  54. SetCursorVisibility (CursorVisibility.Invisible);
  55. for (int row = top; row < rows; row++)
  56. {
  57. if (Console.WindowHeight < 1)
  58. {
  59. return updated;
  60. }
  61. if (!_dirtyLines! [row])
  62. {
  63. continue;
  64. }
  65. if (!SetCursorPosition (0, row))
  66. {
  67. return updated;
  68. }
  69. updated = true;
  70. _dirtyLines [row] = false;
  71. output.Clear ();
  72. for (int col = left; col < cols; col++)
  73. {
  74. lastCol = -1;
  75. var outputWidth = 0;
  76. for (; col < cols; col++)
  77. {
  78. if (!Contents [row, col].IsDirty)
  79. {
  80. if (output.Length > 0)
  81. {
  82. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  83. }
  84. else if (lastCol == -1)
  85. {
  86. lastCol = col;
  87. }
  88. if (lastCol + 1 < cols)
  89. {
  90. lastCol++;
  91. }
  92. continue;
  93. }
  94. if (lastCol == -1)
  95. {
  96. lastCol = col;
  97. }
  98. Attribute attr = Contents [row, col].Attribute!.Value;
  99. // Performance: Only send the escape sequence if the attribute has changed.
  100. if (attr != redrawAttr)
  101. {
  102. redrawAttr = attr;
  103. if (Force16Colors)
  104. {
  105. output.Append (
  106. EscSeqUtils.CSI_SetGraphicsRendition (
  107. MapColors (
  108. (ConsoleColor)attr.Background.GetClosestNamedColor16 (),
  109. false
  110. ),
  111. MapColors ((ConsoleColor)attr.Foreground.GetClosestNamedColor16 ())
  112. )
  113. );
  114. }
  115. else
  116. {
  117. output.Append (
  118. EscSeqUtils.CSI_SetForegroundColorRGB (
  119. attr.Foreground.R,
  120. attr.Foreground.G,
  121. attr.Foreground.B
  122. )
  123. );
  124. output.Append (
  125. EscSeqUtils.CSI_SetBackgroundColorRGB (
  126. attr.Background.R,
  127. attr.Background.G,
  128. attr.Background.B
  129. )
  130. );
  131. }
  132. }
  133. outputWidth++;
  134. Rune rune = Contents [row, col].Rune;
  135. output.Append (rune);
  136. if (Contents [row, col].CombiningMarks.Count > 0)
  137. {
  138. // AtlasEngine does not support NON-NORMALIZED combining marks in a way
  139. // compatible with the driver architecture. Any CMs (except in the first col)
  140. // are correctly combined with the base char, but are ALSO treated as 1 column
  141. // width codepoints E.g. `echo "[e`u{0301}`u{0301}]"` will output `[é ]`.
  142. //
  143. // For now, we just ignore the list of CMs.
  144. //foreach (var combMark in Contents [row, col].CombiningMarks) {
  145. // output.Append (combMark);
  146. //}
  147. // WriteToConsole (output, ref lastCol, row, ref outputWidth);
  148. }
  149. else if (rune.IsSurrogatePair () && rune.GetColumns () < 2)
  150. {
  151. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  152. SetCursorPosition (col - 1, row);
  153. }
  154. Contents [row, col].IsDirty = false;
  155. }
  156. }
  157. if (output.Length > 0)
  158. {
  159. SetCursorPosition (lastCol, row);
  160. Console.Write (output);
  161. }
  162. foreach (var s in Application.Sixel)
  163. {
  164. if (!string.IsNullOrWhiteSpace (s.SixelData))
  165. {
  166. SetCursorPosition (s.ScreenPosition.X, s.ScreenPosition.Y);
  167. Console.Write (s.SixelData);
  168. }
  169. }
  170. }
  171. SetCursorPosition (0, 0);
  172. _cachedCursorVisibility = savedVisibility;
  173. void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
  174. {
  175. SetCursorPosition (lastCol, row);
  176. Console.Write (output);
  177. output.Clear ();
  178. lastCol += outputWidth;
  179. outputWidth = 0;
  180. }
  181. return updated;
  182. }
  183. #region Init/End/MainLoop
  184. // BUGBUG: Fix this nullable issue.
  185. /// <inheritdoc />
  186. internal override IAnsiResponseParser GetParser () => _mainLoopDriver!._netEvents!.Parser;
  187. internal NetMainLoop? _mainLoopDriver;
  188. /// <inheritdoc />
  189. public override MainLoop Init ()
  190. {
  191. Console.OutputEncoding = Encoding.UTF8;
  192. PlatformID p = Environment.OSVersion.Platform;
  193. if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
  194. {
  195. IsWinPlatform = true;
  196. try
  197. {
  198. NetWinConsole = new NetWinVTConsole ();
  199. }
  200. catch (ApplicationException)
  201. {
  202. // Likely running as a unit test, or in a non-interactive session.
  203. }
  204. }
  205. if (IsWinPlatform)
  206. {
  207. Clipboard = new WindowsClipboard ();
  208. }
  209. else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX))
  210. {
  211. Clipboard = new MacOSXClipboard ();
  212. }
  213. else
  214. {
  215. if (CursesDriver.Is_WSL_Platform ())
  216. {
  217. Clipboard = new WSLClipboard ();
  218. }
  219. else
  220. {
  221. Clipboard = new CursesClipboard ();
  222. }
  223. }
  224. if (!RunningUnitTests)
  225. {
  226. Console.TreatControlCAsInput = true;
  227. Cols = Console.WindowWidth;
  228. Rows = Console.WindowHeight;
  229. //Enable alternative screen buffer.
  230. Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
  231. //Set cursor key to application.
  232. Console.Out.Write (EscSeqUtils.CSI_HideCursor);
  233. }
  234. else
  235. {
  236. // We are being run in an environment that does not support a console
  237. // such as a unit test, or a pipe.
  238. Cols = 80;
  239. Rows = 24;
  240. }
  241. ResizeScreen ();
  242. ClearContents ();
  243. CurrentAttribute = new (Color.White, Color.Black);
  244. StartReportingMouseMoves ();
  245. _mainLoopDriver = new (this);
  246. _mainLoopDriver.ProcessInput = ProcessInput;
  247. return new (_mainLoopDriver);
  248. }
  249. private void ProcessInput (InputResult inputEvent)
  250. {
  251. switch (inputEvent.EventType)
  252. {
  253. case EventType.Key:
  254. ConsoleKeyInfo consoleKeyInfo = inputEvent.ConsoleKeyInfo;
  255. //if (consoleKeyInfo.Key == ConsoleKey.Packet) {
  256. // consoleKeyInfo = FromVKPacketToKConsoleKeyInfo (consoleKeyInfo);
  257. //}
  258. //Debug.WriteLine ($"event: {inputEvent}");
  259. KeyCode map = EscSeqUtils.MapKey (consoleKeyInfo);
  260. if (map == KeyCode.Null)
  261. {
  262. break;
  263. }
  264. if (IsValidInput (map, out map))
  265. {
  266. OnKeyDown (new (map));
  267. OnKeyUp (new (map));
  268. }
  269. break;
  270. case EventType.Mouse:
  271. MouseEventArgs me = ToDriverMouse (inputEvent.MouseEvent);
  272. //Debug.WriteLine ($"NetDriver: ({me.X},{me.Y}) - {me.Flags}");
  273. OnMouseEvent (me);
  274. break;
  275. case EventType.WindowSize:
  276. _winSizeChanging = true;
  277. Top = 0;
  278. Left = 0;
  279. Cols = inputEvent.WindowSizeEvent.Size.Width;
  280. Rows = Math.Max (inputEvent.WindowSizeEvent.Size.Height, 0);
  281. ;
  282. ResizeScreen ();
  283. ClearContents ();
  284. _winSizeChanging = false;
  285. OnSizeChanged (new (new (Cols, Rows)));
  286. break;
  287. case EventType.RequestResponse:
  288. break;
  289. case EventType.WindowPosition:
  290. break;
  291. default:
  292. throw new ArgumentOutOfRangeException ();
  293. }
  294. }
  295. public override void End ()
  296. {
  297. StopReportingMouseMoves ();
  298. if (!RunningUnitTests)
  299. {
  300. Console.ResetColor ();
  301. //Disable alternative screen buffer.
  302. Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll);
  303. //Set cursor key to cursor.
  304. Console.Out.Write (EscSeqUtils.CSI_ShowCursor);
  305. Console.Out.Close ();
  306. // Reset the console to its original state
  307. // after sending the escape sequences to restore
  308. // alternative buffer and cursor visibility.
  309. NetWinConsole?.Cleanup ();
  310. }
  311. }
  312. #endregion Init/End/MainLoop
  313. #region Color Handling
  314. public override bool SupportsTrueColor => Environment.OSVersion.Platform == PlatformID.Unix
  315. || (IsWinPlatform && Environment.OSVersion.Version.Build >= 14931);
  316. private const int COLOR_BLACK = 30;
  317. private const int COLOR_BLUE = 34;
  318. private const int COLOR_BRIGHT_BLACK = 90;
  319. private const int COLOR_BRIGHT_BLUE = 94;
  320. private const int COLOR_BRIGHT_CYAN = 96;
  321. private const int COLOR_BRIGHT_GREEN = 92;
  322. private const int COLOR_BRIGHT_MAGENTA = 95;
  323. private const int COLOR_BRIGHT_RED = 91;
  324. private const int COLOR_BRIGHT_WHITE = 97;
  325. private const int COLOR_BRIGHT_YELLOW = 93;
  326. private const int COLOR_CYAN = 36;
  327. private const int COLOR_GREEN = 32;
  328. private const int COLOR_MAGENTA = 35;
  329. private const int COLOR_RED = 31;
  330. private const int COLOR_WHITE = 37;
  331. private const int COLOR_YELLOW = 33;
  332. //// Cache the list of ConsoleColor values.
  333. //[UnconditionalSuppressMessage (
  334. // "AOT",
  335. // "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.",
  336. // Justification = "<Pending>")]
  337. //private static readonly HashSet<int> ConsoleColorValues = new (
  338. // Enum.GetValues (typeof (ConsoleColor))
  339. // .OfType<ConsoleColor> ()
  340. // .Select (c => (int)c)
  341. // );
  342. // Dictionary for mapping ConsoleColor values to the values used by System.Net.Console.
  343. private static readonly Dictionary<ConsoleColor, int> _colorMap = new ()
  344. {
  345. { ConsoleColor.Black, COLOR_BLACK },
  346. { ConsoleColor.DarkBlue, COLOR_BLUE },
  347. { ConsoleColor.DarkGreen, COLOR_GREEN },
  348. { ConsoleColor.DarkCyan, COLOR_CYAN },
  349. { ConsoleColor.DarkRed, COLOR_RED },
  350. { ConsoleColor.DarkMagenta, COLOR_MAGENTA },
  351. { ConsoleColor.DarkYellow, COLOR_YELLOW },
  352. { ConsoleColor.Gray, COLOR_WHITE },
  353. { ConsoleColor.DarkGray, COLOR_BRIGHT_BLACK },
  354. { ConsoleColor.Blue, COLOR_BRIGHT_BLUE },
  355. { ConsoleColor.Green, COLOR_BRIGHT_GREEN },
  356. { ConsoleColor.Cyan, COLOR_BRIGHT_CYAN },
  357. { ConsoleColor.Red, COLOR_BRIGHT_RED },
  358. { ConsoleColor.Magenta, COLOR_BRIGHT_MAGENTA },
  359. { ConsoleColor.Yellow, COLOR_BRIGHT_YELLOW },
  360. { ConsoleColor.White, COLOR_BRIGHT_WHITE }
  361. };
  362. // Map a ConsoleColor to a platform dependent value.
  363. private int MapColors (ConsoleColor color, bool isForeground = true)
  364. {
  365. return _colorMap.TryGetValue (color, out int colorValue) ? colorValue + (isForeground ? 0 : 10) : 0;
  366. }
  367. #endregion
  368. #region Cursor Handling
  369. private bool SetCursorPosition (int col, int row)
  370. {
  371. if (IsWinPlatform)
  372. {
  373. // Could happens that the windows is still resizing and the col is bigger than Console.WindowWidth.
  374. try
  375. {
  376. Console.SetCursorPosition (col, row);
  377. return true;
  378. }
  379. catch (Exception)
  380. {
  381. return false;
  382. }
  383. }
  384. // + 1 is needed because non-Windows is based on 1 instead of 0 and
  385. // Console.CursorTop/CursorLeft isn't reliable.
  386. Console.Out.Write (EscSeqUtils.CSI_SetCursorPosition (row + 1, col + 1));
  387. return true;
  388. }
  389. private CursorVisibility? _cachedCursorVisibility;
  390. public override void UpdateCursor ()
  391. {
  392. EnsureCursorVisibility ();
  393. if (Col >= 0 && Col < Cols && Row >= 0 && Row <= Rows)
  394. {
  395. SetCursorPosition (Col, Row);
  396. SetWindowPosition (0, Row);
  397. }
  398. }
  399. public override bool GetCursorVisibility (out CursorVisibility visibility)
  400. {
  401. visibility = _cachedCursorVisibility ?? CursorVisibility.Default;
  402. return visibility == CursorVisibility.Default;
  403. }
  404. public override bool SetCursorVisibility (CursorVisibility visibility)
  405. {
  406. _cachedCursorVisibility = visibility;
  407. Console.Out.Write (visibility == CursorVisibility.Default ? EscSeqUtils.CSI_ShowCursor : EscSeqUtils.CSI_HideCursor);
  408. return visibility == CursorVisibility.Default;
  409. }
  410. private void EnsureCursorVisibility ()
  411. {
  412. if (!(Col >= 0 && Row >= 0 && Col < Cols && Row < Rows))
  413. {
  414. GetCursorVisibility (out CursorVisibility cursorVisibility);
  415. _cachedCursorVisibility = cursorVisibility;
  416. SetCursorVisibility (CursorVisibility.Invisible);
  417. return;
  418. }
  419. SetCursorVisibility (_cachedCursorVisibility ?? CursorVisibility.Default);
  420. }
  421. #endregion
  422. #region Mouse Handling
  423. public void StartReportingMouseMoves ()
  424. {
  425. if (!RunningUnitTests)
  426. {
  427. Console.Out.Write (EscSeqUtils.CSI_EnableMouseEvents);
  428. }
  429. }
  430. public void StopReportingMouseMoves ()
  431. {
  432. if (!RunningUnitTests)
  433. {
  434. Console.Out.Write (EscSeqUtils.CSI_DisableMouseEvents);
  435. }
  436. }
  437. private MouseEventArgs ToDriverMouse (MouseEvent me)
  438. {
  439. //System.Diagnostics.Debug.WriteLine ($"X: {me.Position.X}; Y: {me.Position.Y}; ButtonState: {me.ButtonState}");
  440. MouseFlags mouseFlag = 0;
  441. if ((me.ButtonState & MouseButtonState.Button1Pressed) != 0)
  442. {
  443. mouseFlag |= MouseFlags.Button1Pressed;
  444. }
  445. if ((me.ButtonState & MouseButtonState.Button1Released) != 0)
  446. {
  447. mouseFlag |= MouseFlags.Button1Released;
  448. }
  449. if ((me.ButtonState & MouseButtonState.Button1Clicked) != 0)
  450. {
  451. mouseFlag |= MouseFlags.Button1Clicked;
  452. }
  453. if ((me.ButtonState & MouseButtonState.Button1DoubleClicked) != 0)
  454. {
  455. mouseFlag |= MouseFlags.Button1DoubleClicked;
  456. }
  457. if ((me.ButtonState & MouseButtonState.Button1TripleClicked) != 0)
  458. {
  459. mouseFlag |= MouseFlags.Button1TripleClicked;
  460. }
  461. if ((me.ButtonState & MouseButtonState.Button2Pressed) != 0)
  462. {
  463. mouseFlag |= MouseFlags.Button2Pressed;
  464. }
  465. if ((me.ButtonState & MouseButtonState.Button2Released) != 0)
  466. {
  467. mouseFlag |= MouseFlags.Button2Released;
  468. }
  469. if ((me.ButtonState & MouseButtonState.Button2Clicked) != 0)
  470. {
  471. mouseFlag |= MouseFlags.Button2Clicked;
  472. }
  473. if ((me.ButtonState & MouseButtonState.Button2DoubleClicked) != 0)
  474. {
  475. mouseFlag |= MouseFlags.Button2DoubleClicked;
  476. }
  477. if ((me.ButtonState & MouseButtonState.Button2TripleClicked) != 0)
  478. {
  479. mouseFlag |= MouseFlags.Button2TripleClicked;
  480. }
  481. if ((me.ButtonState & MouseButtonState.Button3Pressed) != 0)
  482. {
  483. mouseFlag |= MouseFlags.Button3Pressed;
  484. }
  485. if ((me.ButtonState & MouseButtonState.Button3Released) != 0)
  486. {
  487. mouseFlag |= MouseFlags.Button3Released;
  488. }
  489. if ((me.ButtonState & MouseButtonState.Button3Clicked) != 0)
  490. {
  491. mouseFlag |= MouseFlags.Button3Clicked;
  492. }
  493. if ((me.ButtonState & MouseButtonState.Button3DoubleClicked) != 0)
  494. {
  495. mouseFlag |= MouseFlags.Button3DoubleClicked;
  496. }
  497. if ((me.ButtonState & MouseButtonState.Button3TripleClicked) != 0)
  498. {
  499. mouseFlag |= MouseFlags.Button3TripleClicked;
  500. }
  501. if ((me.ButtonState & MouseButtonState.ButtonWheeledUp) != 0)
  502. {
  503. mouseFlag |= MouseFlags.WheeledUp;
  504. }
  505. if ((me.ButtonState & MouseButtonState.ButtonWheeledDown) != 0)
  506. {
  507. mouseFlag |= MouseFlags.WheeledDown;
  508. }
  509. if ((me.ButtonState & MouseButtonState.ButtonWheeledLeft) != 0)
  510. {
  511. mouseFlag |= MouseFlags.WheeledLeft;
  512. }
  513. if ((me.ButtonState & MouseButtonState.ButtonWheeledRight) != 0)
  514. {
  515. mouseFlag |= MouseFlags.WheeledRight;
  516. }
  517. if ((me.ButtonState & MouseButtonState.Button4Pressed) != 0)
  518. {
  519. mouseFlag |= MouseFlags.Button4Pressed;
  520. }
  521. if ((me.ButtonState & MouseButtonState.Button4Released) != 0)
  522. {
  523. mouseFlag |= MouseFlags.Button4Released;
  524. }
  525. if ((me.ButtonState & MouseButtonState.Button4Clicked) != 0)
  526. {
  527. mouseFlag |= MouseFlags.Button4Clicked;
  528. }
  529. if ((me.ButtonState & MouseButtonState.Button4DoubleClicked) != 0)
  530. {
  531. mouseFlag |= MouseFlags.Button4DoubleClicked;
  532. }
  533. if ((me.ButtonState & MouseButtonState.Button4TripleClicked) != 0)
  534. {
  535. mouseFlag |= MouseFlags.Button4TripleClicked;
  536. }
  537. if ((me.ButtonState & MouseButtonState.ReportMousePosition) != 0)
  538. {
  539. mouseFlag |= MouseFlags.ReportMousePosition;
  540. }
  541. if ((me.ButtonState & MouseButtonState.ButtonShift) != 0)
  542. {
  543. mouseFlag |= MouseFlags.ButtonShift;
  544. }
  545. if ((me.ButtonState & MouseButtonState.ButtonCtrl) != 0)
  546. {
  547. mouseFlag |= MouseFlags.ButtonCtrl;
  548. }
  549. if ((me.ButtonState & MouseButtonState.ButtonAlt) != 0)
  550. {
  551. mouseFlag |= MouseFlags.ButtonAlt;
  552. }
  553. return new() { Position = me.Position, Flags = mouseFlag };
  554. }
  555. #endregion Mouse Handling
  556. #region Keyboard Handling
  557. //private ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
  558. //{
  559. // if (consoleKeyInfo.Key != ConsoleKey.Packet)
  560. // {
  561. // return consoleKeyInfo;
  562. // }
  563. // ConsoleModifiers mod = consoleKeyInfo.Modifiers;
  564. // bool shift = (mod & ConsoleModifiers.Shift) != 0;
  565. // bool alt = (mod & ConsoleModifiers.Alt) != 0;
  566. // bool control = (mod & ConsoleModifiers.Control) != 0;
  567. // ConsoleKeyInfo cKeyInfo = DecodeVKPacketToKConsoleKeyInfo (consoleKeyInfo);
  568. // return new (cKeyInfo.KeyChar, cKeyInfo.Key, shift, alt, control);
  569. //}
  570. #endregion Keyboard Handling
  571. #region Low-Level DotNet tuff
  572. /// <inheritdoc/>
  573. public override void WriteRaw (string ansi)
  574. {
  575. Console.Out.Write (ansi);
  576. Console.Out.Flush ();
  577. }
  578. private volatile bool _winSizeChanging;
  579. private void SetWindowPosition (int col, int row)
  580. {
  581. if (!RunningUnitTests)
  582. {
  583. Top = Console.WindowTop;
  584. Left = Console.WindowLeft;
  585. }
  586. else
  587. {
  588. Top = row;
  589. Left = col;
  590. }
  591. }
  592. public virtual void ResizeScreen ()
  593. {
  594. // CONCURRENCY: Unsynchronized access to Clip is not safe.
  595. Clip = new (Screen);
  596. }
  597. #endregion Low-Level DotNet tuff
  598. }