CharMap.cs 25 KB

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