more replace non printable

This commit is contained in:
Charlie Kindel
2020-06-10 14:46:27 -06:00
parent 5cc1d45785
commit a2105cbcc4
2 changed files with 28 additions and 7 deletions

View File

@@ -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 ();

View File

@@ -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)