UICatalogTop.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. using System.Collections.ObjectModel;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Text.Json.Serialization;
  6. using Microsoft.Extensions.Logging;
  7. using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
  8. #nullable enable
  9. namespace UICatalog;
  10. /// <summary>
  11. /// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on
  12. /// the command line) and each time a Scenario ends.
  13. /// </summary>
  14. public class UICatalogTop : Toplevel
  15. {
  16. // When a scenario is run, the main app is killed. The static
  17. // members are cached so that when the scenario exits the
  18. // main app UI can be restored to previous state
  19. // Note, we used to pass this to scenarios that run, but it just added complexity
  20. // So that was removed. But we still have this here to demonstrate how changing
  21. // the scheme works.
  22. public static string? CachedTopLevelScheme { get; set; }
  23. // Diagnostics
  24. private static ViewDiagnosticFlags _diagnosticFlags;
  25. public UICatalogTop ()
  26. {
  27. _diagnosticFlags = Diagnostics;
  28. _menuBar = CreateMenuBar ();
  29. _statusBar = CreateStatusBar ();
  30. _categoryList = CreateCategoryList ();
  31. _scenarioList = CreateScenarioList ();
  32. Add (_menuBar, _categoryList, _scenarioList, _statusBar);
  33. Loaded += LoadedHandler;
  34. Unloaded += UnloadedHandler;
  35. // Restore previous selections
  36. _categoryList.SelectedItem = _cachedCategoryIndex;
  37. _scenarioList.SelectedRow = _cachedScenarioIndex;
  38. SchemeName = CachedTopLevelScheme = SchemeManager.SchemesToSchemeName (Schemes.Base);
  39. ConfigurationManager.Applied += ConfigAppliedHandler;
  40. }
  41. private static bool _isFirstRunning = true;
  42. private void LoadedHandler (object? sender, EventArgs? args)
  43. {
  44. if (_disableMouseCb is { })
  45. {
  46. _disableMouseCb.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;
  47. }
  48. if (_shVersion is { })
  49. {
  50. _shVersion.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {Application.Driver!.GetVersionInfo ()}";
  51. }
  52. if (CachedSelectedScenario != null)
  53. {
  54. CachedSelectedScenario = null;
  55. _isFirstRunning = false;
  56. }
  57. if (!_isFirstRunning)
  58. {
  59. _scenarioList.SetFocus ();
  60. }
  61. if (_statusBar is { })
  62. {
  63. _statusBar.VisibleChanged += (s, e) => { ShowStatusBar = _statusBar.Visible; };
  64. }
  65. Loaded -= LoadedHandler;
  66. _categoryList!.EnsureSelectedItemVisible ();
  67. _scenarioList.EnsureSelectedCellIsVisible ();
  68. }
  69. private void UnloadedHandler (object? sender, EventArgs? args)
  70. {
  71. ConfigurationManager.Applied -= ConfigAppliedHandler;
  72. Unloaded -= UnloadedHandler;
  73. }
  74. #region MenuBar
  75. private readonly MenuBarv2? _menuBar;
  76. private CheckBox? _force16ColorsMenuItemCb;
  77. private OptionSelector? _themesRg;
  78. private OptionSelector? _topSchemeRg;
  79. private OptionSelector? _logLevelRg;
  80. private FlagSelector<ViewDiagnosticFlags>? _diagnosticFlagsSelector;
  81. private CheckBox? _disableMouseCb;
  82. private MenuBarv2 CreateMenuBar ()
  83. {
  84. MenuBarv2 menuBar = new (
  85. [
  86. new (
  87. "_File",
  88. [
  89. new MenuItemv2 ()
  90. {
  91. Title ="_Quit",
  92. HelpText = "Quit UI Catalog",
  93. Key = Application.QuitKey,
  94. // By not specifying TargetView the Key Binding will be Application-level
  95. Command = Command.Quit
  96. }
  97. ]),
  98. new ("_Themes", CreateThemeMenuItems ()),
  99. new ("Diag_nostics", CreateDiagnosticMenuItems ()),
  100. new ("_Logging", CreateLoggingMenuItems ()),
  101. new (
  102. "_Help",
  103. [
  104. new MenuItemv2 (
  105. "_Documentation",
  106. "",
  107. () => OpenUrl ("https://gui-cs.github.io/Terminal.GuiV2Docs"),
  108. Key.F1
  109. ),
  110. new MenuItemv2 (
  111. "_README",
  112. "",
  113. () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"),
  114. Key.F2
  115. ),
  116. new MenuItemv2 (
  117. "_About...",
  118. "About UI Catalog",
  119. () => MessageBox.Query (
  120. "",
  121. GetAboutBoxMessage (),
  122. wrapMessage: false,
  123. buttons: "_Ok"
  124. ),
  125. Key.A.WithCtrl
  126. )
  127. ])
  128. ])
  129. {
  130. Title = "menuBar",
  131. Id = "menuBar"
  132. };
  133. return menuBar;
  134. View [] CreateThemeMenuItems ()
  135. {
  136. List<View> menuItems = [];
  137. _force16ColorsMenuItemCb = new ()
  138. {
  139. Title = "Force _16 Colors",
  140. CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked
  141. };
  142. _force16ColorsMenuItemCb.CheckedStateChanged += (sender, args) =>
  143. {
  144. Application.Force16Colors = args.CurrentValue == CheckState.Checked;
  145. _force16ColorsShortcutCb!.CheckedState = args.CurrentValue;
  146. Application.LayoutAndDraw ();
  147. };
  148. menuItems.Add (
  149. new MenuItemv2
  150. {
  151. CommandView = _force16ColorsMenuItemCb
  152. });
  153. menuItems.Add (new Line ());
  154. if (ConfigurationManager.IsEnabled)
  155. {
  156. _themesRg = new ()
  157. {
  158. HighlightStyle = HighlightStyle.None,
  159. };
  160. _themesRg.SelectedItemChanged += (_, args) =>
  161. {
  162. if (args.SelectedItem is null)
  163. {
  164. return;
  165. }
  166. ThemeManager.Theme = ThemeManager.GetThemeNames () [args.SelectedItem!.Value];
  167. };
  168. var menuItem = new MenuItemv2
  169. {
  170. CommandView = _themesRg,
  171. HelpText = "Cycle Through Themes",
  172. Key = Key.T.WithCtrl
  173. };
  174. menuItems.Add (menuItem);
  175. menuItems.Add (new Line ());
  176. _topSchemeRg = new ()
  177. {
  178. HighlightStyle = HighlightStyle.None,
  179. };
  180. _topSchemeRg.SelectedItemChanged += (_, args) =>
  181. {
  182. if (args.SelectedItem is null)
  183. {
  184. return;
  185. }
  186. CachedTopLevelScheme = SchemeManager.GetSchemesForCurrentTheme ()!.Keys.ToArray () [args.SelectedItem!.Value];
  187. SchemeName = CachedTopLevelScheme;
  188. SetNeedsDraw ();
  189. };
  190. menuItem = new ()
  191. {
  192. Title = "Scheme for Toplevel",
  193. SubMenu = new (
  194. [
  195. new ()
  196. {
  197. CommandView = _topSchemeRg,
  198. HelpText = "Cycle Through schemes",
  199. Key = Key.S.WithCtrl
  200. }
  201. ])
  202. };
  203. menuItems.Add (menuItem);
  204. UpdateThemesMenu ();
  205. }
  206. else
  207. {
  208. menuItems.Add (new MenuItemv2 ()
  209. {
  210. Title = "Configuration Manager is not Enabled",
  211. Enabled = false
  212. });
  213. }
  214. return menuItems.ToArray ();
  215. }
  216. View [] CreateDiagnosticMenuItems ()
  217. {
  218. List<View> menuItems = [];
  219. _diagnosticFlagsSelector = new ()
  220. {
  221. CanFocus = true,
  222. Styles = FlagSelectorStyles.ShowNone,
  223. HighlightStyle = HighlightStyle.None,
  224. };
  225. _diagnosticFlagsSelector.UsedHotKeys.Add (Key.D);
  226. _diagnosticFlagsSelector.AssignHotKeysToCheckBoxes = true;
  227. _diagnosticFlagsSelector.Value = Diagnostics;
  228. _diagnosticFlagsSelector.ValueChanged += (sender, args) =>
  229. {
  230. _diagnosticFlags = (ViewDiagnosticFlags)_diagnosticFlagsSelector.Value;
  231. Diagnostics = _diagnosticFlags;
  232. };
  233. menuItems.Add (
  234. new MenuItemv2
  235. {
  236. CommandView = _diagnosticFlagsSelector,
  237. HelpText = "View Diagnostics"
  238. });
  239. menuItems.Add (new Line ());
  240. _disableMouseCb = new ()
  241. {
  242. Title = "_Disable Mouse",
  243. CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked
  244. };
  245. _disableMouseCb.CheckedStateChanged += (_, args) => { Application.IsMouseDisabled = args.CurrentValue == CheckState.Checked; };
  246. menuItems.Add (
  247. new MenuItemv2
  248. {
  249. CommandView = _disableMouseCb,
  250. HelpText = "Disable Mouse"
  251. });
  252. return menuItems.ToArray ();
  253. }
  254. View [] CreateLoggingMenuItems ()
  255. {
  256. List<View?> menuItems = [];
  257. LogLevel [] logLevels = Enum.GetValues<LogLevel> ();
  258. _logLevelRg = new ()
  259. {
  260. AssignHotKeysToCheckBoxes = true,
  261. Options = Enum.GetNames<LogLevel> (),
  262. SelectedItem = logLevels.ToList ().IndexOf (Enum.Parse<LogLevel> (UICatalog.Options.DebugLogLevel)),
  263. HighlightStyle = HighlightStyle.Hover
  264. };
  265. _logLevelRg.SelectedItemChanged += (_, args) =>
  266. {
  267. UICatalog.Options = UICatalog.Options with { DebugLogLevel = Enum.GetName (logLevels [args.SelectedItem!.Value])! };
  268. UICatalog.LogLevelSwitch.MinimumLevel =
  269. UICatalog.LogLevelToLogEventLevel (Enum.Parse<LogLevel> (UICatalog.Options.DebugLogLevel));
  270. };
  271. menuItems.Add (
  272. new MenuItemv2
  273. {
  274. CommandView = _logLevelRg,
  275. HelpText = "Cycle Through Log Levels",
  276. Key = Key.L.WithCtrl
  277. });
  278. // add a separator
  279. menuItems.Add (new Line ());
  280. menuItems.Add (
  281. new MenuItemv2 (
  282. "_Open Log Folder",
  283. string.Empty,
  284. () => OpenUrl (UICatalog.LOGFILE_LOCATION)
  285. ));
  286. return menuItems.ToArray ()!;
  287. }
  288. }
  289. private void UpdateThemesMenu ()
  290. {
  291. if (_themesRg is null)
  292. {
  293. return;
  294. }
  295. _themesRg.SelectedItem = null;
  296. _themesRg.AssignHotKeysToCheckBoxes = true;
  297. _themesRg.UsedHotKeys.Clear ();
  298. _themesRg.Options = ThemeManager.GetThemeNames ();
  299. _themesRg.SelectedItem =ThemeManager.GetThemeNames ().IndexOf (ThemeManager.GetCurrentThemeName ());
  300. if (_topSchemeRg is null)
  301. {
  302. return;
  303. }
  304. _topSchemeRg.AssignHotKeysToCheckBoxes = true;
  305. _topSchemeRg.UsedHotKeys.Clear ();
  306. int? selectedScheme = _topSchemeRg.SelectedItem;
  307. _topSchemeRg.Options = SchemeManager.GetSchemeNames ();
  308. _topSchemeRg.SelectedItem = selectedScheme;
  309. if (CachedTopLevelScheme is null || !SchemeManager.GetSchemeNames ().Contains (CachedTopLevelScheme))
  310. {
  311. CachedTopLevelScheme = SchemeManager.SchemesToSchemeName (Schemes.Base);
  312. }
  313. int newSelectedItem = SchemeManager.GetSchemeNames ().IndexOf (CachedTopLevelScheme!);
  314. // if the item is in bounds then select it
  315. if (newSelectedItem >= 0 && newSelectedItem < SchemeManager.GetSchemeNames ().Count)
  316. {
  317. _topSchemeRg.SelectedItem = newSelectedItem;
  318. }
  319. }
  320. #endregion MenuBar
  321. #region Scenario List
  322. private readonly TableView _scenarioList;
  323. private static int _cachedScenarioIndex;
  324. public static ObservableCollection<Scenario>? CachedScenarios { get; set; }
  325. // If set, holds the scenario the user selected to run
  326. public static Scenario? CachedSelectedScenario { get; set; }
  327. private TableView CreateScenarioList ()
  328. {
  329. // Create the scenario list. The contents of the scenario list changes whenever the
  330. // Category list selection changes (to show just the scenarios that belong to the selected
  331. // category).
  332. TableView scenarioList = new ()
  333. {
  334. X = Pos.Right (_categoryList!) - 1,
  335. Y = Pos.Bottom (_menuBar!),
  336. Width = Dim.Fill (),
  337. Height = Dim.Fill (
  338. Dim.Func (
  339. () =>
  340. {
  341. if (_statusBar!.NeedsLayout)
  342. {
  343. throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
  344. //_statusBar.Layout ();
  345. }
  346. return _statusBar.Frame.Height;
  347. })),
  348. //AllowsMarking = false,
  349. CanFocus = true,
  350. Title = "_Scenarios",
  351. BorderStyle = _categoryList!.BorderStyle,
  352. SuperViewRendersLineCanvas = true
  353. };
  354. // TableView provides many options for table headers. For simplicity, we turn all
  355. // of these off. By enabling FullRowSelect and turning off headers, TableView looks just
  356. // like a ListView
  357. scenarioList.FullRowSelect = true;
  358. scenarioList.Style.ShowHeaders = false;
  359. scenarioList.Style.ShowHorizontalHeaderOverline = false;
  360. scenarioList.Style.ShowHorizontalHeaderUnderline = false;
  361. scenarioList.Style.ShowHorizontalBottomline = false;
  362. scenarioList.Style.ShowVerticalCellLines = false;
  363. scenarioList.Style.ShowVerticalHeaderLines = false;
  364. /* By default, TableView lays out columns at render time and only
  365. * measures y rows of data at a time. Where y is the height of the
  366. * console. This is for the following reasons:
  367. *
  368. * - Performance, when tables have a large amount of data
  369. * - Defensive, prevents a single wide cell value pushing other
  370. * columns off-screen (requiring horizontal scrolling
  371. *
  372. * In the case of UICatalog here, such an approach is overkill so
  373. * we just measure all the data ourselves and set the appropriate
  374. * max widths as ColumnStyles
  375. */
  376. int longestName = CachedScenarios!.Max (s => s.GetName ().Length);
  377. scenarioList.Style.ColumnStyles.Add (
  378. 0,
  379. new () { MaxWidth = longestName, MinWidth = longestName, MinAcceptableWidth = longestName }
  380. );
  381. scenarioList.Style.ColumnStyles.Add (1, new () { MaxWidth = 1 });
  382. scenarioList.CellActivated += ScenarioView_OpenSelectedItem;
  383. // TableView typically is a grid where nav keys are biased for moving left/right.
  384. scenarioList.KeyBindings.Remove (Key.Home);
  385. scenarioList.KeyBindings.Add (Key.Home, Command.Start);
  386. scenarioList.KeyBindings.Remove (Key.End);
  387. scenarioList.KeyBindings.Add (Key.End, Command.End);
  388. // Ideally, TableView.MultiSelect = false would turn off any keybindings for
  389. // multi-select options. But it currently does not. UI Catalog uses Ctrl-A for
  390. // a shortcut to About.
  391. scenarioList.MultiSelect = false;
  392. scenarioList.KeyBindings.Remove (Key.A.WithCtrl);
  393. return scenarioList;
  394. }
  395. /// <summary>Launches the selected scenario, setting the global _selectedScenario</summary>
  396. /// <param name="e"></param>
  397. private void ScenarioView_OpenSelectedItem (object? sender, EventArgs? e)
  398. {
  399. if (CachedSelectedScenario is null)
  400. {
  401. // Save selected item state
  402. _cachedCategoryIndex = _categoryList!.SelectedItem;
  403. _cachedScenarioIndex = _scenarioList.SelectedRow;
  404. // Create new instance of scenario (even though Scenarios contains instances)
  405. var selectedScenarioName = (string)_scenarioList.Table [_scenarioList.SelectedRow, 0];
  406. CachedSelectedScenario = (Scenario)Activator.CreateInstance (
  407. CachedScenarios!.FirstOrDefault (
  408. s => s.GetName ()
  409. == selectedScenarioName
  410. )!
  411. .GetType ()
  412. )!;
  413. // Tell the main app to stop
  414. Application.RequestStop ();
  415. }
  416. }
  417. #endregion Scenario List
  418. #region Category List
  419. private readonly ListView? _categoryList;
  420. private static int _cachedCategoryIndex;
  421. public static ObservableCollection<string>? CachedCategories { get; set; }
  422. private ListView CreateCategoryList ()
  423. {
  424. // Create the Category list view. This list never changes.
  425. ListView categoryList = new ()
  426. {
  427. X = 0,
  428. Y = Pos.Bottom (_menuBar!),
  429. Width = Dim.Auto (),
  430. Height = Dim.Fill (
  431. Dim.Func (
  432. () =>
  433. {
  434. if (_statusBar!.NeedsLayout)
  435. {
  436. throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
  437. //_statusBar.Layout ();
  438. }
  439. return _statusBar.Frame.Height;
  440. })),
  441. AllowsMarking = false,
  442. CanFocus = true,
  443. Title = "_Categories",
  444. BorderStyle = LineStyle.Rounded,
  445. SuperViewRendersLineCanvas = true,
  446. Source = new ListWrapper<string> (CachedCategories)
  447. };
  448. categoryList.OpenSelectedItem += (s, a) => { _scenarioList!.SetFocus (); };
  449. categoryList.SelectedItemChanged += CategoryView_SelectedChanged;
  450. // This enables the scrollbar by causing lazy instantiation to happen
  451. categoryList.VerticalScrollBar.AutoShow = true;
  452. return categoryList;
  453. }
  454. private void CategoryView_SelectedChanged (object? sender, ListViewItemEventArgs? e)
  455. {
  456. string item = CachedCategories! [e!.Item];
  457. ObservableCollection<Scenario> newScenarioList;
  458. if (e.Item == 0)
  459. {
  460. // First category is "All"
  461. newScenarioList = CachedScenarios!;
  462. }
  463. else
  464. {
  465. newScenarioList = new (CachedScenarios!.Where (s => s.GetCategories ().Contains (item)).ToList ());
  466. }
  467. _scenarioList.Table = new EnumerableTableSource<Scenario> (
  468. newScenarioList,
  469. new ()
  470. {
  471. { "Name", s => s.GetName () }, { "Description", s => s.GetDescription () }
  472. }
  473. );
  474. }
  475. #endregion Category List
  476. #region StatusBar
  477. private readonly StatusBar? _statusBar;
  478. [ConfigurationProperty (Scope = typeof (AppSettingsScope), OmitClassName = true)]
  479. [JsonPropertyName ("UICatalog.StatusBar")]
  480. public static bool ShowStatusBar { get; set; } = true;
  481. private Shortcut? _shQuit;
  482. private Shortcut? _shVersion;
  483. private CheckBox? _force16ColorsShortcutCb;
  484. private StatusBar CreateStatusBar ()
  485. {
  486. StatusBar statusBar = new ()
  487. {
  488. Visible = ShowStatusBar,
  489. AlignmentModes = AlignmentModes.IgnoreFirstOrLast,
  490. CanFocus = false
  491. };
  492. // ReSharper disable All
  493. statusBar.Height = Dim.Auto (
  494. DimAutoStyle.Auto,
  495. minimumContentDim: Dim.Func (() => statusBar.Visible ? 1 : 0),
  496. maximumContentDim: Dim.Func (() => statusBar.Visible ? 1 : 0));
  497. // ReSharper restore All
  498. _shQuit = new ()
  499. {
  500. CanFocus = false,
  501. Title = "Quit",
  502. Key = Application.QuitKey
  503. };
  504. _shVersion = new ()
  505. {
  506. Title = "Version Info",
  507. CanFocus = false
  508. };
  509. var statusBarShortcut = new Shortcut
  510. {
  511. Key = Key.F10,
  512. Title = "Show/Hide Status Bar",
  513. CanFocus = false
  514. };
  515. statusBarShortcut.Accepting += (sender, args) =>
  516. {
  517. statusBar.Visible = !_statusBar!.Visible;
  518. args.Handled = true;
  519. };
  520. _force16ColorsShortcutCb = new ()
  521. {
  522. Title = "16 color mode",
  523. CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
  524. CanFocus = false
  525. };
  526. _force16ColorsShortcutCb.CheckedStateChanging += (sender, args) =>
  527. {
  528. Application.Force16Colors = args.NewValue == CheckState.Checked;
  529. _force16ColorsMenuItemCb!.CheckedState = args.NewValue;
  530. Application.LayoutAndDraw ();
  531. };
  532. statusBar.Add (
  533. _shQuit,
  534. statusBarShortcut,
  535. new Shortcut
  536. {
  537. CanFocus = false,
  538. CommandView = _force16ColorsShortcutCb,
  539. HelpText = "",
  540. BindKeyToApplication = true,
  541. Key = Key.F7
  542. },
  543. _shVersion
  544. );
  545. if (UICatalog.Options.DontEnableConfigurationManagement)
  546. {
  547. statusBar.AddShortcutAt (statusBar.SubViews.ToList ().IndexOf (_shVersion), new Shortcut () { Title = "CM is Disabled" });
  548. }
  549. return statusBar;
  550. }
  551. #endregion StatusBar
  552. #region Configuration Manager
  553. /// <summary>
  554. /// Called when CM has applied changes.
  555. /// </summary>
  556. private void ConfigApplied ()
  557. {
  558. UpdateThemesMenu ();
  559. SchemeName = CachedTopLevelScheme;
  560. if (_shQuit is { })
  561. {
  562. _shQuit.Key = Application.QuitKey;
  563. }
  564. if (_statusBar is { })
  565. {
  566. _statusBar.Visible = ShowStatusBar;
  567. }
  568. _disableMouseCb!.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;
  569. _force16ColorsShortcutCb!.CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
  570. Application.Top?.SetNeedsDraw ();
  571. }
  572. private void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a) { ConfigApplied (); }
  573. #endregion Configuration Manager
  574. /// <summary>
  575. /// Gets the message displayed in the About Box. `public` so it can be used from Unit tests.
  576. /// </summary>
  577. /// <returns></returns>
  578. public static string GetAboutBoxMessage ()
  579. {
  580. // NOTE: Do not use multiline verbatim strings here.
  581. // WSL gets all confused.
  582. StringBuilder msg = new ();
  583. msg.AppendLine ("UI Catalog: A comprehensive sample library and test app for");
  584. msg.AppendLine ();
  585. msg.AppendLine (
  586. """
  587. _______ _ _ _____ _
  588. |__ __| (_) | | / ____| (_)
  589. | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _
  590. | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
  591. | | __/ | | | | | | | | | | | (_| | || |__| | |_| | |
  592. |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
  593. """);
  594. msg.AppendLine ();
  595. msg.AppendLine ("v2 - Pre-Alpha");
  596. msg.AppendLine ();
  597. msg.AppendLine ("https://github.com/gui-cs/Terminal.Gui");
  598. return msg.ToString ();
  599. }
  600. public static void OpenUrl (string url)
  601. {
  602. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows))
  603. {
  604. url = url.Replace ("&", "^&");
  605. Process.Start (new ProcessStartInfo ("cmd", $"/c start {url}") { CreateNoWindow = true });
  606. }
  607. else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux))
  608. {
  609. using var process = new Process
  610. {
  611. StartInfo = new ()
  612. {
  613. FileName = "xdg-open",
  614. Arguments = url,
  615. RedirectStandardError = true,
  616. RedirectStandardOutput = true,
  617. CreateNoWindow = true,
  618. UseShellExecute = false
  619. }
  620. };
  621. process.Start ();
  622. }
  623. else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX))
  624. {
  625. Process.Start ("open", url);
  626. }
  627. }
  628. }