41 lines
955 B
Go
41 lines
955 B
Go
package buf2d
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// WriteString writes a whole string to the buffer at position (x,y)
|
|
// no word wrap is applied at all. If the string does not fit, it will be truncated
|
|
func WriteString(b *Buffer[rune], str string, x, y int) {
|
|
dx := x
|
|
for _, r := range str {
|
|
if dx >= b.width {
|
|
return
|
|
}
|
|
b.Set(dx, y, r)
|
|
dx++
|
|
}
|
|
}
|
|
|
|
// WriteMultiLineString writes a multi-line string to the buffer at position (x,y)
|
|
// no word wrap is applied at all. If a line does not fit horizontally, it will be truncated
|
|
// All lines which do not fit vertically will be truncated as well
|
|
func WriteMultiLineString(b *Buffer[rune], str string, x, y int) {
|
|
lines := strings.Split(str, "\n")
|
|
for dy, line := range lines {
|
|
if dy >= b.height {
|
|
return
|
|
}
|
|
WriteString(b, line, x, y+dy)
|
|
}
|
|
}
|
|
|
|
// Fill fills the whole buffer with c
|
|
func (b *Buffer[T]) Fill(value T) {
|
|
for _, col := range b.data {
|
|
for ri := range col {
|
|
col[ri] = value
|
|
}
|
|
}
|
|
}
|