Explorar el Código

more replace non printable

Charlie Kindel hace 5 años
padre
commit
a2105cbcc4
Se han modificado 2 ficheros con 28 adiciones y 7 borrados
  1. 15 0
      Terminal.Gui/Views/Button.cs
  2. 13 7
      Terminal.Gui/Views/Label.cs

+ 15 - 0
Terminal.Gui/Views/Button.cs

@@ -6,6 +6,7 @@
 //
 
 using System;
+using System.Collections.Generic;
 using NStack;
 
 namespace Terminal.Gui {
@@ -166,6 +167,20 @@ namespace Terminal.Gui {
 			else
 				shown_text = ustring.Make (_leftBracket) + " " + text + " " + ustring.Make (_rightBracket);
 
+			ustring ReplaceNonPrintables (ustring str)
+			{
+				var runes = new List<Rune> ();
+				foreach (var r in str.ToRunes ()) {
+					if (r < 0x20) {
+						runes.Add (new Rune (r + 0x2400));         // U+25A1 □ WHITE SQUARE
+					} else {
+						runes.Add (r);
+					}
+				}
+				return ustring.Make (runes); ;
+			}
+			shown_text = ReplaceNonPrintables (text);
+
 			shown_text = GetTextFromHotKey (shown_text, '_', out hot_pos, out hot_key);
 
 			SetNeedsDisplay ();

+ 13 - 7
Terminal.Gui/Views/Label.cs

@@ -171,13 +171,19 @@ namespace Terminal.Gui {
 			int start = 0, end;
 			var lines = new List<ustring> ();
 
-			text = text
-				.Replace ("\f", "\u21a1")               // U+21A1 ↡ DOWNWARDS TWO HEADED ARROW
-				.Replace ("\n", "\u240a")               // U+240A (SYMBOL FOR LINE FEED, ␊)
-				.Replace ("\r", "\u240d")               // U+240D (SYMBOL FOR CARRIAGE RETURN, ␍)
-				.Replace ("\t", "\u2409")               // U+2409 ␉ SYMBOL FOR HORIZONTAL TABULATION
-				.Replace ("\v", "\u240b")               // U+240B ␋ SYMBOL FOR VERTICAL TABULATION
-				.TrimSpace ();
+			ustring ReplaceNonPrintables (ustring str)
+			{
+				var runes = new List<Rune>();
+				foreach (var r in str.ToRunes()) {
+					if (r < 0x20) {
+						runes.Add(new Rune (r + 0x2400));         // U+25A1 □ WHITE SQUARE
+					} else {
+						runes.Add(r);
+					}
+				}
+				return ustring.Make (runes); ;
+			}
+			text = ReplaceNonPrintables (text);
 
 			while ((end = start + margin) < text.Length) {
 				while (text [end] != ' ' && end > start)