CombiningMarks.cs 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. namespace UICatalog.Scenarios;
  2. [ScenarioMetadata ("Combining Marks", "Illustrates how Unicode Combining Marks work (or don't).")]
  3. [ScenarioCategory ("Text and Formatting")]
  4. public class CombiningMarks : Scenario
  5. {
  6. public override void Main ()
  7. {
  8. Application.Init ();
  9. var top = new Toplevel ();
  10. top.DrawComplete += (s, e) =>
  11. {
  12. // Forces reset _lineColsOffset because we're dealing with direct draw
  13. Application.Current!.SetNeedsDraw ();
  14. var i = -1;
  15. top.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");
  16. top.Move (0, ++i);
  17. top.AddStr ("\u0301<- \"\\u0301\" using AddStr.");
  18. top.Move (0, ++i);
  19. top.AddStr ("[\u0301]<- \"[\\u0301]\" using AddStr.");
  20. top.Move (0, ++i);
  21. top.AddStr ("[ \u0301]<- \"[ \\u0301]\" using AddStr.");
  22. top.Move (0, ++i);
  23. top.AddStr ("[\u0301 ]<- \"[\\u0301 ]\" using AddStr.");
  24. top.Move (0, ++i);
  25. top.AddStr ("\u0301\u0301\u0328<- \"\\u0301\\u0301\\u0328\" using AddStr.");
  26. top.Move (0, ++i);
  27. top.AddStr ("[\u0301\u0301\u0328]<- \"[\\u0301\\u0301\\u0328]\" using AddStr.");
  28. top.Move (0, ++i);
  29. top.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u0301\\u0301\\u0328]\" using AddStr.");
  30. top.Move (0, ++i);
  31. top.AddRune ('[');
  32. top.AddRune ('a');
  33. top.AddRune ('\u0301');
  34. top.AddRune ('\u0301');
  35. top.AddRune ('\u0328');
  36. top.AddRune (']');
  37. top.AddStr ("<- \"[a\\u0301\\u0301\\u0328]\" using AddRune for each.");
  38. top.Move (0, ++i);
  39. top.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u0301\\u0301\\u0328]\" using AddStr.");
  40. top.Move (0, ++i);
  41. top.AddStr ("[e\u0301\u0301\u0328]<- \"[e\\u0301\\u0301\\u0328]\" using AddStr.");
  42. top.Move (0, ++i);
  43. top.AddStr ("[e\u0328\u0301]<- \"[e\\u0328\\u0301]\" using AddStr.");
  44. top.Move (0, ++i);
  45. top.AddStr ("\u00ad<- \"\\u00ad\" using AddStr.");
  46. top.Move (0, ++i);
  47. top.AddStr ("[\u00ad]<- \"[\\u00ad]\" using AddStr.");
  48. top.Move (0, ++i);
  49. top.AddRune ('[');
  50. top.AddRune ('\u00ad');
  51. top.AddRune (']');
  52. top.AddStr ("<- \"[\\u00ad]\" using AddRune for each.");
  53. i++;
  54. top.Move (0, ++i);
  55. top.AddStr ("From now on we are using TextFormatter");
  56. TextFormatter tf = new () { Text = "[e\u0301\u0301\u0328]<- \"[e\\u0301\\u0301\\u0328]\" using TextFormatter." };
  57. tf.Draw (driver: Application.Driver, screen: new (0, ++i, tf.Text.Length, 1), normalColor: top.GetAttributeForRole (VisualRole.Normal), hotColor: top.GetAttributeForRole (VisualRole.Normal));
  58. tf.Text = "[e\u0328\u0301]<- \"[e\\u0328\\u0301]\" using TextFormatter.";
  59. tf.Draw (driver: Application.Driver, screen: new (0, ++i, tf.Text.Length, 1), normalColor: top.GetAttributeForRole (VisualRole.Normal), hotColor: top.GetAttributeForRole (VisualRole.Normal));
  60. i++;
  61. top.Move (0, ++i);
  62. top.AddStr ("From now on we are using Surrogate pairs with combining diacritics");
  63. top.Move (0, ++i);
  64. top.AddStr ("[\ud835\udc4b\u0302]<- \"[\\ud835\\udc4b\\u0302]\" using AddStr.");
  65. top.Move (0, ++i);
  66. top.AddStr ("[\ud83d\udc68\ud83e\uddd2]<- \"[\\ud83d\\udc68\\ud83e\\uddd2]\" using AddStr.");
  67. top.Move (0, ++i);
  68. top.AddStr ("\u200d<- \"\\u200d\" using AddStr.");
  69. top.Move (0, ++i);
  70. top.AddStr ("[\u200d]<- \"[\\u200d]\" using AddStr.");
  71. top.Move (0, ++i);
  72. top.AddStr ("[\ud83d\udc68\u200d\ud83e\uddd2]<- \"[\\ud83d\\udc68\\u200d\\ud83e\\uddd2]\" using AddStr.");
  73. top.Move (0, ++i);
  74. top.AddStr ("[\U0001F469\U0001F9D2]<- \"[\\U0001F469\\U0001F9D2]\" using AddStr.");
  75. top.Move (0, ++i);
  76. top.AddStr ("[\U0001F469\u200D\U0001F9D2]<- \"[\\U0001F469\\u200D\\U0001F9D2]\" using AddStr.");
  77. top.Move (0, ++i);
  78. top.AddStr ("[\U0001F468\U0001F469\U0001F9D2]<- \"[\\U0001F468\\U0001F469\\U0001F9D2]\" using AddStr.");
  79. top.Move (0, ++i);
  80. top.AddStr ("[\U0001F468\u200D\U0001F469\u200D\U0001F9D2]<- \"[\\U0001F468\\u200D\\U0001F469\\u200D\\U0001F9D2]\" using AddStr.");
  81. };
  82. Application.Run (top);
  83. top.Dispose ();
  84. Application.Shutdown ();
  85. }
  86. }