CharMap.cs 25 KB

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