fix: #226, unicode strings display in paragraph, table and list
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"image"
|
||||
|
||||
. "github.com/gizak/termui"
|
||||
rw "github.com/mattn/go-runewidth"
|
||||
)
|
||||
|
||||
type List struct {
|
||||
@@ -57,7 +58,7 @@ func (self *List) Draw(buf *Buffer) {
|
||||
break
|
||||
} else {
|
||||
buf.SetCell(NewCell(cells[j].Rune, style), point)
|
||||
point = point.Add(image.Pt(1, 0))
|
||||
point = point.Add(image.Pt(rw.RuneWidth(cells[j].Rune), 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ func (self *Paragraph) Draw(buf *Buffer) {
|
||||
break
|
||||
}
|
||||
row = TrimCells(row, self.Inner.Dx())
|
||||
for x, cell := range row {
|
||||
for signal := range BuildCellChannel(row) {
|
||||
x, cell := signal.X, signal.Cell
|
||||
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,8 @@ func (self *Table) Draw(buf *Buffer) {
|
||||
col := ParseText(row[j], rowStyle)
|
||||
// draw row cell
|
||||
if len(col) > columnWidths[j] || self.TextAlign == AlignLeft {
|
||||
for k, cell := range col {
|
||||
for signal := range BuildCellChannel(col) {
|
||||
k, cell := signal.X, signal.Cell
|
||||
if k == columnWidths[j] || colXCoordinate+k == self.Inner.Max.X {
|
||||
cell.Rune = ELLIPSES
|
||||
buf.SetCell(cell, image.Pt(colXCoordinate+k-1, yCoordinate))
|
||||
@@ -86,12 +87,14 @@ func (self *Table) Draw(buf *Buffer) {
|
||||
} else if self.TextAlign == AlignCenter {
|
||||
xCoordinateOffset := (columnWidths[j] - len(col)) / 2
|
||||
stringXCoordinate := xCoordinateOffset + colXCoordinate
|
||||
for k, cell := range col {
|
||||
for signal := range BuildCellChannel(col) {
|
||||
k, cell := signal.X, signal.Cell
|
||||
buf.SetCell(cell, image.Pt(stringXCoordinate+k, yCoordinate))
|
||||
}
|
||||
} else if self.TextAlign == AlignRight {
|
||||
stringXCoordinate := MinInt(colXCoordinate+columnWidths[j], self.Inner.Max.X) - len(col)
|
||||
for k, cell := range col {
|
||||
for signal := range BuildCellChannel(col) {
|
||||
k, cell := signal.X, signal.Cell
|
||||
buf.SetCell(cell, image.Pt(stringXCoordinate+k, yCoordinate))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user