ConsoleDriver.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. //
  2. // ConsoleDriver.cs: Base class for Terminal.Gui ConsoleDriver implementations.
  3. //
  4. using System.Text;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using static Terminal.Gui.ColorScheme;
  9. using System.Linq;
  10. using System.Data;
  11. namespace Terminal.Gui;
  12. /// <summary>
  13. /// Base class for Terminal.Gui ConsoleDriver implementations.
  14. /// </summary>
  15. /// <remarks>
  16. /// There are currently four implementations:
  17. /// - <see cref="CursesDriver"/> (for Unix and Mac)
  18. /// - <see cref="WindowsDriver"/>
  19. /// - <see cref="NetDriver"/> that uses the .NET Console API
  20. /// - <see cref="FakeConsole"/> for unit testing.
  21. /// </remarks>
  22. public abstract class ConsoleDriver {
  23. /// <summary>
  24. /// Set this to true in any unit tests that attempt to test drivers other than FakeDriver.
  25. /// <code>
  26. /// public ColorTests ()
  27. /// {
  28. /// ConsoleDriver.RunningUnitTests = true;
  29. /// }
  30. /// </code>
  31. /// </summary>
  32. internal static bool RunningUnitTests { get; set; }
  33. #region Setup & Teardown
  34. /// <summary>
  35. /// Initializes the driver
  36. /// </summary>
  37. /// <returns>Returns an instance of <see cref="MainLoop"/> using the <see cref="IMainLoopDriver"/> for the driver.</returns>
  38. internal abstract MainLoop Init ();
  39. /// <summary>
  40. /// Ends the execution of the console driver.
  41. /// </summary>
  42. internal abstract void End ();
  43. #endregion
  44. /// <summary>
  45. /// The event fired when the terminal is resized.
  46. /// </summary>
  47. public event EventHandler<SizeChangedEventArgs> SizeChanged;
  48. /// <summary>
  49. /// Called when the terminal size changes. Fires the <see cref="SizeChanged"/> event.
  50. /// </summary>
  51. /// <param name="args"></param>
  52. public void OnSizeChanged (SizeChangedEventArgs args) => SizeChanged?.Invoke (this, args);
  53. /// <summary>
  54. /// The number of columns visible in the terminal.
  55. /// </summary>
  56. public virtual int Cols { get; internal set; }
  57. /// <summary>
  58. /// The number of rows visible in the terminal.
  59. /// </summary>
  60. public virtual int Rows { get; internal set; }
  61. /// <summary>
  62. /// The leftmost column in the terminal.
  63. /// </summary>
  64. public virtual int Left { get; internal set; } = 0;
  65. /// <summary>
  66. /// The topmost row in the terminal.
  67. /// </summary>
  68. public virtual int Top { get; internal set; } = 0;
  69. /// <summary>
  70. /// Get the operating system clipboard.
  71. /// </summary>
  72. public IClipboard Clipboard { get; internal set; }
  73. /// <summary>
  74. /// The contents of the application output. The driver outputs this buffer to the terminal when <see cref="UpdateScreen"/>
  75. /// is called.
  76. /// <remarks>
  77. /// The format of the array is rows, columns, and 3 values on the last column: Rune, Attribute and Dirty Flag
  78. /// </remarks>
  79. /// </summary>
  80. //public int [,,] Contents { get; internal set; }
  81. ///// <summary>
  82. ///// The contents of the application output. The driver outputs this buffer to the terminal when <see cref="UpdateScreen"/>
  83. ///// is called.
  84. ///// <remarks>
  85. ///// The format of the array is rows, columns. The first index is the row, the second index is the column.
  86. ///// </remarks>
  87. ///// </summary>
  88. public Cell [,] Contents { get; internal set; }
  89. /// <summary>
  90. /// Gets the column last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/>
  91. /// are used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
  92. /// </summary>
  93. public int Col { get; internal set; }
  94. /// <summary>
  95. /// Gets the row last set by <see cref="Move"/>. <see cref="Col"/> and <see cref="Row"/>
  96. /// are used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
  97. /// </summary>
  98. public int Row { get; internal set; }
  99. /// <summary>
  100. /// Updates <see cref="Col"/> and <see cref="Row"/> to the specified column and row in <see cref="Contents"/>.
  101. /// Used by <see cref="AddRune(Rune)"/> and <see cref="AddStr"/> to determine where to add content.
  102. /// </summary>
  103. /// <remarks>
  104. /// <para>
  105. /// This does not move the cursor on the screen, it only updates the internal state of the driver.
  106. /// </para>
  107. /// <para>
  108. /// If <paramref name="col"/> or <paramref name="row"/> are negative or beyond <see cref="Cols"/> and <see cref="Rows"/>,
  109. /// the method still sets those properties.
  110. /// </para>
  111. /// </remarks>
  112. /// <param name="col">Column to move to.</param>
  113. /// <param name="row">Row to move to.</param>
  114. public virtual void Move (int col, int row)
  115. {
  116. Col = col;
  117. Row = row;
  118. }
  119. /// <summary>
  120. /// Tests if the specified rune is supported by the driver.
  121. /// </summary>
  122. /// <param name="rune"></param>
  123. /// <returns><see langword="true"/> if the rune can be properly presented; <see langword="false"/> if the driver
  124. /// does not support displaying this rune.</returns>
  125. public virtual bool IsRuneSupported (Rune rune)
  126. {
  127. return Rune.IsValid (rune.Value);
  128. }
  129. /// <summary>
  130. /// Adds the specified rune to the display at the current cursor position.
  131. /// </summary>
  132. /// <remarks>
  133. /// <para>
  134. /// When the method returns, <see cref="Col"/> will be incremented by the number of columns <paramref name="rune"/> required,
  135. /// even if the new column value is outside of the <see cref="Clip"/> or screen dimensions defined by <see cref="Cols"/>.
  136. /// </para>
  137. /// <para>
  138. /// If <paramref name="rune"/> requires more than one column, and <see cref="Col"/> plus the number of columns needed
  139. /// exceeds the <see cref="Clip"/> or screen dimensions, the default Unicode replacement character (U+FFFD) will be added instead.
  140. /// </para>
  141. /// </remarks>
  142. /// <param name="rune">Rune to add.</param>
  143. public void AddRune (Rune rune)
  144. {
  145. int runeWidth = -1;
  146. var validLocation = IsValidLocation (Col, Row);
  147. if (validLocation) {
  148. rune = rune.MakePrintable ();
  149. runeWidth = rune.GetColumns ();
  150. if (runeWidth == 0 && rune.IsCombiningMark ()) {
  151. if (Col > 0) {
  152. if (Contents [Row, Col - 1].CombiningMarks.Count > 0) {
  153. // Just add this mark to the list
  154. Contents [Row, Col - 1].CombiningMarks.Add (rune);
  155. // Don't move to next column (let the driver figure out what to do).
  156. } else {
  157. // Attempt to normalize the cell to our left combined with this mark
  158. string combined = Contents [Row, Col - 1].Rune + rune.ToString ();
  159. // Normalize to Form C (Canonical Composition)
  160. string normalized = combined.Normalize (NormalizationForm.FormC);
  161. if (normalized.Length == 1) {
  162. // It normalized! We can just set the Cell to the left with the
  163. // normalized codepoint
  164. Contents [Row, Col - 1].Rune = (Rune)normalized [0];
  165. // Don't move to next column because we're already there
  166. } else {
  167. // It didn't normalize. Add it to the Cell to left's CM list
  168. Contents [Row, Col - 1].CombiningMarks.Add (rune);
  169. // Don't move to next column (let the driver figure out what to do).
  170. }
  171. }
  172. Contents [Row, Col - 1].Attribute = CurrentAttribute;
  173. Contents [Row, Col - 1].IsDirty = true;
  174. } else {
  175. // Most drivers will render a combining mark at col 0 as the mark
  176. Contents [Row, Col].Rune = rune;
  177. Contents [Row, Col].Attribute = CurrentAttribute;
  178. Contents [Row, Col].IsDirty = true;
  179. Col++;
  180. }
  181. } else {
  182. Contents [Row, Col].Attribute = CurrentAttribute;
  183. Contents [Row, Col].IsDirty = true;
  184. if (Col > 0) {
  185. // Check if cell to left has a wide glyph
  186. if (Contents [Row, Col - 1].Rune.GetColumns () > 1) {
  187. // Invalidate cell to left
  188. Contents [Row, Col - 1].Rune = Rune.ReplacementChar;
  189. Contents [Row, Col - 1].IsDirty = true;
  190. }
  191. }
  192. if (runeWidth < 1) {
  193. Contents [Row, Col].Rune = Rune.ReplacementChar;
  194. } else if (runeWidth == 1) {
  195. Contents [Row, Col].Rune = rune;
  196. if (Col < Clip.Right - 1) {
  197. Contents [Row, Col + 1].IsDirty = true;
  198. }
  199. } else if (runeWidth == 2) {
  200. if (Col == Clip.Right - 1) {
  201. // We're at the right edge of the clip, so we can't display a wide character.
  202. // TODO: Figure out if it is better to show a replacement character or ' '
  203. Contents [Row, Col].Rune = Rune.ReplacementChar;
  204. } else {
  205. Contents [Row, Col].Rune = rune;
  206. if (Col < Clip.Right - 1) {
  207. // Invalidate cell to right so that it doesn't get drawn
  208. // TODO: Figure out if it is better to show a replacement character or ' '
  209. Contents [Row, Col + 1].Rune = Rune.ReplacementChar;
  210. Contents [Row, Col + 1].IsDirty = true;
  211. }
  212. }
  213. } else {
  214. // This is a non-spacing character, so we don't need to do anything
  215. Contents [Row, Col].Rune = (Rune)' ';
  216. Contents [Row, Col].IsDirty = false;
  217. }
  218. _dirtyLines [Row] = true;
  219. }
  220. }
  221. if (runeWidth is < 0 or > 0) {
  222. Col++;
  223. }
  224. if (runeWidth > 1) {
  225. Debug.Assert (runeWidth <= 2);
  226. if (validLocation && Col < Clip.Right) {
  227. // This is a double-width character, and we are not at the end of the line.
  228. // Col now points to the second column of the character. Ensure it doesn't
  229. // Get rendered.
  230. Contents [Row, Col].IsDirty = false;
  231. Contents [Row, Col].Attribute = CurrentAttribute;
  232. // TODO: Determine if we should wipe this out (for now now)
  233. //Contents [Row, Col].Rune = (Rune)' ';
  234. }
  235. Col++;
  236. }
  237. }
  238. /// <summary>
  239. /// Adds the specified <see langword="char"/> to the display at the current cursor position. This method
  240. /// is a convenience method that calls <see cref="AddRune(Rune)"/> with the <see cref="Rune"/> constructor.
  241. /// </summary>
  242. /// <param name="c">Character to add.</param>
  243. public void AddRune (char c) => AddRune (new Rune (c));
  244. /// <summary>
  245. /// Adds the <paramref name="str"/> to the display at the cursor position.
  246. /// </summary>
  247. /// <remarks>
  248. /// <para>
  249. /// When the method returns, <see cref="Col"/> will be incremented by the number of columns <paramref name="str"/> required,
  250. /// unless the new column value is outside of the <see cref="Clip"/> or screen dimensions defined by <see cref="Cols"/>.
  251. /// </para>
  252. /// <para>
  253. /// If <paramref name="str"/> requires more columns than are available, the output will be clipped.
  254. /// </para>
  255. /// </remarks>
  256. /// <param name="str">String.</param>
  257. public void AddStr (string str)
  258. {
  259. var runes = str.EnumerateRunes ().ToList ();
  260. for (var i = 0; i < runes.Count; i++) {
  261. //if (runes [i].IsCombiningMark()) {
  262. // // Attempt to normalize
  263. // string combined = runes [i-1] + runes [i].ToString();
  264. // // Normalize to Form C (Canonical Composition)
  265. // string normalized = combined.Normalize (NormalizationForm.FormC);
  266. // runes [i-]
  267. //}
  268. AddRune (runes [i]);
  269. }
  270. }
  271. Rect _clip;
  272. /// <summary>
  273. /// Tests whether the specified coordinate are valid for drawing.
  274. /// </summary>
  275. /// <param name="col">The column.</param>
  276. /// <param name="row">The row.</param>
  277. /// <returns><see langword="false"/> if the coordinate is outside of the
  278. /// screen bounds or outside of <see cref="Clip"/>. <see langword="true"/> otherwise.</returns>
  279. public bool IsValidLocation (int col, int row) =>
  280. col >= 0 && row >= 0 &&
  281. col < Cols && row < Rows &&
  282. Clip.Contains (col, row);
  283. /// <summary>
  284. /// Gets or sets the clip rectangle that <see cref="AddRune(Rune)"/> and <see cref="AddStr(string)"/> are
  285. /// subject to.
  286. /// </summary>
  287. /// <value>The rectangle describing the bounds of <see cref="Clip"/>.</value>
  288. public Rect Clip {
  289. get => _clip;
  290. set => _clip = value;
  291. }
  292. /// <summary>
  293. /// Updates the screen to reflect all the changes that have been done to the display buffer
  294. /// </summary>
  295. public abstract void Refresh ();
  296. /// <summary>
  297. /// Sets the position of the terminal cursor to <see cref="Col"/> and <see cref="Row"/>.
  298. /// </summary>
  299. public abstract void UpdateCursor ();
  300. /// <summary>
  301. /// Gets the terminal cursor visibility.
  302. /// </summary>
  303. /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
  304. /// <returns><see langword="true"/> upon success</returns>
  305. public abstract bool GetCursorVisibility (out CursorVisibility visibility);
  306. /// <summary>
  307. /// Sets the terminal cursor visibility.
  308. /// </summary>
  309. /// <param name="visibility">The wished <see cref="CursorVisibility"/></param>
  310. /// <returns><see langword="true"/> upon success</returns>
  311. public abstract bool SetCursorVisibility (CursorVisibility visibility);
  312. /// <summary>
  313. /// Determines if the terminal cursor should be visible or not and sets it accordingly.
  314. /// </summary>
  315. /// <returns><see langword="true"/> upon success</returns>
  316. public abstract bool EnsureCursorVisibility ();
  317. // As performance is a concern, we keep track of the dirty lines and only refresh those.
  318. // This is in addition to the dirty flag on each cell.
  319. internal bool [] _dirtyLines;
  320. /// <summary>
  321. /// Clears the <see cref="Contents"/> of the driver.
  322. /// </summary>
  323. public void ClearContents ()
  324. {
  325. // TODO: This method is really "Clear Contents" now and should not be abstract (or virtual)
  326. Contents = new Cell [Rows, Cols];
  327. Clip = new Rect (0, 0, Cols, Rows);
  328. _dirtyLines = new bool [Rows];
  329. lock (Contents) {
  330. // Can raise an exception while is still resizing.
  331. try {
  332. for (var row = 0; row < Rows; row++) {
  333. for (var c = 0; c < Cols; c++) {
  334. Contents [row, c] = new Cell () {
  335. Rune = (Rune)' ',
  336. Attribute = new Attribute (Color.White, Color.Black),
  337. IsDirty = true
  338. };
  339. _dirtyLines [row] = true;
  340. }
  341. }
  342. } catch (IndexOutOfRangeException) { }
  343. }
  344. }
  345. /// <summary>
  346. /// Redraws the physical screen with the contents that have been queued up via any of the printing commands.
  347. /// </summary>
  348. public abstract void UpdateScreen ();
  349. #region Color Handling
  350. /// <summary>
  351. /// Gets whether the <see cref="ConsoleDriver"/> supports TrueColor output.
  352. /// </summary>
  353. public virtual bool SupportsTrueColor { get => true; }
  354. /// <summary>
  355. /// Gets or sets whether the <see cref="ConsoleDriver"/> should use 16 colors instead of the default TrueColors. See <see cref="Application.Force16Colors"/>
  356. /// to change this setting via <see cref="ConfigurationManager"/>.
  357. /// </summary>
  358. /// <remarks>
  359. /// <para>
  360. /// Will be forced to <see langword="true"/> if <see cref="ConsoleDriver.SupportsTrueColor"/> is <see langword="false"/>, indicating
  361. /// that the <see cref="ConsoleDriver"/> cannot support TrueColor.
  362. /// </para>
  363. /// </remarks>
  364. internal virtual bool Force16Colors {
  365. get => Application.Force16Colors || !SupportsTrueColor;
  366. set => Application.Force16Colors = (value || !SupportsTrueColor);
  367. }
  368. Attribute _currentAttribute;
  369. /// <summary>
  370. /// The <see cref="Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/> call.
  371. /// </summary>
  372. public Attribute CurrentAttribute {
  373. get => _currentAttribute;
  374. set {
  375. if (Application.Driver != null) {
  376. _currentAttribute = new Attribute (value.Foreground, value.Background);
  377. return;
  378. }
  379. _currentAttribute = value;
  380. }
  381. }
  382. /// <summary>
  383. /// Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.
  384. /// </summary>
  385. /// <remarks>
  386. /// Implementations should call <c>base.SetAttribute(c)</c>.
  387. /// </remarks>
  388. /// <param name="c">C.</param>
  389. public Attribute SetAttribute (Attribute c)
  390. {
  391. var prevAttribute = CurrentAttribute;
  392. CurrentAttribute = c;
  393. return prevAttribute;
  394. }
  395. /// <summary>
  396. /// Gets the current <see cref="Attribute"/>.
  397. /// </summary>
  398. /// <returns>The current attribute.</returns>
  399. public Attribute GetAttribute () => CurrentAttribute;
  400. // TODO: This is only overridden by CursesDriver. Once CursesDriver supports 24-bit color, this virtual method can be
  401. // removed (and Attribute can lose the platformColor property).
  402. /// <summary>
  403. /// Makes an <see cref="Attribute"/>.
  404. /// </summary>
  405. /// <param name="foreground">The foreground color.</param>
  406. /// <param name="background">The background color.</param>
  407. /// <returns>The attribute for the foreground and background colors.</returns>
  408. public virtual Attribute MakeColor (Color foreground, Color background)
  409. {
  410. // Encode the colors into the int value.
  411. return new Attribute (
  412. platformColor: 0, // only used by cursesdriver!
  413. foreground: foreground,
  414. background: background
  415. );
  416. }
  417. #endregion
  418. #region Mouse and Keyboard
  419. /// <summary>
  420. /// Event fired after a key has been pressed and released.
  421. /// </summary>
  422. public event EventHandler<KeyEventEventArgs> KeyPressed;
  423. /// <summary>
  424. /// Called after a key has been pressed and released. Fires the <see cref="KeyPressed"/> event.
  425. /// </summary>
  426. /// <param name="a"></param>
  427. public void OnKeyPressed (KeyEventEventArgs a) => KeyPressed?.Invoke (this, a);
  428. /// <summary>
  429. /// Event fired when a key is released.
  430. /// </summary>
  431. public event EventHandler<KeyEventEventArgs> KeyUp;
  432. /// <summary>
  433. /// Called when a key is released. Fires the <see cref="KeyUp"/> event.
  434. /// </summary>
  435. /// <param name="a"></param>
  436. public void OnKeyUp (KeyEventEventArgs a) => KeyUp?.Invoke (this, a);
  437. /// <summary>
  438. /// Event fired when a key is pressed.
  439. /// </summary>
  440. public event EventHandler<KeyEventEventArgs> KeyDown;
  441. /// <summary>
  442. /// Called when a key is pressed. Fires the <see cref="KeyDown"/> event.
  443. /// </summary>
  444. /// <param name="a"></param>
  445. public void OnKeyDown (KeyEventEventArgs a) => KeyDown?.Invoke (this, a);
  446. /// <summary>
  447. /// Event fired when a mouse event occurs.
  448. /// </summary>
  449. public event EventHandler<MouseEventEventArgs> MouseEvent;
  450. /// <summary>
  451. /// Called when a mouse event occurs. Fires the <see cref="MouseEvent"/> event.
  452. /// </summary>
  453. /// <param name="a"></param>
  454. public void OnMouseEvent (MouseEventEventArgs a) => MouseEvent?.Invoke (this, a);
  455. /// <summary>
  456. /// Simulates a key press.
  457. /// </summary>
  458. /// <param name="keyChar">The key character.</param>
  459. /// <param name="key">The key.</param>
  460. /// <param name="shift">If <see langword="true"/> simulates the Shift key being pressed.</param>
  461. /// <param name="alt">If <see langword="true"/> simulates the Alt key being pressed.</param>
  462. /// <param name="ctrl">If <see langword="true"/> simulates the Ctrl key being pressed.</param>
  463. public abstract void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl);
  464. #endregion
  465. /// <summary>
  466. /// Enables diagnostic functions
  467. /// </summary>
  468. [Flags]
  469. public enum DiagnosticFlags : uint {
  470. /// <summary>
  471. /// All diagnostics off
  472. /// </summary>
  473. Off = 0b_0000_0000,
  474. /// <summary>
  475. /// When enabled, <see cref="Frame.OnDrawFrames"/> will draw a
  476. /// ruler in the frame for any side with a padding value greater than 0.
  477. /// </summary>
  478. FrameRuler = 0b_0000_0001,
  479. /// <summary>
  480. /// When enabled, <see cref="Frame.OnDrawFrames"/> will draw a
  481. /// 'L', 'R', 'T', and 'B' when clearing <see cref="Thickness"/>'s instead of ' '.
  482. /// </summary>
  483. FramePadding = 0b_0000_0010,
  484. }
  485. /// <summary>
  486. /// Set flags to enable/disable <see cref="ConsoleDriver"/> diagnostics.
  487. /// </summary>
  488. public static DiagnosticFlags Diagnostics { get; set; }
  489. /// <summary>
  490. /// Suspends the application (e.g. on Linux via SIGTSTP) and upon resume, resets the console driver.
  491. /// </summary>
  492. /// <remarks>This is only implemented in <see cref="CursesDriver"/>.</remarks>
  493. public abstract void Suspend ();
  494. // TODO: Move FillRect to ./Drawing
  495. /// <summary>
  496. /// Fills the specified rectangle with the specified rune.
  497. /// </summary>
  498. /// <param name="rect"></param>
  499. /// <param name="rune"></param>
  500. public void FillRect (Rect rect, Rune rune = default)
  501. {
  502. for (var r = rect.Y; r < rect.Y + rect.Height; r++) {
  503. for (var c = rect.X; c < rect.X + rect.Width; c++) {
  504. Application.Driver.Move (c, r);
  505. Application.Driver.AddRune (rune == default ? new Rune (' ') : rune);
  506. }
  507. }
  508. }
  509. /// <summary>
  510. /// Fills the specified rectangle with the specified <see langword="char"/>. This method
  511. /// is a convenience method that calls <see cref="FillRect(Rect, Rune)"/>.
  512. /// </summary>
  513. /// <param name="rect"></param>
  514. /// <param name="c"></param>
  515. public void FillRect (Rect rect, char c) => FillRect (rect, new Rune (c));
  516. /// <summary>
  517. /// Returns the name of the driver and relevant library version information.
  518. /// </summary>
  519. /// <returns></returns>
  520. public virtual string GetVersionInfo () => GetType ().Name;
  521. }
  522. /// <summary>
  523. /// Terminal Cursor Visibility settings.
  524. /// </summary>
  525. /// <remarks>
  526. /// Hex value are set as 0xAABBCCDD where :
  527. ///
  528. /// AA stand for the TERMINFO DECSUSR parameter value to be used under Linux and MacOS
  529. /// BB stand for the NCurses curs_set parameter value to be used under Linux and MacOS
  530. /// CC stand for the CONSOLE_CURSOR_INFO.bVisible parameter value to be used under Windows
  531. /// DD stand for the CONSOLE_CURSOR_INFO.dwSize parameter value to be used under Windows
  532. ///</remarks>
  533. public enum CursorVisibility {
  534. /// <summary>
  535. /// Cursor caret has default
  536. /// </summary>
  537. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Underscore"/>. This default directly depends of the XTerm user configuration settings so it could be Block, I-Beam, Underline with possible blinking.</remarks>
  538. Default = 0x00010119,
  539. /// <summary>
  540. /// Cursor caret is hidden
  541. /// </summary>
  542. Invisible = 0x03000019,
  543. /// <summary>
  544. /// Cursor caret is normally shown as a blinking underline bar _
  545. /// </summary>
  546. Underline = 0x03010119,
  547. /// <summary>
  548. /// Cursor caret is normally shown as a underline bar _
  549. /// </summary>
  550. /// <remarks>Under Windows, this is equivalent to <see ref="UnderscoreBlinking"/></remarks>
  551. UnderlineFix = 0x04010119,
  552. /// <summary>
  553. /// Cursor caret is displayed a blinking vertical bar |
  554. /// </summary>
  555. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Underscore"/></remarks>
  556. Vertical = 0x05010119,
  557. /// <summary>
  558. /// Cursor caret is displayed a blinking vertical bar |
  559. /// </summary>
  560. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Underscore"/></remarks>
  561. VerticalFix = 0x06010119,
  562. /// <summary>
  563. /// Cursor caret is displayed as a blinking block ▉
  564. /// </summary>
  565. Box = 0x01020164,
  566. /// <summary>
  567. /// Cursor caret is displayed a block ▉
  568. /// </summary>
  569. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Block"/></remarks>
  570. BoxFix = 0x02020164,
  571. }