CharMap.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. #nullable enable
  2. using System;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Text.Json;
  8. using Terminal.Gui;
  9. namespace UICatalog.Scenarios;
  10. /// <summary>
  11. /// A scrollable map of the Unicode codepoints.
  12. /// </summary>
  13. /// <remarks>
  14. /// See <see href="CharacterMap/README.md"/> for details.
  15. /// </remarks>
  16. public class CharMap : View, IDesignable
  17. {
  18. private const int COLUMN_WIDTH = 3; // Width of each column of glyphs
  19. private const int HEADER_HEIGHT = 1; // Height of the header
  20. private int _rowHeight = 1; // Height of each row of 16 glyphs - changing this is not tested
  21. private ContextMenu _contextMenu = new ();
  22. /// <summary>
  23. /// Initializes a new instance.
  24. /// </summary>
  25. public CharMap ()
  26. {
  27. base.ColorScheme = Colors.ColorSchemes ["Dialog"];
  28. CanFocus = true;
  29. CursorVisibility = CursorVisibility.Default;
  30. AddCommand (
  31. Command.Up,
  32. () =>
  33. {
  34. SelectedCodePoint -= 16;
  35. return true;
  36. }
  37. );
  38. AddCommand (
  39. Command.Down,
  40. () =>
  41. {
  42. SelectedCodePoint += 16;
  43. return true;
  44. }
  45. );
  46. AddCommand (
  47. Command.Left,
  48. () =>
  49. {
  50. SelectedCodePoint--;
  51. return true;
  52. }
  53. );
  54. AddCommand (
  55. Command.Right,
  56. () =>
  57. {
  58. SelectedCodePoint++;
  59. return true;
  60. }
  61. );
  62. AddCommand (
  63. Command.PageUp,
  64. () =>
  65. {
  66. int page = (Viewport.Height - HEADER_HEIGHT / _rowHeight) * 16;
  67. SelectedCodePoint -= page;
  68. return true;
  69. }
  70. );
  71. AddCommand (
  72. Command.PageDown,
  73. () =>
  74. {
  75. int page = (Viewport.Height - HEADER_HEIGHT / _rowHeight) * 16;
  76. SelectedCodePoint += page;
  77. return true;
  78. }
  79. );
  80. AddCommand (
  81. Command.Start,
  82. () =>
  83. {
  84. SelectedCodePoint = 0;
  85. return true;
  86. }
  87. );
  88. AddCommand (
  89. Command.End,
  90. () =>
  91. {
  92. SelectedCodePoint = MAX_CODE_POINT;
  93. return true;
  94. }
  95. );
  96. AddCommand (
  97. Command.Accept,
  98. () =>
  99. {
  100. ShowDetails ();
  101. return true;
  102. }
  103. );
  104. KeyBindings.Add (Key.CursorUp, Command.Up);
  105. KeyBindings.Add (Key.CursorDown, Command.Down);
  106. KeyBindings.Add (Key.CursorLeft, Command.Left);
  107. KeyBindings.Add (Key.CursorRight, Command.Right);
  108. KeyBindings.Add (Key.PageUp, Command.PageUp);
  109. KeyBindings.Add (Key.PageDown, Command.PageDown);
  110. KeyBindings.Add (Key.Home, Command.Start);
  111. KeyBindings.Add (Key.End, Command.End);
  112. MouseClick += Handle_MouseClick;
  113. SetContentSize (new (COLUMN_WIDTH * 16 + RowLabelWidth, MAX_CODE_POINT / 16 * _rowHeight + HEADER_HEIGHT));
  114. // Set up the horizontal scrollbar. Turn off AutoShow since we do it manually.
  115. HorizontalScrollBar.AutoShow = false;
  116. HorizontalScrollBar.Increment = COLUMN_WIDTH;
  117. // This prevents scrolling past the last column
  118. HorizontalScrollBar.ScrollableContentSize = GetContentSize ().Width - RowLabelWidth;
  119. HorizontalScrollBar.X = RowLabelWidth;
  120. HorizontalScrollBar.Y = Pos.AnchorEnd ();
  121. HorizontalScrollBar.Width = Dim.Fill (1);
  122. // We want the horizontal scrollbar to only show when needed.
  123. // We can't use ScrollBar.AutoShow because we are using custom ContentSize
  124. // So, we do it manually on ViewportChanged events.
  125. ViewportChanged += (sender, args) =>
  126. {
  127. if (Viewport.Width < GetContentSize ().Width)
  128. {
  129. HorizontalScrollBar.Visible = true;
  130. }
  131. else
  132. {
  133. HorizontalScrollBar.Visible = false;
  134. }
  135. };
  136. // Set up the vertical scrollbar. Turn off AutoShow since it's always visible.
  137. VerticalScrollBar.AutoShow = false;
  138. VerticalScrollBar.Visible = true; // Force always visible
  139. VerticalScrollBar.X = Pos.AnchorEnd ();
  140. VerticalScrollBar.Y = HEADER_HEIGHT; // Header
  141. }
  142. private void ScrollToMakeCursorVisible (Point offsetToNewCursor)
  143. {
  144. // Adjust vertical scrolling
  145. if (offsetToNewCursor.Y < 1) // Header is at Y = 0
  146. {
  147. ScrollVertical (offsetToNewCursor.Y - HEADER_HEIGHT);
  148. }
  149. else if (offsetToNewCursor.Y >= Viewport.Height)
  150. {
  151. ScrollVertical (offsetToNewCursor.Y - Viewport.Height + HEADER_HEIGHT);
  152. }
  153. // Adjust horizontal scrolling
  154. if (offsetToNewCursor.X < RowLabelWidth + 1)
  155. {
  156. ScrollHorizontal (offsetToNewCursor.X - (RowLabelWidth + 1));
  157. }
  158. else if (offsetToNewCursor.X >= Viewport.Width)
  159. {
  160. ScrollHorizontal (offsetToNewCursor.X - Viewport.Width + 1);
  161. }
  162. }
  163. #region Cursor
  164. private Point GetCursor (int codePoint)
  165. {
  166. // + 1 for padding between label and first column
  167. int x = codePoint % 16 * COLUMN_WIDTH + RowLabelWidth + 1 - Viewport.X;
  168. int y = codePoint / 16 * _rowHeight + HEADER_HEIGHT - Viewport.Y;
  169. return new (x, y);
  170. }
  171. public override Point? PositionCursor ()
  172. {
  173. Point cursor = GetCursor (SelectedCodePoint);
  174. if (HasFocus
  175. && cursor.X >= RowLabelWidth
  176. && cursor.X < Viewport.Width
  177. && cursor.Y > 0
  178. && cursor.Y < Viewport.Height)
  179. {
  180. Move (cursor.X, cursor.Y);
  181. }
  182. else
  183. {
  184. return null;
  185. }
  186. return cursor;
  187. }
  188. #endregion Cursor
  189. // ReSharper disable once InconsistentNaming
  190. private static readonly int MAX_CODE_POINT = UnicodeRange.Ranges.Max (r => r.End);
  191. private int _selectedCodepoint; // Currently selected codepoint
  192. private int _startCodepoint; // The codepoint that will be displayed at the top of the Viewport
  193. /// <summary>
  194. /// Gets or sets the currently selected codepoint. Causes the Viewport to scroll to make the selected code point
  195. /// visible.
  196. /// </summary>
  197. public int SelectedCodePoint
  198. {
  199. get => _selectedCodepoint;
  200. set
  201. {
  202. if (_selectedCodepoint == value)
  203. {
  204. return;
  205. }
  206. int newSelectedCodePoint = Math.Clamp (value, 0, MAX_CODE_POINT);
  207. Point offsetToNewCursor = GetCursor (newSelectedCodePoint);
  208. _selectedCodepoint = newSelectedCodePoint;
  209. // Ensure the new cursor position is visible
  210. ScrollToMakeCursorVisible (offsetToNewCursor);
  211. SetNeedsDraw ();
  212. SelectedCodePointChanged?.Invoke (this, new (SelectedCodePoint));
  213. }
  214. }
  215. /// <summary>
  216. /// Raised when the selected code point changes.
  217. /// </summary>
  218. public event EventHandler<EventArgs<int>>? SelectedCodePointChanged;
  219. /// <summary>
  220. /// Specifies the starting offset for the character map. The default is 0x2500 which is the Box Drawing
  221. /// characters.
  222. /// </summary>
  223. public int StartCodePoint
  224. {
  225. get => _startCodepoint;
  226. set
  227. {
  228. _startCodepoint = value;
  229. SelectedCodePoint = value;
  230. }
  231. }
  232. /// <summary>
  233. /// Gets or sets whether the number of columns each glyph is displayed.
  234. /// </summary>
  235. public bool ShowGlyphWidths
  236. {
  237. get => _rowHeight == 2;
  238. set
  239. {
  240. _rowHeight = value ? 2 : 1;
  241. SetNeedsDraw ();
  242. }
  243. }
  244. private void CopyCodePoint () { Clipboard.Contents = $"U+{SelectedCodePoint:x5}"; }
  245. private void CopyGlyph () { Clipboard.Contents = $"{new Rune (SelectedCodePoint)}"; }
  246. #region Drawing
  247. private static int RowLabelWidth => $"U+{MAX_CODE_POINT:x5}".Length + 1;
  248. protected override bool OnDrawingContent ()
  249. {
  250. if (Viewport.Height == 0 || Viewport.Width == 0)
  251. {
  252. return true;
  253. }
  254. int cursorCol = GetCursor (SelectedCodePoint).X + Viewport.X - RowLabelWidth - 1;
  255. int cursorRow = GetCursor (SelectedCodePoint).Y + Viewport.Y - 1;
  256. SetAttribute (GetHotNormalColor ());
  257. Move (0, 0);
  258. AddStr (new (' ', RowLabelWidth + 1));
  259. int firstColumnX = RowLabelWidth - Viewport.X;
  260. // Header
  261. for (var hexDigit = 0; hexDigit < 16; hexDigit++)
  262. {
  263. int x = firstColumnX + hexDigit * COLUMN_WIDTH;
  264. if (x > RowLabelWidth - 2)
  265. {
  266. Move (x, 0);
  267. SetAttribute (GetHotNormalColor ());
  268. AddStr (" ");
  269. SetAttribute (HasFocus && cursorCol + firstColumnX == x ? GetHotFocusColor () : GetHotNormalColor ());
  270. AddStr ($"{hexDigit:x}");
  271. SetAttribute (GetHotNormalColor ());
  272. AddStr (" ");
  273. }
  274. }
  275. // Start at 1 because Header.
  276. for (var y = 1; y < Viewport.Height; y++)
  277. {
  278. // What row is this?
  279. int row = (y + Viewport.Y - 1) / _rowHeight;
  280. int val = row * 16;
  281. if (val > MAX_CODE_POINT)
  282. {
  283. break;
  284. }
  285. Move (firstColumnX + COLUMN_WIDTH, y);
  286. SetAttribute (GetNormalColor ());
  287. for (var col = 0; col < 16; col++)
  288. {
  289. int x = firstColumnX + COLUMN_WIDTH * col + 1;
  290. if (x < 0 || x > Viewport.Width - 1)
  291. {
  292. continue;
  293. }
  294. Move (x, y);
  295. // If we're at the cursor position, and we don't have focus, invert the colors.
  296. if (row == cursorRow && x == cursorCol && !HasFocus)
  297. {
  298. SetAttribute (GetFocusColor ());
  299. }
  300. int scalar = val + col;
  301. var rune = (Rune)'?';
  302. if (Rune.IsValid (scalar))
  303. {
  304. rune = new (scalar);
  305. }
  306. int width = rune.GetColumns ();
  307. if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
  308. {
  309. // Draw the rune
  310. if (width > 0)
  311. {
  312. AddRune (rune);
  313. }
  314. else
  315. {
  316. if (rune.IsCombiningMark ())
  317. {
  318. // This is a hack to work around the fact that combining marks
  319. // a) can't be rendered on their own
  320. // b) that don't normalize are not properly supported in
  321. // any known terminal (esp Windows/AtlasEngine).
  322. // See Issue #2616
  323. var sb = new StringBuilder ();
  324. sb.Append ('a');
  325. sb.Append (rune);
  326. // Try normalizing after combining with 'a'. If it normalizes, at least
  327. // it'll show on the 'a'. If not, just show the replacement char.
  328. string normal = sb.ToString ().Normalize (NormalizationForm.FormC);
  329. if (normal.Length == 1)
  330. {
  331. AddRune ((Rune)normal [0]);
  332. }
  333. else
  334. {
  335. AddRune (Rune.ReplacementChar);
  336. }
  337. }
  338. }
  339. }
  340. else
  341. {
  342. // Draw the width of the rune
  343. SetAttribute (GetHotNormalColor ());
  344. AddStr ($"{width}");
  345. }
  346. // If we're at the cursor position, and we don't have focus, revert the colors to normal
  347. if (row == cursorRow && x == cursorCol && !HasFocus)
  348. {
  349. SetAttribute (GetNormalColor ());
  350. }
  351. }
  352. // Draw row label (U+XXXX_)
  353. Move (0, y);
  354. SetAttribute (HasFocus && y + Viewport.Y - 1 == cursorRow ? GetHotFocusColor () : GetHotNormalColor ());
  355. if (!ShowGlyphWidths || (y + Viewport.Y) % _rowHeight > 0)
  356. {
  357. AddStr ($"U+{val / 16:x5}_ ");
  358. }
  359. else
  360. {
  361. AddStr (new (' ', RowLabelWidth));
  362. }
  363. }
  364. return true;
  365. }
  366. /// <summary>
  367. /// Helper to convert a string into camel case.
  368. /// </summary>
  369. /// <param name="str"></param>
  370. /// <returns></returns>
  371. public static string ToCamelCase (string str)
  372. {
  373. if (string.IsNullOrEmpty (str))
  374. {
  375. return str;
  376. }
  377. TextInfo textInfo = new CultureInfo ("en-US", false).TextInfo;
  378. str = textInfo.ToLower (str);
  379. str = textInfo.ToTitleCase (str);
  380. return str;
  381. }
  382. #endregion Drawing
  383. #region Mouse Handling
  384. // TODO: Use this to demonstrate using a popover to show glyph info on hover
  385. public event EventHandler<ListViewItemEventArgs>? Hover;
  386. /// <inheritdoc />
  387. protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
  388. {
  389. if (mouseEvent.Flags == MouseFlags.WheeledDown)
  390. {
  391. if (Viewport.Y + Viewport.Height - HEADER_HEIGHT < GetContentSize ().Height)
  392. {
  393. ScrollVertical (1);
  394. }
  395. return mouseEvent.Handled = true;
  396. }
  397. if (mouseEvent.Flags == MouseFlags.WheeledUp)
  398. {
  399. ScrollVertical (-1);
  400. return mouseEvent.Handled = true;
  401. }
  402. if (mouseEvent.Flags == MouseFlags.WheeledRight)
  403. {
  404. if (Viewport.X + Viewport.Width < GetContentSize ().Width)
  405. {
  406. ScrollHorizontal (1);
  407. }
  408. return mouseEvent.Handled = true;
  409. }
  410. if (mouseEvent.Flags == MouseFlags.WheeledLeft)
  411. {
  412. ScrollHorizontal (-1);
  413. return mouseEvent.Handled = true;
  414. }
  415. return false;
  416. }
  417. private void Handle_MouseClick (object? sender, MouseEventArgs me)
  418. {
  419. if (me.Flags != MouseFlags.ReportMousePosition && me.Flags != MouseFlags.Button1Clicked && me.Flags != MouseFlags.Button1DoubleClicked)
  420. {
  421. return;
  422. }
  423. if (me.Position.Y == 0)
  424. {
  425. me.Position = me.Position with { Y = GetCursor (SelectedCodePoint).Y };
  426. }
  427. if (me.Position.X < RowLabelWidth || me.Position.X > RowLabelWidth + 16 * COLUMN_WIDTH - 1)
  428. {
  429. me.Position = me.Position with { X = GetCursor (SelectedCodePoint).X };
  430. }
  431. int row = (me.Position.Y - 1 - -Viewport.Y) / _rowHeight; // -1 for header
  432. int col = (me.Position.X - RowLabelWidth - -Viewport.X) / COLUMN_WIDTH;
  433. if (col > 15)
  434. {
  435. col = 15;
  436. }
  437. int val = row * 16 + col;
  438. if (val > MAX_CODE_POINT)
  439. {
  440. return;
  441. }
  442. if (me.Flags == MouseFlags.ReportMousePosition)
  443. {
  444. Hover?.Invoke (this, new (val, null));
  445. }
  446. if (!HasFocus && CanFocus)
  447. {
  448. SetFocus ();
  449. }
  450. me.Handled = true;
  451. if (me.Flags == MouseFlags.Button1Clicked)
  452. {
  453. SelectedCodePoint = val;
  454. return;
  455. }
  456. if (me.Flags == MouseFlags.Button1DoubleClicked)
  457. {
  458. SelectedCodePoint = val;
  459. ShowDetails ();
  460. return;
  461. }
  462. if (me.Flags == _contextMenu.MouseFlags)
  463. {
  464. SelectedCodePoint = val;
  465. _contextMenu = new ()
  466. {
  467. Position = new (me.Position.X + 1, me.Position.Y + 1)
  468. };
  469. MenuBarItem menuItems = new (
  470. new MenuItem []
  471. {
  472. new (
  473. "_Copy Glyph",
  474. "",
  475. CopyGlyph,
  476. null,
  477. null,
  478. (KeyCode)Key.C.WithCtrl
  479. ),
  480. new (
  481. "Copy Code _Point",
  482. "",
  483. CopyCodePoint,
  484. null,
  485. null,
  486. (KeyCode)Key.C.WithCtrl
  487. .WithShift
  488. )
  489. }
  490. );
  491. _contextMenu.Show (menuItems);
  492. }
  493. }
  494. #endregion Mouse Handling
  495. #region Details Dialog
  496. private void ShowDetails ()
  497. {
  498. UcdApiClient? client = new ();
  499. var decResponse = string.Empty;
  500. var getCodePointError = string.Empty;
  501. Dialog? waitIndicator = new ()
  502. {
  503. Title = "Getting Code Point Information",
  504. X = Pos.Center (),
  505. Y = Pos.Center (),
  506. Width = 40,
  507. Height = 10,
  508. Buttons = [new () { Text = "_Cancel" }]
  509. };
  510. var errorLabel = new Label
  511. {
  512. Text = UcdApiClient.BaseUrl,
  513. X = 0,
  514. Y = 0,
  515. Width = Dim.Fill (),
  516. Height = Dim.Fill (3),
  517. TextAlignment = Alignment.Center
  518. };
  519. var spinner = new SpinnerView
  520. {
  521. X = Pos.Center (),
  522. Y = Pos.Bottom (errorLabel),
  523. Style = new SpinnerStyle.Aesthetic ()
  524. };
  525. spinner.AutoSpin = true;
  526. waitIndicator.Add (errorLabel);
  527. waitIndicator.Add (spinner);
  528. waitIndicator.Ready += async (s, a) =>
  529. {
  530. try
  531. {
  532. decResponse = await client.GetCodepointDec (SelectedCodePoint);
  533. Application.Invoke (() => waitIndicator.RequestStop ());
  534. }
  535. catch (HttpRequestException e)
  536. {
  537. getCodePointError = errorLabel.Text = e.Message;
  538. Application.Invoke (() => waitIndicator.RequestStop ());
  539. }
  540. };
  541. Application.Run (waitIndicator);
  542. waitIndicator.Dispose ();
  543. if (!string.IsNullOrEmpty (decResponse))
  544. {
  545. var name = string.Empty;
  546. using (JsonDocument document = JsonDocument.Parse (decResponse))
  547. {
  548. JsonElement root = document.RootElement;
  549. // Get a property by name and output its value
  550. if (root.TryGetProperty ("name", out JsonElement nameElement))
  551. {
  552. name = nameElement.GetString ();
  553. }
  554. //// Navigate to a nested property and output its value
  555. //if (root.TryGetProperty ("property3", out JsonElement property3Element)
  556. //&& property3Element.TryGetProperty ("nestedProperty", out JsonElement nestedPropertyElement)) {
  557. // Console.WriteLine (nestedPropertyElement.GetString ());
  558. //}
  559. decResponse = JsonSerializer.Serialize (
  560. document.RootElement,
  561. new
  562. JsonSerializerOptions
  563. { WriteIndented = true }
  564. );
  565. }
  566. var title = $"{ToCamelCase (name!)} - {new Rune (SelectedCodePoint)} U+{SelectedCodePoint:x5}";
  567. Button? copyGlyph = new () { Text = "Copy _Glyph" };
  568. Button? copyCodepoint = new () { Text = "Copy Code _Point" };
  569. Button? cancel = new () { Text = "Cancel" };
  570. var dlg = new Dialog { Title = title, Buttons = [copyGlyph, copyCodepoint, cancel] };
  571. copyGlyph.Accepting += (s, a) =>
  572. {
  573. CopyGlyph ();
  574. dlg!.RequestStop ();
  575. };
  576. copyCodepoint.Accepting += (s, a) =>
  577. {
  578. CopyCodePoint ();
  579. dlg!.RequestStop ();
  580. };
  581. cancel.Accepting += (s, a) => dlg!.RequestStop ();
  582. var rune = (Rune)SelectedCodePoint;
  583. var label = new Label { Text = "IsAscii: ", X = 0, Y = 0 };
  584. dlg.Add (label);
  585. label = new () { Text = $"{rune.IsAscii}", X = Pos.Right (label), Y = Pos.Top (label) };
  586. dlg.Add (label);
  587. label = new () { Text = ", Bmp: ", X = Pos.Right (label), Y = Pos.Top (label) };
  588. dlg.Add (label);
  589. label = new () { Text = $"{rune.IsBmp}", X = Pos.Right (label), Y = Pos.Top (label) };
  590. dlg.Add (label);
  591. label = new () { Text = ", CombiningMark: ", X = Pos.Right (label), Y = Pos.Top (label) };
  592. dlg.Add (label);
  593. label = new () { Text = $"{rune.IsCombiningMark ()}", X = Pos.Right (label), Y = Pos.Top (label) };
  594. dlg.Add (label);
  595. label = new () { Text = ", SurrogatePair: ", X = Pos.Right (label), Y = Pos.Top (label) };
  596. dlg.Add (label);
  597. label = new () { Text = $"{rune.IsSurrogatePair ()}", X = Pos.Right (label), Y = Pos.Top (label) };
  598. dlg.Add (label);
  599. label = new () { Text = ", Plane: ", X = Pos.Right (label), Y = Pos.Top (label) };
  600. dlg.Add (label);
  601. label = new () { Text = $"{rune.Plane}", X = Pos.Right (label), Y = Pos.Top (label) };
  602. dlg.Add (label);
  603. label = new () { Text = "Columns: ", X = 0, Y = Pos.Bottom (label) };
  604. dlg.Add (label);
  605. label = new () { Text = $"{rune.GetColumns ()}", X = Pos.Right (label), Y = Pos.Top (label) };
  606. dlg.Add (label);
  607. label = new () { Text = ", Utf16SequenceLength: ", X = Pos.Right (label), Y = Pos.Top (label) };
  608. dlg.Add (label);
  609. label = new () { Text = $"{rune.Utf16SequenceLength}", X = Pos.Right (label), Y = Pos.Top (label) };
  610. dlg.Add (label);
  611. label = new ()
  612. {
  613. Text =
  614. $"Code Point Information from {UcdApiClient.BaseUrl}codepoint/dec/{SelectedCodePoint}:",
  615. X = 0,
  616. Y = Pos.Bottom (label)
  617. };
  618. dlg.Add (label);
  619. var json = new TextView
  620. {
  621. X = 0,
  622. Y = Pos.Bottom (label),
  623. Width = Dim.Fill (),
  624. Height = Dim.Fill (2),
  625. ReadOnly = true,
  626. Text = decResponse
  627. };
  628. dlg.Add (json);
  629. Application.Run (dlg);
  630. dlg.Dispose ();
  631. }
  632. else
  633. {
  634. MessageBox.ErrorQuery (
  635. "Code Point API",
  636. $"{UcdApiClient.BaseUrl}codepoint/dec/{SelectedCodePoint} did not return a result for\r\n {new Rune (SelectedCodePoint)} U+{SelectedCodePoint:x5}.",
  637. "_Ok"
  638. );
  639. }
  640. // BUGBUG: This is a workaround for some weird ScrollView related mouse grab bug
  641. Application.GrabMouse (this);
  642. }
  643. #endregion Details Dialog
  644. }