mirror of
https://github.com/1f349/voidterm.git
synced 2024-11-09 22:52:55 +00:00
33 lines
523 B
Go
33 lines
523 B
Go
|
package voidterm
|
||
|
|
||
|
type Line struct {
|
||
|
wrapped bool
|
||
|
cells []Cell
|
||
|
}
|
||
|
|
||
|
func LineFromRunes(runes []rune, style CellAttributes) Line {
|
||
|
l := make(Line, len(runes))
|
||
|
for i, r := range runes {
|
||
|
l[i] = Cell{
|
||
|
r: r,
|
||
|
s: style,
|
||
|
}
|
||
|
}
|
||
|
return l
|
||
|
}
|
||
|
|
||
|
func (l Line) Wrap(width uint64) WrappedLine {
|
||
|
if uint64(len(l)) <= width {
|
||
|
return WrappedLine{l}
|
||
|
}
|
||
|
a := l
|
||
|
w := make(WrappedLine, 0, 1+uint64(len(l)-1)/width)
|
||
|
for uint64(len(a)) > width {
|
||
|
w = append(w, a[:width])
|
||
|
a = a[width:]
|
||
|
}
|
||
|
return w
|
||
|
}
|
||
|
|
||
|
type WrappedLine []Line
|