Unicode.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using NStack;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Terminal.Gui;
  5. namespace UICatalog {
  6. [ScenarioMetadata (Name: "Unicode", Description: "Tries to test Unicode in all controls (#204)")]
  7. [ScenarioCategory ("Text")]
  8. [ScenarioCategory ("Controls")]
  9. class UnicodeInMenu : Scenario {
  10. public override void Setup ()
  11. {
  12. const string IdenticalSign = "\u2261";
  13. const string ArrowUpSign = "\u2191";
  14. const string ArrowDownSign = "\u2193";
  15. const string EllipsesSign = "\u2026";
  16. const string StashSign = "\u205E";
  17. //string text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line.";
  18. string unicode = "Τὴ γλῶσσα μοῦ ἔδωσαν ἑλληνικὴ\nτὸ σπίτι φτωχικὸ στὶς ἀμμουδιὲς τοῦ Ὁμήρου.\nΜονάχη ἔγνοια ἡ γλῶσσα μου στὶς ἀμμουδιὲς τοῦ Ὁμήρου.";
  19. string gitString = $"gui.cs master {IdenticalSign} {ArrowDownSign}18 {ArrowUpSign}10 {StashSign}1 {EllipsesSign}";
  20. var menu = new MenuBar (new MenuBarItem [] {
  21. new MenuBarItem ("_Файл", new MenuItem [] {
  22. new MenuItem ("_Создать", "Creates new file", null),
  23. new MenuItem ("_Открыть", "", null),
  24. new MenuItem ("Со_хранить", "", null),
  25. new MenuItem ("_Выход", "", () => Application.RequestStop() )
  26. }),
  27. new MenuBarItem ("_Edit", new MenuItem [] {
  28. new MenuItem ("_Copy", "", null),
  29. new MenuItem ("C_ut", "", null),
  30. new MenuItem ("_Paste", "", null)
  31. })
  32. });
  33. Top.Add (menu);
  34. var statusBar = new StatusBar (new StatusItem [] {
  35. new StatusItem (Key.ControlQ, "~^Q~ Выход", () => Application.RequestStop()),
  36. new StatusItem (Key.Unknown, "~F2~ Создать", null),
  37. new StatusItem(Key.Unknown, "~F3~ Со_хранить", null),
  38. });
  39. Top.Add (statusBar);
  40. var label = new Label ("Label:") { X = 0, Y = 1 };
  41. Win.Add (label);
  42. var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
  43. Win.Add (testlabel);
  44. label = new Label ("Label (CanFocus):") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  45. Win.Add (label);
  46. testlabel = new Label ("Стоял &он, дум великих полн") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), CanFocus = true, HotKeySpecifier = new System.Rune('&') };
  47. Win.Add (testlabel);
  48. label = new Label ("Button:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  49. Win.Add (label);
  50. var button = new Button ("A123456789♥♦♣♠JQK") { X = 20, Y = Pos.Y (label) };
  51. Win.Add (button);
  52. label = new Label ("CheckBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  53. Win.Add (label);
  54. var checkBox = new CheckBox (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
  55. Win.Add (checkBox);
  56. // BUGBUG: Combobox does not deal with unicode properly.
  57. #if false
  58. label = new Label ("ComboBox:") { X = Pos.X (label), Y = Pos.Bottom (label) + 1 };
  59. Win.Add (label);
  60. var comboBox = new ComboBox () {
  61. X = 20,
  62. Y = Pos.Y (label),
  63. Width = Dim.Percent (50),
  64. };
  65. comboBox.SetSource (new List<string> () { gitString, "Со_хранить" });
  66. Win.Add (comboBox);
  67. comboBox.Text = gitString;
  68. #endif
  69. label = new Label ("HexView:") { X = Pos.X (label), Y = Pos.Bottom (label) + 2 };
  70. Win.Add (label);
  71. var hexView = new HexView (new System.IO.MemoryStream (Encoding.ASCII.GetBytes (gitString + " Со_хранить"))) {
  72. X = 20,
  73. Y = Pos.Y (label),
  74. Width = Dim.Percent (60),
  75. Height = 5
  76. };
  77. Win.Add (hexView);
  78. label = new Label ("ListView:") { X = Pos.X (label), Y = Pos.Bottom (hexView) + 1 };
  79. Win.Add (label);
  80. var listView = new ListView (new List<string> () { "item #1", gitString, "Со_хранить", unicode }) {
  81. X = 20,
  82. Y = Pos.Y (label),
  83. Width = Dim.Percent (60),
  84. Height = 3,
  85. };
  86. Win.Add (listView);
  87. label = new Label ("RadioGroup:") { X = Pos.X (label), Y = Pos.Bottom (listView) + 1 };
  88. Win.Add (label);
  89. var radioGroup = new RadioGroup (new ustring [] { "item #1", gitString, "Со_хранить" }, selected: 0) {
  90. X = 20,
  91. Y = Pos.Y (label),
  92. Width = Dim.Percent (60),
  93. };
  94. Win.Add (radioGroup);
  95. label = new Label ("TextField:") { X = Pos.X (label), Y = Pos.Bottom (radioGroup) + 1 };
  96. Win.Add (label);
  97. var textField = new TextField (gitString + " = Со_хранить") { X = 20, Y = Pos.Y (label), Width = Dim.Percent (60) };
  98. Win.Add (textField);
  99. label = new Label ("TextView:") { X = Pos.X (label), Y = Pos.Bottom (textField) + 1 };
  100. Win.Add (label);
  101. var textView = new TextView () {
  102. X = 20,
  103. Y = Pos.Y (label),
  104. Width = Dim.Percent (60),
  105. Height = 5,
  106. Text = unicode,
  107. };
  108. Win.Add (textView);
  109. }
  110. }
  111. }