From fb735057e085b3f290757e83eb427487eccc37c6 Mon Sep 17 00:00:00 2001 From: giuliano Date: Thu, 20 Jul 2023 23:57:24 +0200 Subject: [PATCH] Use runes for rendered text --- pkg/display/display.go | 10 +++++----- pkg/display/rendering.go | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/display/display.go b/pkg/display/display.go index 5675974..5440170 100644 --- a/pkg/display/display.go +++ b/pkg/display/display.go @@ -64,10 +64,10 @@ type display struct { mu sync.Mutex - // dislay raw text + // display raw text raw [][]byte - // dislay rendered text - rendered [][]byte + // display rendered text + rendered [][]rune // gob cache cache *cache.Cache @@ -151,7 +151,7 @@ func (d *display) appendToRaw(s string) { } func (d *display) appendToRendered(s string) { - d.rendered = append(d.rendered, []byte(s)) + d.rendered = append(d.rendered, []rune(s)) } func (d *display) currentRow() int { @@ -170,7 +170,7 @@ func (d *display) resetCoordinates() { func (d *display) resetRows() { d.raw = make([][]byte, 0) - d.rendered = make([][]byte, 0) + d.rendered = make([][]rune, 0) } func (d *display) insertCharAt(c string, i int) { diff --git a/pkg/display/rendering.go b/pkg/display/rendering.go index 95b5c42..8adb622 100644 --- a/pkg/display/rendering.go +++ b/pkg/display/rendering.go @@ -19,7 +19,7 @@ func (d *display) renderURLs() { cached[cachedFeed.Url] = cachedFeed } - d.rendered = make([][]byte, 0) + d.rendered = make([][]rune, 0) for row := range d.raw { url := d.raw[row] if !strings.Contains(string(url), "#") { @@ -46,7 +46,7 @@ func (d *display) renderArticlesList() { } } - d.rendered = make([][]byte, 0) + d.rendered = make([][]rune, 0) if currentFeed != nil { for _, item := range currentFeed.GetItemsOrderedByDate() { if item.New { @@ -82,8 +82,8 @@ func (d *display) renderArticleText() { } } - d.rendered = make([][]byte, 0) - line := make([]byte, 0) + d.rendered = make([][]rune, 0) + line := make([]rune, 0) for _, c := range runes { if c == '\r' || c == '\n' { @@ -91,8 +91,8 @@ func (d *display) renderArticleText() { if len(line) != 0 { d.rendered = append(d.rendered, add(margin, line)) } - d.rendered = append(d.rendered, []byte{}) - line = make([]byte, 0) + d.rendered = append(d.rendered, []rune{}) + line = make([]rune, 0) continue } @@ -104,11 +104,11 @@ func (d *display) renderArticleText() { } if len(line) < textSpace { - line = append(line, []byte(string(c))...) + line = append(line, c) } else { d.rendered = append(d.rendered, add(margin, line)) - line = make([]byte, 0) - line = append(line, []byte(string(c))...) + line = make([]rune, 0) + line = append(line, c) } } @@ -117,9 +117,9 @@ func (d *display) renderArticleText() { } } -func add(margin int, line []byte) []byte { +func add(margin int, line []rune) []rune { if margin != 0 { - padded := make([]byte, 0) + padded := make([]rune, 0) for margin != 0 { padded = append(padded, ' ') margin--