Unicode.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using System.Collections.ObjectModel;
  2. using System.IO;
  3. using System.Text;
  4. using Terminal.Gui;
  5. namespace UICatalog.Scenarios;
  6. [ScenarioMetadata ("Unicode", "Tries to test Unicode in all controls (#204)")]
  7. [ScenarioCategory ("Text and Formatting")]
  8. [ScenarioCategory ("Controls")]
  9. public class UnicodeInMenu : Scenario
  10. {
  11. public override void Main ()
  12. {
  13. var unicode =
  14. "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
  15. var gitString =
  16. $"gui.cs 糊 (hú) {
  17. CM.Glyphs.IdenticalTo
  18. } {
  19. CM.Glyphs.DownArrow
  20. }18 {
  21. CM.Glyphs.UpArrow
  22. }10 {
  23. CM.Glyphs.VerticalFourDots
  24. }1 {
  25. CM.Glyphs.HorizontalEllipsis
  26. }";
  27. // Init
  28. Application.Init ();
  29. // Setup - Create a top-level application window and configure it.
  30. Window appWindow = new ()
  31. {
  32. Title = GetQuitKeyAndName ()
  33. };
  34. var menu = new MenuBar
  35. {
  36. Menus =
  37. [
  38. new (
  39. "_Файл",
  40. new MenuItem []
  41. {
  42. new (
  43. "_Создать",
  44. "Creates new file",
  45. null
  46. ),
  47. new ("_Открыть", "", null),
  48. new ("Со_хранить", "", null),
  49. new (
  50. "_Выход",
  51. "",
  52. () => Application.RequestStop ()
  53. )
  54. }
  55. ),
  56. new (
  57. "_Edit",
  58. new MenuItem []
  59. {
  60. new ("_Copy", "", null), new ("C_ut", "", null),
  61. new ("_糊", "hú (Paste)", null)
  62. }
  63. )
  64. ]
  65. };
  66. appWindow.Add (menu);
  67. var statusBar = new StatusBar (
  68. new Shortcut []
  69. {
  70. new (
  71. Application.QuitKey,
  72. "Выход",
  73. () => Application.RequestStop ()
  74. ),
  75. new (Key.F2, "Создать", null),
  76. new (Key.F3, "Со_хранить", null)
  77. }
  78. );
  79. appWindow.Add (statusBar);
  80. var label = new Label { X = 0, Y = 1, Text = "Label:" };
  81. appWindow.Add (label);
  82. var testlabel = new Label
  83. {
  84. X = 20,
  85. Y = Pos.Y (label),
  86. Width = Dim.Percent (50),
  87. Text = gitString
  88. };
  89. appWindow.Add (testlabel);
  90. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Label (CanFocus):" };
  91. appWindow.Add (label);
  92. var sb = new StringBuilder ();
  93. sb.Append ('e');
  94. sb.Append ('\u0301');
  95. sb.Append ('\u0301');
  96. testlabel = new ()
  97. {
  98. X = 20,
  99. Y = Pos.Y (label),
  100. Width = Dim.Percent (50),
  101. CanFocus = true,
  102. HotKeySpecifier = new ('&'),
  103. Text = $"Should be [e with two accents, but isn't due to #2616]: [{sb}]"
  104. };
  105. appWindow.Add (testlabel);
  106. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "Button:" };
  107. appWindow.Add (label);
  108. var button = new Button { X = 20, Y = Pos.Y (label), Text = "A123456789♥♦♣♠JQK" };
  109. appWindow.Add (button);
  110. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 1, Text = "CheckBox:" };
  111. appWindow.Add (label);
  112. var checkBox = new CheckBox
  113. {
  114. X = 20,
  115. Y = Pos.Y (label),
  116. Width = Dim.Percent (50),
  117. Height = 1,
  118. Text = gitString
  119. };
  120. var checkBoxRight = new CheckBox
  121. {
  122. X = 20,
  123. Y = Pos.Bottom (checkBox),
  124. Width = Dim.Percent (50),
  125. Height = 1,
  126. TextAlignment = Alignment.End,
  127. Text = $"End - {gitString}"
  128. };
  129. appWindow.Add (checkBox, checkBoxRight);
  130. label = new () { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1, Text = "ComboBox:" };
  131. appWindow.Add (label);
  132. var comboBox = new ComboBox { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  133. comboBox.SetSource (new ObservableCollection<string> { gitString, "Со_хранить" });
  134. appWindow.Add (comboBox);
  135. comboBox.Text = gitString;
  136. label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 2, Text = "HexView:" };
  137. appWindow.Add (label);
  138. var hexView = new HexView (new MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить")))
  139. {
  140. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Height = 5
  141. };
  142. appWindow.Add (hexView);
  143. label = new () { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1, Text = "ListView:" };
  144. appWindow.Add (label);
  145. var listView = new ListView
  146. {
  147. X = 20,
  148. Y = Pos.Y (label),
  149. Width = Dim.Percent (60),
  150. Height = 3,
  151. Source = new ListWrapper<string> (
  152. ["item #1", gitString, "Со_хранить", unicode]
  153. )
  154. };
  155. appWindow.Add (listView);
  156. label = new () { X = Pos.X (label), Y = Pos.Bottom (listView) + 1, Text = "RadioGroup:" };
  157. appWindow.Add (label);
  158. var radioGroup = new RadioGroup
  159. {
  160. X = 20,
  161. Y = Pos.Y (label),
  162. Width = Dim.Percent (60),
  163. RadioLabels = new [] { "item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ" }
  164. };
  165. appWindow.Add (radioGroup);
  166. label = new () { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1, Text = "TextField:" };
  167. appWindow.Add (label);
  168. var textField = new TextField
  169. {
  170. X = 20, Y = Pos.Y (label), Width = Dim.Percent (60), Text = gitString + " = Со_хранить"
  171. };
  172. appWindow.Add (textField);
  173. label = new () { X = Pos.X (label), Y = Pos.Bottom (textField) + 1, Text = "TextView:" };
  174. appWindow.Add (label);
  175. var textView = new TextView
  176. {
  177. X = 20,
  178. Y = Pos.Y (label),
  179. Width = Dim.Percent (60),
  180. Height = 5,
  181. Text = unicode
  182. };
  183. appWindow.Add (textView);
  184. // Run - Start the application.
  185. Application.Run (appWindow);
  186. appWindow.Dispose ();
  187. // Shutdown - Calling Application.Shutdown is required.
  188. Application.Shutdown ();
  189. }
  190. }