ConsoleDriver.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. //
  2. // ConsoleDriver.cs: Definition for the Console Driver API
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // Define this to enable diagnostics drawing for Window Frames
  8. using NStack;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Runtime.CompilerServices;
  13. namespace Terminal.Gui {
  14. /// <summary>
  15. /// Basic colors that can be used to set the foreground and background colors in console applications.
  16. /// </summary>
  17. public enum Color {
  18. /// <summary>
  19. /// The black color.
  20. /// </summary>
  21. Black,
  22. /// <summary>
  23. /// The blue color.
  24. /// </summary>
  25. Blue,
  26. /// <summary>
  27. /// The green color.
  28. /// </summary>
  29. Green,
  30. /// <summary>
  31. /// The cyan color.
  32. /// </summary>
  33. Cyan,
  34. /// <summary>
  35. /// The red color.
  36. /// </summary>
  37. Red,
  38. /// <summary>
  39. /// The magenta color.
  40. /// </summary>
  41. Magenta,
  42. /// <summary>
  43. /// The brown color.
  44. /// </summary>
  45. Brown,
  46. /// <summary>
  47. /// The gray color.
  48. /// </summary>
  49. Gray,
  50. /// <summary>
  51. /// The dark gray color.
  52. /// </summary>
  53. DarkGray,
  54. /// <summary>
  55. /// The bright bBlue color.
  56. /// </summary>
  57. BrightBlue,
  58. /// <summary>
  59. /// The bright green color.
  60. /// </summary>
  61. BrightGreen,
  62. /// <summary>
  63. /// The bright cyan color.
  64. /// </summary>
  65. BrightCyan,
  66. /// <summary>
  67. /// The bright red color.
  68. /// </summary>
  69. BrightRed,
  70. /// <summary>
  71. /// The bright magenta color.
  72. /// </summary>
  73. BrightMagenta,
  74. /// <summary>
  75. /// The bright yellow color.
  76. /// </summary>
  77. BrightYellow,
  78. /// <summary>
  79. /// The White color.
  80. /// </summary>
  81. White
  82. }
  83. /// <summary>
  84. /// Attributes are used as elements that contain both a foreground and a background or platform specific features
  85. /// </summary>
  86. /// <remarks>
  87. /// <see cref="Attribute"/>s are needed to map colors to terminal capabilities that might lack colors, on color
  88. /// scenarios, they encode both the foreground and the background color and are used in the <see cref="ColorScheme"/>
  89. /// class to define color schemes that can be used in your application.
  90. /// </remarks>
  91. public struct Attribute {
  92. /// <summary>
  93. /// The color attribute value.
  94. /// </summary>
  95. public int Value { get; }
  96. /// <summary>
  97. /// The foreground color.
  98. /// </summary>
  99. public Color Foreground { get; }
  100. /// <summary>
  101. /// The background color.
  102. /// </summary>
  103. public Color Background { get; }
  104. /// <summary>
  105. /// Initializes a new instance of the <see cref="Attribute"/> struct with only the value passed to
  106. /// and trying to get the colors if defined.
  107. /// </summary>
  108. /// <param name="value">Value.</param>
  109. public Attribute (int value)
  110. {
  111. Color foreground = default;
  112. Color background = default;
  113. if (Application.Driver != null) {
  114. Application.Driver.GetColors (value, out foreground, out background);
  115. }
  116. Value = value;
  117. Foreground = foreground;
  118. Background = background;
  119. }
  120. /// <summary>
  121. /// Initializes a new instance of the <see cref="Attribute"/> struct.
  122. /// </summary>
  123. /// <param name="value">Value.</param>
  124. /// <param name="foreground">Foreground</param>
  125. /// <param name="background">Background</param>
  126. public Attribute (int value, Color foreground, Color background)
  127. {
  128. Value = value;
  129. Foreground = foreground;
  130. Background = background;
  131. }
  132. /// <summary>
  133. /// Initializes a new instance of the <see cref="Attribute"/> struct.
  134. /// </summary>
  135. /// <param name="foreground">Foreground</param>
  136. /// <param name="background">Background</param>
  137. public Attribute (Color foreground = new Color (), Color background = new Color ())
  138. {
  139. Value = Make (foreground, background).Value;
  140. Foreground = foreground;
  141. Background = background;
  142. }
  143. /// <summary>
  144. /// Initializes a new instance of the <see cref="Attribute"/> struct
  145. /// with the same colors for the foreground and background.
  146. /// </summary>
  147. /// <param name="color">The color.</param>
  148. public Attribute (Color color) : this (color, color) { }
  149. /// <summary>
  150. /// Implicit conversion from an <see cref="Attribute"/> to the underlying Int32 representation
  151. /// </summary>
  152. /// <returns>The integer value stored in the attribute.</returns>
  153. /// <param name="c">The attribute to convert</param>
  154. public static implicit operator int (Attribute c) => c.Value;
  155. /// <summary>
  156. /// Implicitly convert an integer value into an <see cref="Attribute"/>
  157. /// </summary>
  158. /// <returns>An attribute with the specified integer value.</returns>
  159. /// <param name="v">value</param>
  160. public static implicit operator Attribute (int v) => new Attribute (v);
  161. /// <summary>
  162. /// Creates an <see cref="Attribute"/> from the specified foreground and background.
  163. /// </summary>
  164. /// <returns>The make.</returns>
  165. /// <param name="foreground">Foreground color to use.</param>
  166. /// <param name="background">Background color to use.</param>
  167. public static Attribute Make (Color foreground, Color background)
  168. {
  169. if (Application.Driver == null)
  170. throw new InvalidOperationException ("The Application has not been initialized");
  171. return Application.Driver.MakeAttribute (foreground, background);
  172. }
  173. /// <summary>
  174. /// Gets the current <see cref="Attribute"/> from the driver.
  175. /// </summary>
  176. /// <returns>The current attribute.</returns>
  177. public static Attribute Get ()
  178. {
  179. if (Application.Driver == null)
  180. throw new InvalidOperationException ("The Application has not been initialized");
  181. return Application.Driver.GetAttribute ();
  182. }
  183. }
  184. /// <summary>
  185. /// Color scheme definitions, they cover some common scenarios and are used
  186. /// typically in containers such as <see cref="Window"/> and <see cref="FrameView"/> to set the scheme that is used by all the
  187. /// views contained inside.
  188. /// </summary>
  189. public class ColorScheme : IEquatable<ColorScheme> {
  190. Attribute _normal;
  191. Attribute _focus;
  192. Attribute _hotNormal;
  193. Attribute _hotFocus;
  194. Attribute _disabled;
  195. internal string caller = "";
  196. /// <summary>
  197. /// The default color for text, when the view is not focused.
  198. /// </summary>
  199. public Attribute Normal { get { return _normal; } set { _normal = SetAttribute (value); } }
  200. /// <summary>
  201. /// The color for text when the view has the focus.
  202. /// </summary>
  203. public Attribute Focus { get { return _focus; } set { _focus = SetAttribute (value); } }
  204. /// <summary>
  205. /// The color for the hotkey when a view is not focused
  206. /// </summary>
  207. public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetAttribute (value); } }
  208. /// <summary>
  209. /// The color for the hotkey when the view is focused.
  210. /// </summary>
  211. public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetAttribute (value); } }
  212. /// <summary>
  213. /// The default color for text, when the view is disabled.
  214. /// </summary>
  215. public Attribute Disabled { get { return _disabled; } set { _disabled = SetAttribute (value); } }
  216. bool preparingScheme = false;
  217. Attribute SetAttribute (Attribute attribute, [CallerMemberName] string callerMemberName = null)
  218. {
  219. if (!Application._initialized && !preparingScheme)
  220. return attribute;
  221. if (preparingScheme)
  222. return attribute;
  223. preparingScheme = true;
  224. switch (caller) {
  225. case "TopLevel":
  226. switch (callerMemberName) {
  227. case "Normal":
  228. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  229. break;
  230. case "Focus":
  231. HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
  232. break;
  233. case "HotNormal":
  234. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
  235. break;
  236. case "HotFocus":
  237. HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
  238. if (Focus.Foreground != attribute.Background)
  239. Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
  240. break;
  241. }
  242. break;
  243. case "Base":
  244. switch (callerMemberName) {
  245. case "Normal":
  246. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  247. break;
  248. case "Focus":
  249. HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
  250. break;
  251. case "HotNormal":
  252. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
  253. Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
  254. break;
  255. case "HotFocus":
  256. HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
  257. if (Focus.Foreground != attribute.Background)
  258. Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
  259. break;
  260. }
  261. break;
  262. case "Menu":
  263. switch (callerMemberName) {
  264. case "Normal":
  265. if (Focus.Background != attribute.Background)
  266. Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
  267. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  268. Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
  269. break;
  270. case "Focus":
  271. Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
  272. HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
  273. break;
  274. case "HotNormal":
  275. if (Focus.Background != attribute.Background)
  276. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
  277. Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
  278. Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
  279. break;
  280. case "HotFocus":
  281. HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
  282. if (Focus.Foreground != attribute.Background)
  283. Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
  284. break;
  285. case "Disabled":
  286. if (Focus.Background != attribute.Background)
  287. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
  288. Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
  289. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  290. break;
  291. }
  292. break;
  293. case "Dialog":
  294. switch (callerMemberName) {
  295. case "Normal":
  296. if (Focus.Background != attribute.Background)
  297. Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
  298. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  299. break;
  300. case "Focus":
  301. Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
  302. HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
  303. break;
  304. case "HotNormal":
  305. if (Focus.Background != attribute.Background)
  306. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
  307. if (Normal.Foreground != attribute.Background)
  308. Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
  309. break;
  310. case "HotFocus":
  311. HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
  312. if (Focus.Foreground != attribute.Background)
  313. Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
  314. break;
  315. }
  316. break;
  317. case "Error":
  318. switch (callerMemberName) {
  319. case "Normal":
  320. HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
  321. HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
  322. break;
  323. case "HotNormal":
  324. case "HotFocus":
  325. HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, attribute.Background);
  326. Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
  327. break;
  328. }
  329. break;
  330. }
  331. preparingScheme = false;
  332. return attribute;
  333. }
  334. /// <summary>
  335. /// Compares two <see cref="ColorScheme"/> objects for equality.
  336. /// </summary>
  337. /// <param name="obj"></param>
  338. /// <returns>true if the two objects are equal</returns>
  339. public override bool Equals (object obj)
  340. {
  341. return Equals (obj as ColorScheme);
  342. }
  343. /// <summary>
  344. /// Compares two <see cref="ColorScheme"/> objects for equality.
  345. /// </summary>
  346. /// <param name="other"></param>
  347. /// <returns>true if the two objects are equal</returns>
  348. public bool Equals (ColorScheme other)
  349. {
  350. return other != null &&
  351. EqualityComparer<Attribute>.Default.Equals (_normal, other._normal) &&
  352. EqualityComparer<Attribute>.Default.Equals (_focus, other._focus) &&
  353. EqualityComparer<Attribute>.Default.Equals (_hotNormal, other._hotNormal) &&
  354. EqualityComparer<Attribute>.Default.Equals (_hotFocus, other._hotFocus) &&
  355. EqualityComparer<Attribute>.Default.Equals (_disabled, other._disabled);
  356. }
  357. /// <summary>
  358. /// Returns a hashcode for this instance.
  359. /// </summary>
  360. /// <returns>hashcode for this instance</returns>
  361. public override int GetHashCode ()
  362. {
  363. int hashCode = -1242460230;
  364. hashCode = hashCode * -1521134295 + _normal.GetHashCode ();
  365. hashCode = hashCode * -1521134295 + _focus.GetHashCode ();
  366. hashCode = hashCode * -1521134295 + _hotNormal.GetHashCode ();
  367. hashCode = hashCode * -1521134295 + _hotFocus.GetHashCode ();
  368. hashCode = hashCode * -1521134295 + _disabled.GetHashCode ();
  369. return hashCode;
  370. }
  371. /// <summary>
  372. /// Compares two <see cref="ColorScheme"/> objects for equality.
  373. /// </summary>
  374. /// <param name="left"></param>
  375. /// <param name="right"></param>
  376. /// <returns><c>true</c> if the two objects are equivalent</returns>
  377. public static bool operator == (ColorScheme left, ColorScheme right)
  378. {
  379. return EqualityComparer<ColorScheme>.Default.Equals (left, right);
  380. }
  381. /// <summary>
  382. /// Compares two <see cref="ColorScheme"/> objects for inequality.
  383. /// </summary>
  384. /// <param name="left"></param>
  385. /// <param name="right"></param>
  386. /// <returns><c>true</c> if the two objects are not equivalent</returns>
  387. public static bool operator != (ColorScheme left, ColorScheme right)
  388. {
  389. return !(left == right);
  390. }
  391. }
  392. /// <summary>
  393. /// The default <see cref="ColorScheme"/>s for the application.
  394. /// </summary>
  395. public static class Colors {
  396. static Colors ()
  397. {
  398. // Use reflection to dynamically create the default set of ColorSchemes from the list defined
  399. // by the class.
  400. ColorSchemes = typeof (Colors).GetProperties ()
  401. .Where (p => p.PropertyType == typeof (ColorScheme))
  402. .Select (p => new KeyValuePair<string, ColorScheme> (p.Name, new ColorScheme ())) // (ColorScheme)p.GetValue (p)))
  403. .ToDictionary (t => t.Key, t => t.Value);
  404. }
  405. /// <summary>
  406. /// The application toplevel color scheme, for the default toplevel views.
  407. /// </summary>
  408. /// <remarks>
  409. /// <para>
  410. /// This API will be deprecated in the future. Use <see cref="Colors.ColorSchemes"/> instead (e.g. <c>edit.ColorScheme = Colors.ColorSchemes["TopLevel"];</c>
  411. /// </para>
  412. /// </remarks>
  413. public static ColorScheme TopLevel { get => GetColorScheme (); set => SetColorScheme (value); }
  414. /// <summary>
  415. /// The base color scheme, for the default toplevel views.
  416. /// </summary>
  417. /// <remarks>
  418. /// <para>
  419. /// This API will be deprecated in the future. Use <see cref="Colors.ColorSchemes"/> instead (e.g. <c>edit.ColorScheme = Colors.ColorSchemes["Base"];</c>
  420. /// </para>
  421. /// </remarks>
  422. public static ColorScheme Base { get => GetColorScheme (); set => SetColorScheme (value); }
  423. /// <summary>
  424. /// The dialog color scheme, for standard popup dialog boxes
  425. /// </summary>
  426. /// <remarks>
  427. /// <para>
  428. /// This API will be deprecated in the future. Use <see cref="Colors.ColorSchemes"/> instead (e.g. <c>edit.ColorScheme = Colors.ColorSchemes["Dialog"];</c>
  429. /// </para>
  430. /// </remarks>
  431. public static ColorScheme Dialog { get => GetColorScheme (); set => SetColorScheme (value); }
  432. /// <summary>
  433. /// The menu bar color
  434. /// </summary>
  435. /// <remarks>
  436. /// <para>
  437. /// This API will be deprecated in the future. Use <see cref="Colors.ColorSchemes"/> instead (e.g. <c>edit.ColorScheme = Colors.ColorSchemes["Menu"];</c>
  438. /// </para>
  439. /// </remarks>
  440. public static ColorScheme Menu { get => GetColorScheme (); set => SetColorScheme (value); }
  441. /// <summary>
  442. /// The color scheme for showing errors.
  443. /// </summary>
  444. /// <remarks>
  445. /// <para>
  446. /// This API will be deprecated in the future. Use <see cref="Colors.ColorSchemes"/> instead (e.g. <c>edit.ColorScheme = Colors.ColorSchemes["Error"];</c>
  447. /// </para>
  448. /// </remarks>
  449. public static ColorScheme Error { get => GetColorScheme (); set => SetColorScheme (value); }
  450. static ColorScheme GetColorScheme ([CallerMemberName] string callerMemberName = null)
  451. {
  452. return ColorSchemes [callerMemberName];
  453. }
  454. static void SetColorScheme (ColorScheme colorScheme, [CallerMemberName] string callerMemberName = null)
  455. {
  456. ColorSchemes [callerMemberName] = colorScheme;
  457. colorScheme.caller = callerMemberName;
  458. }
  459. /// <summary>
  460. /// Provides the defined <see cref="ColorScheme"/>s.
  461. /// </summary>
  462. public static Dictionary<string, ColorScheme> ColorSchemes { get; }
  463. }
  464. /// <summary>
  465. /// Cursors Visibility that are displayed
  466. /// </summary>
  467. //
  468. // Hexa value are set as 0xAABBCCDD where :
  469. //
  470. // AA stand for the TERMINFO DECSUSR parameter value to be used under Linux & MacOS
  471. // BB stand for the NCurses curs_set parameter value to be used under Linux & MacOS
  472. // CC stand for the CONSOLE_CURSOR_INFO.bVisible parameter value to be used under Windows
  473. // DD stand for the CONSOLE_CURSOR_INFO.dwSize parameter value to be used under Windows
  474. //
  475. public enum CursorVisibility {
  476. /// <summary>
  477. /// Cursor caret has default
  478. /// </summary>
  479. /// <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>
  480. Default = 0x00010119,
  481. /// <summary>
  482. /// Cursor caret is hidden
  483. /// </summary>
  484. Invisible = 0x03000019,
  485. /// <summary>
  486. /// Cursor caret is normally shown as a blinking underline bar _
  487. /// </summary>
  488. Underline = 0x03010119,
  489. /// <summary>
  490. /// Cursor caret is normally shown as a underline bar _
  491. /// </summary>
  492. /// <remarks>Under Windows, this is equivalent to <see ref="UnderscoreBlinking"/></remarks>
  493. UnderlineFix = 0x04010119,
  494. /// <summary>
  495. /// Cursor caret is displayed a blinking vertical bar |
  496. /// </summary>
  497. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Underscore"/></remarks>
  498. Vertical = 0x05010119,
  499. /// <summary>
  500. /// Cursor caret is displayed a blinking vertical bar |
  501. /// </summary>
  502. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Underscore"/></remarks>
  503. VerticalFix = 0x06010119,
  504. /// <summary>
  505. /// Cursor caret is displayed as a blinking block ▉
  506. /// </summary>
  507. Box = 0x01020164,
  508. /// <summary>
  509. /// Cursor caret is displayed a block ▉
  510. /// </summary>
  511. /// <remarks>Works under Xterm-like terminal otherwise this is equivalent to <see ref="Block"/></remarks>
  512. BoxFix = 0x02020164,
  513. }
  514. ///// <summary>
  515. ///// Special characters that can be drawn with
  516. ///// </summary>
  517. //public enum SpecialChar {
  518. // /// <summary>
  519. // /// Horizontal line character.
  520. // /// </summary>
  521. // HLine,
  522. // /// <summary>
  523. // /// Vertical line character.
  524. // /// </summary>
  525. // VLine,
  526. // /// <summary>
  527. // /// Stipple pattern
  528. // /// </summary>
  529. // Stipple,
  530. // /// <summary>
  531. // /// Diamond character
  532. // /// </summary>
  533. // Diamond,
  534. // /// <summary>
  535. // /// Upper left corner
  536. // /// </summary>
  537. // ULCorner,
  538. // /// <summary>
  539. // /// Lower left corner
  540. // /// </summary>
  541. // LLCorner,
  542. // /// <summary>
  543. // /// Upper right corner
  544. // /// </summary>
  545. // URCorner,
  546. // /// <summary>
  547. // /// Lower right corner
  548. // /// </summary>
  549. // LRCorner,
  550. // /// <summary>
  551. // /// Left tee
  552. // /// </summary>
  553. // LeftTee,
  554. // /// <summary>
  555. // /// Right tee
  556. // /// </summary>
  557. // RightTee,
  558. // /// <summary>
  559. // /// Top tee
  560. // /// </summary>
  561. // TopTee,
  562. // /// <summary>
  563. // /// The bottom tee.
  564. // /// </summary>
  565. // BottomTee,
  566. //}
  567. /// <summary>
  568. /// ConsoleDriver is an abstract class that defines the requirements for a console driver.
  569. /// There are currently three implementations: <see cref="CursesDriver"/> (for Unix and Mac), <see cref="WindowsDriver"/>, and <see cref="NetDriver"/> that uses the .NET Console API.
  570. /// </summary>
  571. public abstract class ConsoleDriver {
  572. /// <summary>
  573. /// The handler fired when the terminal is resized.
  574. /// </summary>
  575. protected Action TerminalResized;
  576. /// <summary>
  577. /// The current number of columns in the terminal.
  578. /// </summary>
  579. public abstract int Cols { get; }
  580. /// <summary>
  581. /// The current number of rows in the terminal.
  582. /// </summary>
  583. public abstract int Rows { get; }
  584. /// <summary>
  585. /// The current left in the terminal.
  586. /// </summary>
  587. public abstract int Left { get; }
  588. /// <summary>
  589. /// The current top in the terminal.
  590. /// </summary>
  591. public abstract int Top { get; }
  592. /// <summary>
  593. /// Get the operation system clipboard.
  594. /// </summary>
  595. public abstract IClipboard Clipboard { get; }
  596. /// <summary>
  597. /// If false height is measured by the window height and thus no scrolling.
  598. /// If true then height is measured by the buffer height, enabling scrolling.
  599. /// </summary>
  600. public abstract bool HeightAsBuffer { get; set; }
  601. /// <summary>
  602. /// The format is rows, columns and 3 values on the last column: Rune, Attribute and Dirty Flag
  603. /// </summary>
  604. public virtual int [,,] Contents { get; }
  605. /// <summary>
  606. /// Initializes the driver
  607. /// </summary>
  608. /// <param name="terminalResized">Method to invoke when the terminal is resized.</param>
  609. public abstract void Init (Action terminalResized);
  610. /// <summary>
  611. /// Moves the cursor to the specified column and row.
  612. /// </summary>
  613. /// <param name="col">Column to move the cursor to.</param>
  614. /// <param name="row">Row to move the cursor to.</param>
  615. public abstract void Move (int col, int row);
  616. /// <summary>
  617. /// Adds the specified rune to the display at the current cursor position
  618. /// </summary>
  619. /// <param name="rune">Rune to add.</param>
  620. public abstract void AddRune (Rune rune);
  621. /// <summary>
  622. /// Ensures a Rune is not a control character and can be displayed by translating characters below 0x20
  623. /// to equivalent, printable, Unicode chars.
  624. /// </summary>
  625. /// <param name="c">Rune to translate</param>
  626. /// <returns></returns>
  627. public static Rune MakePrintable (Rune c)
  628. {
  629. var controlChars = c & 0xFFFF;
  630. if (controlChars <= 0x1F || controlChars >= 0X7F && controlChars <= 0x9F) {
  631. // ASCII (C0) control characters.
  632. // C1 control characters (https://www.aivosto.com/articles/control-characters.html#c1)
  633. return new Rune (controlChars + 0x2400);
  634. }
  635. return c;
  636. }
  637. /// <summary>
  638. /// Ensures that the column and line are in a valid range from the size of the driver.
  639. /// </summary>
  640. /// <param name="col">The column.</param>
  641. /// <param name="row">The row.</param>
  642. /// <param name="clip">The clip.</param>
  643. /// <returns><c>true</c>if it's a valid range,<c>false</c>otherwise.</returns>
  644. public bool IsValidContent (int col, int row, Rect clip) =>
  645. col >= 0 && row >= 0 && col < Cols && row < Rows && clip.Contains (col, row);
  646. /// <summary>
  647. /// Adds the specified
  648. /// </summary>
  649. /// <param name="str">String.</param>
  650. public abstract void AddStr (ustring str);
  651. /// <summary>
  652. /// Prepare the driver and set the key and mouse events handlers.
  653. /// </summary>
  654. /// <param name="mainLoop">The main loop.</param>
  655. /// <param name="keyHandler">The handler for ProcessKey</param>
  656. /// <param name="keyDownHandler">The handler for key down events</param>
  657. /// <param name="keyUpHandler">The handler for key up events</param>
  658. /// <param name="mouseHandler">The handler for mouse events</param>
  659. public abstract void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler);
  660. /// <summary>
  661. /// Updates the screen to reflect all the changes that have been done to the display buffer
  662. /// </summary>
  663. public abstract void Refresh ();
  664. /// <summary>
  665. /// Updates the location of the cursor position
  666. /// </summary>
  667. public abstract void UpdateCursor ();
  668. /// <summary>
  669. /// Retreive the cursor caret visibility
  670. /// </summary>
  671. /// <param name="visibility">The current <see cref="CursorVisibility"/></param>
  672. /// <returns>true upon success</returns>
  673. public abstract bool GetCursorVisibility (out CursorVisibility visibility);
  674. /// <summary>
  675. /// Change the cursor caret visibility
  676. /// </summary>
  677. /// <param name="visibility">The wished <see cref="CursorVisibility"/></param>
  678. /// <returns>true upon success</returns>
  679. public abstract bool SetCursorVisibility (CursorVisibility visibility);
  680. /// <summary>
  681. /// Ensure the cursor visibility
  682. /// </summary>
  683. /// <returns>true upon success</returns>
  684. public abstract bool EnsureCursorVisibility ();
  685. /// <summary>
  686. /// Ends the execution of the console driver.
  687. /// </summary>
  688. public abstract void End ();
  689. /// <summary>
  690. /// Resizes the clip area when the screen is resized.
  691. /// </summary>
  692. public abstract void ResizeScreen ();
  693. /// <summary>
  694. /// Reset and recreate the contents and the driver buffer.
  695. /// </summary>
  696. public abstract void UpdateOffScreen ();
  697. /// <summary>
  698. /// Redraws the physical screen with the contents that have been queued up via any of the printing commands.
  699. /// </summary>
  700. public abstract void UpdateScreen ();
  701. /// <summary>
  702. /// Selects the specified attribute as the attribute to use for future calls to AddRune, AddString.
  703. /// </summary>
  704. /// <param name="c">C.</param>
  705. public abstract void SetAttribute (Attribute c);
  706. /// <summary>
  707. /// Set Colors from limit sets of colors.
  708. /// </summary>
  709. /// <param name="foreground">Foreground.</param>
  710. /// <param name="background">Background.</param>
  711. public abstract void SetColors (ConsoleColor foreground, ConsoleColor background);
  712. // Advanced uses - set colors to any pre-set pairs, you would need to init_color
  713. // that independently with the R, G, B values.
  714. /// <summary>
  715. /// Advanced uses - set colors to any pre-set pairs, you would need to init_color
  716. /// that independently with the R, G, B values.
  717. /// </summary>
  718. /// <param name="foregroundColorId">Foreground color identifier.</param>
  719. /// <param name="backgroundColorId">Background color identifier.</param>
  720. public abstract void SetColors (short foregroundColorId, short backgroundColorId);
  721. /// <summary>
  722. /// Gets the foreground and background colors based on the value.
  723. /// </summary>
  724. /// <param name="value">The value.</param>
  725. /// <param name="foreground">The foreground.</param>
  726. /// <param name="background">The background.</param>
  727. /// <returns></returns>
  728. public abstract bool GetColors (int value, out Color foreground, out Color background);
  729. /// <summary>
  730. /// Allows sending keys without typing on a keyboard.
  731. /// </summary>
  732. /// <param name="keyChar">The character key.</param>
  733. /// <param name="key">The key.</param>
  734. /// <param name="shift">If shift key is sending.</param>
  735. /// <param name="alt">If alt key is sending.</param>
  736. /// <param name="control">If control key is sending.</param>
  737. public abstract void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control);
  738. /// <summary>
  739. /// Set the handler when the terminal is resized.
  740. /// </summary>
  741. /// <param name="terminalResized"></param>
  742. public void SetTerminalResized (Action terminalResized)
  743. {
  744. TerminalResized = terminalResized;
  745. }
  746. /// <summary>
  747. /// Draws the title for a Window-style view incorporating padding.
  748. /// </summary>
  749. /// <param name="region">Screen relative region where the frame will be drawn.</param>
  750. /// <param name="title">The title for the window. The title will only be drawn if <c>title</c> is not null or empty and paddingTop is greater than 0.</param>
  751. /// <param name="paddingLeft">Number of columns to pad on the left (if 0 the border will not appear on the left).</param>
  752. /// <param name="paddingTop">Number of rows to pad on the top (if 0 the border and title will not appear on the top).</param>
  753. /// <param name="paddingRight">Number of columns to pad on the right (if 0 the border will not appear on the right).</param>
  754. /// <param name="paddingBottom">Number of rows to pad on the bottom (if 0 the border will not appear on the bottom).</param>
  755. /// <param name="textAlignment">Not yet implemented.</param>
  756. /// <remarks></remarks>
  757. public virtual void DrawWindowTitle (Rect region, ustring title, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, TextAlignment textAlignment = TextAlignment.Left)
  758. {
  759. var width = region.Width - (paddingLeft + 2) * 2;
  760. if (!ustring.IsNullOrEmpty (title) && width > 4 && region.Y + paddingTop <= region.Y + paddingBottom) {
  761. Move (region.X + 1 + paddingLeft, region.Y + paddingTop);
  762. AddRune (' ');
  763. var str = title.Sum (r => Math.Max (Rune.ColumnWidth (r), 1)) >= width
  764. ? TextFormatter.Format (title, width - 2, false, false) [0] : title;
  765. AddStr (str);
  766. AddRune (' ');
  767. }
  768. }
  769. /// <summary>
  770. /// Enables diagnostic functions
  771. /// </summary>
  772. [Flags]
  773. public enum DiagnosticFlags : uint {
  774. /// <summary>
  775. /// All diagnostics off
  776. /// </summary>
  777. Off = 0b_0000_0000,
  778. /// <summary>
  779. /// When enabled, <see cref="DrawWindowFrame(Rect, int, int, int, int, bool, bool, Border)"/> will draw a
  780. /// ruler in the frame for any side with a padding value greater than 0.
  781. /// </summary>
  782. FrameRuler = 0b_0000_0001,
  783. /// <summary>
  784. /// When Enabled, <see cref="DrawWindowFrame(Rect, int, int, int, int, bool, bool, Border)"/> will use
  785. /// 'L', 'R', 'T', and 'B' for padding instead of ' '.
  786. /// </summary>
  787. FramePadding = 0b_0000_0010,
  788. }
  789. /// <summary>
  790. /// Set flags to enable/disable <see cref="ConsoleDriver"/> diagnostics.
  791. /// </summary>
  792. public static DiagnosticFlags Diagnostics { get; set; }
  793. /// <summary>
  794. /// Draws a frame for a window with padding and an optional visible border inside the padding.
  795. /// </summary>
  796. /// <param name="region">Screen relative region where the frame will be drawn.</param>
  797. /// <param name="paddingLeft">Number of columns to pad on the left (if 0 the border will not appear on the left).</param>
  798. /// <param name="paddingTop">Number of rows to pad on the top (if 0 the border and title will not appear on the top).</param>
  799. /// <param name="paddingRight">Number of columns to pad on the right (if 0 the border will not appear on the right).</param>
  800. /// <param name="paddingBottom">Number of rows to pad on the bottom (if 0 the border will not appear on the bottom).</param>
  801. /// <param name="border">If set to <c>true</c> and any padding dimension is > 0 the border will be drawn.</param>
  802. /// <param name="fill">If set to <c>true</c> it will clear the content area (the area inside the padding) with the current color, otherwise the content area will be left untouched.</param>
  803. /// <param name="borderContent">The <see cref="Border"/> to be used if defined.</param>
  804. public virtual void DrawWindowFrame (Rect region, int paddingLeft = 0, int paddingTop = 0, int paddingRight = 0,
  805. int paddingBottom = 0, bool border = true, bool fill = false, Border borderContent = null)
  806. {
  807. char clearChar = ' ';
  808. char leftChar = clearChar;
  809. char rightChar = clearChar;
  810. char topChar = clearChar;
  811. char bottomChar = clearChar;
  812. if ((Diagnostics & DiagnosticFlags.FramePadding) == DiagnosticFlags.FramePadding) {
  813. leftChar = 'L';
  814. rightChar = 'R';
  815. topChar = 'T';
  816. bottomChar = 'B';
  817. clearChar = 'C';
  818. }
  819. void AddRuneAt (int col, int row, Rune ch)
  820. {
  821. Move (col, row);
  822. AddRune (ch);
  823. }
  824. // fwidth is count of hLine chars
  825. int fwidth = (int)(region.Width - (paddingRight + paddingLeft));
  826. // fheight is count of vLine chars
  827. int fheight = (int)(region.Height - (paddingBottom + paddingTop));
  828. // fleft is location of left frame line
  829. int fleft = region.X + paddingLeft - 1;
  830. // fright is location of right frame line
  831. int fright = fleft + fwidth + 1;
  832. // ftop is location of top frame line
  833. int ftop = region.Y + paddingTop - 1;
  834. // fbottom is location of bottom frame line
  835. int fbottom = ftop + fheight + 1;
  836. var borderStyle = borderContent == null ? BorderStyle.Single : borderContent.BorderStyle;
  837. Rune hLine = default, vLine = default,
  838. uRCorner = default, uLCorner = default, lLCorner = default, lRCorner = default;
  839. if (border) {
  840. switch (borderStyle) {
  841. case BorderStyle.None:
  842. break;
  843. case BorderStyle.Single:
  844. hLine = HLine;
  845. vLine = VLine;
  846. uRCorner = URCorner;
  847. uLCorner = ULCorner;
  848. lLCorner = LLCorner;
  849. lRCorner = LRCorner;
  850. break;
  851. case BorderStyle.Double:
  852. hLine = HDLine;
  853. vLine = VDLine;
  854. uRCorner = URDCorner;
  855. uLCorner = ULDCorner;
  856. lLCorner = LLDCorner;
  857. lRCorner = LRDCorner;
  858. break;
  859. case BorderStyle.Rounded:
  860. hLine = HRLine;
  861. vLine = VRLine;
  862. uRCorner = URRCorner;
  863. uLCorner = ULRCorner;
  864. lLCorner = LLRCorner;
  865. lRCorner = LRRCorner;
  866. break;
  867. }
  868. } else {
  869. hLine = vLine = uRCorner = uLCorner = lLCorner = lRCorner = clearChar;
  870. }
  871. // Outside top
  872. if (paddingTop > 1) {
  873. for (int r = region.Y; r < ftop; r++) {
  874. for (int c = region.X; c < region.X + region.Width; c++) {
  875. AddRuneAt (c, r, topChar);
  876. }
  877. }
  878. }
  879. // Outside top-left
  880. for (int c = region.X; c < fleft; c++) {
  881. AddRuneAt (c, ftop, leftChar);
  882. }
  883. // Frame top-left corner
  884. AddRuneAt (fleft, ftop, paddingTop >= 0 ? (paddingLeft >= 0 ? uLCorner : hLine) : leftChar);
  885. // Frame top
  886. for (int c = fleft + 1; c < fleft + 1 + fwidth; c++) {
  887. AddRuneAt (c, ftop, paddingTop > 0 ? hLine : topChar);
  888. }
  889. // Frame top-right corner
  890. if (fright > fleft) {
  891. AddRuneAt (fright, ftop, paddingTop >= 0 ? (paddingRight >= 0 ? uRCorner : hLine) : rightChar);
  892. }
  893. // Outside top-right corner
  894. for (int c = fright + 1; c < fright + paddingRight; c++) {
  895. AddRuneAt (c, ftop, rightChar);
  896. }
  897. // Left, Fill, Right
  898. if (fbottom > ftop) {
  899. for (int r = ftop + 1; r < fbottom; r++) {
  900. // Outside left
  901. for (int c = region.X; c < fleft; c++) {
  902. AddRuneAt (c, r, leftChar);
  903. }
  904. // Frame left
  905. AddRuneAt (fleft, r, paddingLeft > 0 ? vLine : leftChar);
  906. // Fill
  907. if (fill) {
  908. for (int x = fleft + 1; x < fright; x++) {
  909. AddRuneAt (x, r, clearChar);
  910. }
  911. }
  912. // Frame right
  913. if (fright > fleft) {
  914. var v = vLine;
  915. if ((Diagnostics & DiagnosticFlags.FrameRuler) == DiagnosticFlags.FrameRuler) {
  916. v = (char)(((int)'0') + ((r - ftop) % 10)); // vLine;
  917. }
  918. AddRuneAt (fright, r, paddingRight > 0 ? v : rightChar);
  919. }
  920. // Outside right
  921. for (int c = fright + 1; c < fright + paddingRight; c++) {
  922. AddRuneAt (c, r, rightChar);
  923. }
  924. }
  925. // Outside Bottom
  926. for (int c = region.X; c < region.X + region.Width; c++) {
  927. AddRuneAt (c, fbottom, leftChar);
  928. }
  929. // Frame bottom-left
  930. AddRuneAt (fleft, fbottom, paddingLeft > 0 ? lLCorner : leftChar);
  931. if (fright > fleft) {
  932. // Frame bottom
  933. for (int c = fleft + 1; c < fright; c++) {
  934. var h = hLine;
  935. if ((Diagnostics & DiagnosticFlags.FrameRuler) == DiagnosticFlags.FrameRuler) {
  936. h = (char)(((int)'0') + ((c - fleft) % 10)); // hLine;
  937. }
  938. AddRuneAt (c, fbottom, paddingBottom > 0 ? h : bottomChar);
  939. }
  940. // Frame bottom-right
  941. AddRuneAt (fright, fbottom, paddingRight > 0 ? (paddingBottom > 0 ? lRCorner : hLine) : rightChar);
  942. }
  943. // Outside right
  944. for (int c = fright + 1; c < fright + paddingRight; c++) {
  945. AddRuneAt (c, fbottom, rightChar);
  946. }
  947. }
  948. // Out bottom - ensure top is always drawn if we overlap
  949. if (paddingBottom > 0) {
  950. for (int r = fbottom + 1; r < fbottom + paddingBottom; r++) {
  951. for (int c = region.X; c < region.X + region.Width; c++) {
  952. AddRuneAt (c, r, bottomChar);
  953. }
  954. }
  955. }
  956. }
  957. /// <summary>
  958. /// Draws a frame on the specified region with the specified padding around the frame.
  959. /// </summary>
  960. /// <param name="region">Screen relative region where the frame will be drawn.</param>
  961. /// <param name="padding">Padding to add on the sides.</param>
  962. /// <param name="fill">If set to <c>true</c> it will clear the contents with the current color, otherwise the contents will be left untouched.</param>
  963. /// <remarks>This API has been superseded by <see cref="DrawWindowFrame(Rect, int, int, int, int, bool, bool, Border)"/>.</remarks>
  964. /// <remarks>This API is equivalent to calling <c>DrawWindowFrame(Rect, p - 1, p - 1, p - 1, p - 1)</c>. In other words,
  965. /// A padding value of 0 means there is actually a one cell border.
  966. /// </remarks>
  967. public virtual void DrawFrame (Rect region, int padding, bool fill)
  968. {
  969. // DrawFrame assumes the border is always at least one row/col thick
  970. // DrawWindowFrame assumes a padding of 0 means NO padding and no frame
  971. DrawWindowFrame (new Rect (region.X, region.Y, region.Width, region.Height),
  972. padding + 1, padding + 1, padding + 1, padding + 1, border: false, fill: fill);
  973. }
  974. /// <summary>
  975. /// Suspend the application, typically needs to save the state, suspend the app and upon return, reset the console driver.
  976. /// </summary>
  977. public abstract void Suspend ();
  978. Rect clip;
  979. /// <summary>
  980. /// Controls the current clipping region that AddRune/AddStr is subject to.
  981. /// </summary>
  982. /// <value>The clip.</value>
  983. public Rect Clip {
  984. get => clip;
  985. set => this.clip = value;
  986. }
  987. /// <summary>
  988. /// Start of mouse moves.
  989. /// </summary>
  990. public abstract void StartReportingMouseMoves ();
  991. /// <summary>
  992. /// Stop reporting mouses moves.
  993. /// </summary>
  994. public abstract void StopReportingMouseMoves ();
  995. /// <summary>
  996. /// Disables the cooked event processing from the mouse driver. At startup, it is assumed mouse events are cooked.
  997. /// </summary>
  998. public abstract void UncookMouse ();
  999. /// <summary>
  1000. /// Enables the cooked event processing from the mouse driver
  1001. /// </summary>
  1002. public abstract void CookMouse ();
  1003. /// <summary>
  1004. /// Horizontal line character.
  1005. /// </summary>
  1006. public Rune HLine = '\u2500';
  1007. /// <summary>
  1008. /// Vertical line character.
  1009. /// </summary>
  1010. public Rune VLine = '\u2502';
  1011. /// <summary>
  1012. /// Stipple pattern
  1013. /// </summary>
  1014. public Rune Stipple = '\u2591';
  1015. /// <summary>
  1016. /// Diamond character
  1017. /// </summary>
  1018. public Rune Diamond = '\u25ca';
  1019. /// <summary>
  1020. /// Upper left corner
  1021. /// </summary>
  1022. public Rune ULCorner = '\u250C';
  1023. /// <summary>
  1024. /// Lower left corner
  1025. /// </summary>
  1026. public Rune LLCorner = '\u2514';
  1027. /// <summary>
  1028. /// Upper right corner
  1029. /// </summary>
  1030. public Rune URCorner = '\u2510';
  1031. /// <summary>
  1032. /// Lower right corner
  1033. /// </summary>
  1034. public Rune LRCorner = '\u2518';
  1035. /// <summary>
  1036. /// Left tee
  1037. /// </summary>
  1038. public Rune LeftTee = '\u251c';
  1039. /// <summary>
  1040. /// Right tee
  1041. /// </summary>
  1042. public Rune RightTee = '\u2524';
  1043. /// <summary>
  1044. /// Top tee
  1045. /// </summary>
  1046. public Rune TopTee = '\u252c';
  1047. /// <summary>
  1048. /// The bottom tee.
  1049. /// </summary>
  1050. public Rune BottomTee = '\u2534';
  1051. /// <summary>
  1052. /// Checkmark.
  1053. /// </summary>
  1054. public Rune Checked = '\u221a';
  1055. /// <summary>
  1056. /// Un-checked checkmark.
  1057. /// </summary>
  1058. public Rune UnChecked = '\u2574';
  1059. /// <summary>
  1060. /// Selected mark.
  1061. /// </summary>
  1062. public Rune Selected = '\u25cf';
  1063. /// <summary>
  1064. /// Un-selected selected mark.
  1065. /// </summary>
  1066. public Rune UnSelected = '\u25cc';
  1067. /// <summary>
  1068. /// Right Arrow.
  1069. /// </summary>
  1070. public Rune RightArrow = '\u25ba';
  1071. /// <summary>
  1072. /// Left Arrow.
  1073. /// </summary>
  1074. public Rune LeftArrow = '\u25c4';
  1075. /// <summary>
  1076. /// Down Arrow.
  1077. /// </summary>
  1078. public Rune DownArrow = '\u25bc';
  1079. /// <summary>
  1080. /// Up Arrow.
  1081. /// </summary>
  1082. public Rune UpArrow = '\u25b2';
  1083. /// <summary>
  1084. /// Left indicator for default action (e.g. for <see cref="Button"/>).
  1085. /// </summary>
  1086. public Rune LeftDefaultIndicator = '\u25e6';
  1087. /// <summary>
  1088. /// Right indicator for default action (e.g. for <see cref="Button"/>).
  1089. /// </summary>
  1090. public Rune RightDefaultIndicator = '\u25e6';
  1091. /// <summary>
  1092. /// Left frame/bracket (e.g. '[' for <see cref="Button"/>).
  1093. /// </summary>
  1094. public Rune LeftBracket = '[';
  1095. /// <summary>
  1096. /// Right frame/bracket (e.g. ']' for <see cref="Button"/>).
  1097. /// </summary>
  1098. public Rune RightBracket = ']';
  1099. /// <summary>
  1100. /// Blocks Segment indicator for meter views (e.g. <see cref="ProgressBar"/>.
  1101. /// </summary>
  1102. public Rune BlocksMeterSegment = '\u258c';
  1103. /// <summary>
  1104. /// Continuous Segment indicator for meter views (e.g. <see cref="ProgressBar"/>.
  1105. /// </summary>
  1106. public Rune ContinuousMeterSegment = '\u2588';
  1107. /// <summary>
  1108. /// Horizontal double line character.
  1109. /// </summary>
  1110. public Rune HDLine = '\u2550';
  1111. /// <summary>
  1112. /// Vertical double line character.
  1113. /// </summary>
  1114. public Rune VDLine = '\u2551';
  1115. /// <summary>
  1116. /// Upper left double corner
  1117. /// </summary>
  1118. public Rune ULDCorner = '\u2554';
  1119. /// <summary>
  1120. /// Lower left double corner
  1121. /// </summary>
  1122. public Rune LLDCorner = '\u255a';
  1123. /// <summary>
  1124. /// Upper right double corner
  1125. /// </summary>
  1126. public Rune URDCorner = '\u2557';
  1127. /// <summary>
  1128. /// Lower right double corner
  1129. /// </summary>
  1130. public Rune LRDCorner = '\u255d';
  1131. /// <summary>
  1132. /// Horizontal line character for rounded corners.
  1133. /// </summary>
  1134. public Rune HRLine = '\u2500';
  1135. /// <summary>
  1136. /// Vertical line character for rounded corners.
  1137. /// </summary>
  1138. public Rune VRLine = '\u2502';
  1139. /// <summary>
  1140. /// Upper left rounded corner
  1141. /// </summary>
  1142. public Rune ULRCorner = '\u256d';
  1143. /// <summary>
  1144. /// Lower left rounded corner
  1145. /// </summary>
  1146. public Rune LLRCorner = '\u2570';
  1147. /// <summary>
  1148. /// Upper right rounded corner
  1149. /// </summary>
  1150. public Rune URRCorner = '\u256e';
  1151. /// <summary>
  1152. /// Lower right rounded corner
  1153. /// </summary>
  1154. public Rune LRRCorner = '\u256f';
  1155. /// <summary>
  1156. /// Make the attribute for the foreground and background colors.
  1157. /// </summary>
  1158. /// <param name="fore">Foreground.</param>
  1159. /// <param name="back">Background.</param>
  1160. /// <returns></returns>
  1161. public abstract Attribute MakeAttribute (Color fore, Color back);
  1162. /// <summary>
  1163. /// Gets the current <see cref="Attribute"/>.
  1164. /// </summary>
  1165. /// <returns>The current attribute.</returns>
  1166. public abstract Attribute GetAttribute ();
  1167. /// <summary>
  1168. /// Make the <see cref="Colors"/> for the <see cref="ColorScheme"/>.
  1169. /// </summary>
  1170. /// <param name="foreground">The foreground color.</param>
  1171. /// <param name="background">The background color.</param>
  1172. /// <returns>The attribute for the foreground and background colors.</returns>
  1173. public abstract Attribute MakeColor (Color foreground, Color background);
  1174. /// <summary>
  1175. /// Create all <see cref="Colors"/> with the <see cref="ColorScheme"/> for the console driver.
  1176. /// </summary>
  1177. /// <param name="hasColors">Flag indicating if colors are supported.</param>
  1178. public void CreateColors (bool hasColors = true)
  1179. {
  1180. Colors.TopLevel = new ColorScheme ();
  1181. Colors.Base = new ColorScheme ();
  1182. Colors.Dialog = new ColorScheme ();
  1183. Colors.Menu = new ColorScheme ();
  1184. Colors.Error = new ColorScheme ();
  1185. if (!hasColors) {
  1186. return;
  1187. }
  1188. Colors.TopLevel.Normal = MakeColor (Color.BrightGreen, Color.Black);
  1189. Colors.TopLevel.Focus = MakeColor (Color.White, Color.Cyan);
  1190. Colors.TopLevel.HotNormal = MakeColor (Color.Brown, Color.Black);
  1191. Colors.TopLevel.HotFocus = MakeColor (Color.Blue, Color.Cyan);
  1192. Colors.TopLevel.Disabled = MakeColor (Color.DarkGray, Color.Black);
  1193. Colors.Base.Normal = MakeColor (Color.White, Color.Blue);
  1194. Colors.Base.Focus = MakeColor (Color.Black, Color.Gray);
  1195. Colors.Base.HotNormal = MakeColor (Color.BrightCyan, Color.Blue);
  1196. Colors.Base.HotFocus = MakeColor (Color.BrightBlue, Color.Gray);
  1197. Colors.Base.Disabled = MakeColor (Color.DarkGray, Color.Blue);
  1198. Colors.Dialog.Normal = MakeColor (Color.Black, Color.Gray);
  1199. Colors.Dialog.Focus = MakeColor (Color.White, Color.DarkGray);
  1200. Colors.Dialog.HotNormal = MakeColor (Color.Blue, Color.Gray);
  1201. Colors.Dialog.HotFocus = MakeColor (Color.BrightYellow, Color.DarkGray);
  1202. Colors.Dialog.Disabled = MakeColor (Color.Gray, Color.DarkGray);
  1203. Colors.Menu.Normal = MakeColor (Color.White, Color.DarkGray);
  1204. Colors.Menu.Focus = MakeColor (Color.White, Color.Black);
  1205. Colors.Menu.HotNormal = MakeColor (Color.BrightYellow, Color.DarkGray);
  1206. Colors.Menu.HotFocus = MakeColor (Color.BrightYellow, Color.Black);
  1207. Colors.Menu.Disabled = MakeColor (Color.Gray, Color.DarkGray);
  1208. Colors.Error.Normal = MakeColor (Color.Red, Color.White);
  1209. Colors.Error.Focus = MakeColor (Color.Black, Color.BrightRed);
  1210. Colors.Error.HotNormal = MakeColor (Color.Black, Color.White);
  1211. Colors.Error.HotFocus = MakeColor (Color.BrightRed, Color.Gray);
  1212. Colors.Error.Disabled = MakeColor (Color.DarkGray, Color.White);
  1213. }
  1214. }
  1215. }