From 0ebcb1ed991477db0084c8fc07efddd9ddd1f82c Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sat, 9 Jun 2018 13:16:20 +0200 Subject: [PATCH] Excluding control characters from output (creates unwanted artefacts). Fixes #130 --- textview.go | 3 ++- util.go | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/textview.go b/textview.go index 34197c3..429338a 100644 --- a/textview.go +++ b/textview.go @@ -5,6 +5,7 @@ import ( "fmt" "regexp" "sync" + "unicode" "unicode/utf8" "github.com/gdamore/tcell" @@ -815,7 +816,7 @@ func (t *TextView) Draw(screen tcell.Screen) { // Draw the character. var comb []rune - if len(runeSequence) > 1 { + if len(runeSequence) > 1 && !unicode.IsControl(runeSequence[1]) { // Allocate space for the combining characters only when necessary. comb = make([]rune, len(runeSequence)-1) copy(comb, runeSequence[1:]) diff --git a/util.go b/util.go index 0f8c075..ac12e57 100644 --- a/util.go +++ b/util.go @@ -419,7 +419,7 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, _, background, _ := finalStyle.Decompose() finalStyle = overlayStyle(background, style, foregroundColor, backgroundColor, attributes) var comb []rune - if len(runeSequence) > 1 { + if len(runeSequence) > 1 && !unicode.IsControl(runeSequence[1]) { // Allocate space for the combining characters only when necessary. comb = make([]rune, len(runeSequence)-1) copy(comb, runeSequence[1:]) @@ -475,7 +475,6 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int, } runeSequence = append(runeSequence, ch) runeSeqWidth += chWidth - } if drawnWidth+runeSeqWidth <= maxWidth { flush()