Skip to content

Commit

Permalink
Use runes for rendered text
Browse files Browse the repository at this point in the history
  • Loading branch information
giulianopz committed Jul 20, 2023
1 parent d29e64e commit fb73505
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pkg/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions pkg/display/rendering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), "#") {
Expand All @@ -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 {
Expand Down Expand Up @@ -82,17 +82,17 @@ 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' {

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
}

Expand All @@ -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)
}
}

Expand All @@ -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--
Expand Down

0 comments on commit fb73505

Please sign in to comment.