CombiningMarks.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 Runnable ();
  10. top.DrawingContent += (s, e) =>
  11. {
  12. var i = -1;
  13. top.Move (0, ++i);
  14. top.AddStr ("Terminal.Gui supports all combining sequences that can be rendered as an unique grapheme.");
  15. top.Move (0, ++i);
  16. top.AddStr ("\u0301<- \"\\u0301\" using AddStr.");
  17. top.Move (0, ++i);
  18. top.AddStr ("[\u0301]<- \"[\\u0301]\" using AddStr.");
  19. top.Move (0, ++i);
  20. top.AddStr ("[ \u0301]<- \"[ \\u0301]\" using AddStr.");
  21. top.Move (0, ++i);
  22. top.AddStr ("[\u0301 ]<- \"[\\u0301 ]\" using AddStr.");
  23. top.Move (0, ++i);
  24. top.AddStr ("\u0301\u0301\u0328<- \"\\u0301\\u0301\\u0328\" using AddStr.");
  25. top.Move (0, ++i);
  26. top.AddStr ("[\u0301\u0301\u0328]<- \"[\\u0301\\u0301\\u0328]\" using AddStr.");
  27. top.Move (0, ++i);
  28. top.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u0301\\u0301\\u0328]\" using AddStr.");
  29. top.Move (0, ++i);
  30. top.AddRune ('[');
  31. top.AddRune ('a');
  32. top.AddRune ('\u0301');
  33. top.AddRune ('\u0301');
  34. top.AddRune ('\u0328');
  35. top.AddRune (']');
  36. top.AddStr ("<- \"[a\\u0301\\u0301\\u0328]\" using AddRune for each. Avoid use AddRune for combining sequences because may result with empty blocks at end.");
  37. top.Move (0, ++i);
  38. top.AddStr ("[a\u0301\u0301\u0328]<- \"[a\\u0301\\u0301\\u0328]\" using AddStr.");
  39. top.Move (0, ++i);
  40. top.AddStr ("[e\u0301\u0301\u0328]<- \"[e\\u0301\\u0301\\u0328]\" using AddStr.");
  41. top.Move (0, ++i);
  42. top.AddStr ("[e\u0328\u0301]<- \"[e\\u0328\\u0301]\" using AddStr.");
  43. top.Move (0, ++i);
  44. top.AddStr ("\u00ad<- \"\\u00ad\" using AddStr.");
  45. top.Move (0, ++i);
  46. top.AddStr ("[\u00ad]<- \"[\\u00ad]\" using AddStr.");
  47. top.Move (0, ++i);
  48. top.AddRune ('[');
  49. top.AddRune ('\u00ad');
  50. top.AddRune (']');
  51. top.AddStr ("<- \"[\\u00ad]\" using AddRune for each.");
  52. i++;
  53. top.Move (0, ++i);
  54. top.AddStr ("From now on we are using TextFormatter");
  55. TextFormatter tf = new () { Text = "[e\u0301\u0301\u0328]<- \"[e\\u0301\\u0301\\u0328]\" using TextFormatter." };
  56. tf.Draw (driver: Application.Driver, screen: new (0, ++i, tf.Text.Length, 1), normalColor: top.GetAttributeForRole (VisualRole.Normal), hotColor: top.GetAttributeForRole (VisualRole.Normal));
  57. tf.Text = "[e\u0328\u0301]<- \"[e\\u0328\\u0301]\" using TextFormatter.";
  58. tf.Draw (driver: Application.Driver, screen: new (0, ++i, tf.Text.Length, 1), normalColor: top.GetAttributeForRole (VisualRole.Normal), hotColor: top.GetAttributeForRole (VisualRole.Normal));
  59. i++;
  60. top.Move (0, ++i);
  61. top.AddStr ("From now on we are using Surrogate pairs with combining diacritics");
  62. top.Move (0, ++i);
  63. top.AddStr ("[\ud835\udc4b\u0302]<- \"[\\ud835\\udc4b\\u0302]\" using AddStr.");
  64. top.Move (0, ++i);
  65. top.AddStr ("[\ud83d\udc68\ud83e\uddd2]<- \"[\\ud83d\\udc68\\ud83e\\uddd2]\" using AddStr.");
  66. top.Move (0, ++i);
  67. top.AddStr ("\u200d<- \"\\u200d\" using AddStr.");
  68. top.Move (0, ++i);
  69. top.AddStr ("[\u200d]<- \"[\\u200d]\" using AddStr.");
  70. top.Move (0, ++i);
  71. top.AddStr ("[\ud83d\udc68\u200d\ud83e\uddd2]<- \"[\\ud83d\\udc68\\u200d\\ud83e\\uddd2]\" using AddStr.");
  72. top.Move (0, ++i);
  73. top.AddStr ("[\U0001F469\U0001F9D2]<- \"[\\U0001F469\\U0001F9D2]\" using AddStr.");
  74. top.Move (0, ++i);
  75. top.AddStr ("[\U0001F469\u200D\U0001F9D2]<- \"[\\U0001F469\\u200D\\U0001F9D2]\" using AddStr.");
  76. top.Move (0, ++i);
  77. top.AddStr ("[\U0001F468\U0001F469\U0001F9D2]<- \"[\\U0001F468\\U0001F469\\U0001F9D2]\" using AddStr.");
  78. top.Move (0, ++i);
  79. top.AddStr ("[\U0001F468\u200D\U0001F469\u200D\U0001F9D2]<- \"[\\U0001F468\\u200D\\U0001F469\\u200D\\U0001F9D2]\" using AddStr.");
  80. top.Move (0, ++i);
  81. top.AddStr ("[\U0001F468\u200D\U0001F469\u200D\U0001F467\u200D\U0001F466]<- \"[\\U0001F468\\u200D\\U0001F469\\u200D\\U0001F467\\u200D\\U0001F466]\" using AddStr.");
  82. top.Move (0, ++i);
  83. top.AddStr ("[\u0e32\u0e33]<- \"[\\u0e32\\u0e33]\" using AddStr.");
  84. top.Move (0, ++i);
  85. top.AddStr ("[\U0001F469\u200D\u2764\uFE0F\u200D\U0001F48B\u200D\U0001F468]<- \"[\\U0001F469\\u200D\\u2764\\uFE0F\\u200D\\U0001F48B\\u200D\\U0001F468]\" using AddStr.");
  86. top.Move (0, ++i);
  87. top.AddStr ("[\u0061\uFE20\u0065\uFE21]<- \"[\\u0061\\uFE20\\u0065\\uFE21]\" using AddStr.");
  88. top.Move (0, ++i);
  89. top.AddStr ("[\u1100\uD7B0]<- \"[\\u1100\\uD7B0]\" using AddStr.");
  90. };
  91. Application.Run (top);
  92. top.Dispose ();
  93. Application.Shutdown ();
  94. }
  95. }