diff --git a/utils.go b/utils.go index eea7b84..e53d531 100644 --- a/utils.go +++ b/utils.go @@ -219,13 +219,12 @@ type CellWithX struct { Cell Cell } -func BuildCellChannel(cells []Cell) chan CellWithX { - c := make(chan CellWithX, len(cells)) +func BuildCellWithXArray(cells []Cell) []CellWithX { + cellWithXArray := make([]CellWithX, len(cells)) index := 0 - for _, cell := range cells { - c <- CellWithX{X: index, Cell: cell} + for i, cell := range cells { + cellWithXArray[i] = CellWithX{X: index, Cell: cell} index += rw.RuneWidth(cell.Rune) } - close(c) - return c + return cellWithXArray } diff --git a/widgets/paragraph.go b/widgets/paragraph.go index 34ca187..7eb56bd 100644 --- a/widgets/paragraph.go +++ b/widgets/paragraph.go @@ -40,8 +40,8 @@ func (self *Paragraph) Draw(buf *Buffer) { break } row = TrimCells(row, self.Inner.Dx()) - for signal := range BuildCellChannel(row) { - x, cell := signal.X, signal.Cell + for _, cx := range BuildCellWithXArray(row) { + x, cell := cx.X, cx.Cell buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min)) } } diff --git a/widgets/table.go b/widgets/table.go index 3660ff1..6095954 100644 --- a/widgets/table.go +++ b/widgets/table.go @@ -74,8 +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 signal := range BuildCellChannel(col) { - k, cell := signal.X, signal.Cell + for _, cx := range BuildCellWithXArray(col) { + k, cell := cx.X, cx.Cell if k == columnWidths[j] || colXCoordinate+k == self.Inner.Max.X { cell.Rune = ELLIPSES buf.SetCell(cell, image.Pt(colXCoordinate+k-1, yCoordinate)) @@ -87,14 +87,14 @@ func (self *Table) Draw(buf *Buffer) { } else if self.TextAlign == AlignCenter { xCoordinateOffset := (columnWidths[j] - len(col)) / 2 stringXCoordinate := xCoordinateOffset + colXCoordinate - for signal := range BuildCellChannel(col) { - k, cell := signal.X, signal.Cell + for _, cx := range BuildCellWithXArray(col) { + k, cell := cx.X, cx.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 signal := range BuildCellChannel(col) { - k, cell := signal.X, signal.Cell + for _, cx := range BuildCellWithXArray(col) { + k, cell := cx.X, cx.Cell buf.SetCell(cell, image.Pt(stringXCoordinate+k, yCoordinate)) } }