Unicode support improvement

This commit is contained in:
Zachary Yedidia
2019-06-15 16:54:53 -04:00
parent c93d7a1b35
commit 47a129b70f
3 changed files with 48 additions and 15 deletions

View File

@@ -99,7 +99,14 @@ func (i *InfoWindow) displayBuffer() {
}
screen.Screen.SetContent(vlocX, i.Y, r, nil, style)
rw := runewidth.RuneWidth(r)
for j := 0; j < rw; j++ {
c := r
if j > 0 {
c = ' '
}
screen.Screen.SetContent(vlocX, i.Y, c, nil, style)
}
vlocX++
}
nColsBeforeStart--

View File

@@ -3,14 +3,17 @@ package display
import (
"bytes"
"fmt"
"log"
"path"
"regexp"
"strconv"
"unicode/utf8"
runewidth "github.com/mattn/go-runewidth"
"github.com/zyedidia/micro/internal/buffer"
"github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/screen"
"github.com/zyedidia/micro/internal/util"
)
// StatusLine represents the information line at the bottom
@@ -95,19 +98,36 @@ func (s *StatusLine) Display() {
statusLineStyle = style
}
leftLen := utf8.RuneCount(leftText)
rightLen := utf8.RuneCount(rightText)
leftLen := util.StringWidth(leftText, utf8.RuneCount(leftText), 1)
rightLen := util.StringWidth(rightText, utf8.RuneCount(rightText), 1)
winX := s.win.X
for x := 0; x < s.win.Width; x++ {
if x < leftLen {
r, size := utf8.DecodeRune(leftText)
leftText = leftText[size:]
screen.Screen.SetContent(winX+x, y, r, nil, statusLineStyle)
rw := runewidth.RuneWidth(r)
for j := 0; j < rw; j++ {
c := r
if j > 0 {
c = ' '
x++
}
log.Println(x, string(c))
screen.Screen.SetContent(winX+x, y, c, nil, statusLineStyle)
}
} else if x >= s.win.Width-rightLen && x < rightLen+s.win.Width-rightLen {
r, size := utf8.DecodeRune(rightText)
rightText = rightText[size:]
screen.Screen.SetContent(winX+x, y, r, nil, statusLineStyle)
rw := runewidth.RuneWidth(r)
for j := 0; j < rw; j++ {
c := r
if j > 0 {
c = ' '
x++
}
screen.Screen.SetContent(winX+x, y, c, nil, statusLineStyle)
}
} else {
screen.Screen.SetContent(winX+x, y, ' ', nil, statusLineStyle)
}

View File

@@ -3,6 +3,7 @@ package display
import (
"unicode/utf8"
runewidth "github.com/mattn/go-runewidth"
"github.com/zyedidia/micro/internal/buffer"
"github.com/zyedidia/micro/internal/config"
"github.com/zyedidia/micro/internal/screen"
@@ -77,24 +78,29 @@ func (w *TabWindow) SetActive(a int) {
}
}
// TODO: handle files with character width >=2
func (w *TabWindow) Display() {
x := -w.hscroll
done := false
draw := func(r rune, n int) {
for i := 0; i < n; i++ {
if x == w.width-1 && !done {
screen.Screen.SetContent(w.width-1, w.Y, '>', nil, config.DefStyle.Reverse(true))
rw := runewidth.RuneWidth(r)
for j := 0; j < rw; j++ {
c := r
if j > 0 {
c = ' '
}
if x == w.width-1 && !done {
screen.Screen.SetContent(w.width-1, w.Y, '>', nil, config.DefStyle.Reverse(true))
x++
break
} else if x == 0 && w.hscroll > 0 {
screen.Screen.SetContent(0, w.Y, '<', nil, config.DefStyle.Reverse(true))
} else if x >= 0 && x < w.width {
screen.Screen.SetContent(x, w.Y, c, nil, config.DefStyle.Reverse(true))
}
x++
break
} else if x == 0 && w.hscroll > 0 {
screen.Screen.SetContent(0, w.Y, '<', nil, config.DefStyle.Reverse(true))
} else if x >= 0 && x < w.width {
screen.Screen.SetContent(x, w.Y, r, nil, config.DefStyle.Reverse(true))
}
x++
}
}