WriteMultiLineString added
This commit is contained in:
parent
d5ee06e128
commit
88a6a466bf
@ -1,5 +1,7 @@
|
|||||||
package buf2d
|
package buf2d
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
// WriteString writes a whole string to the buffer at position (x,y)
|
// 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
|
// no word wrap is applied at all. If the string does not fit, it will be truncated
|
||||||
func (b *Buffer) WriteString(str string, x, y int) {
|
func (b *Buffer) WriteString(str string, x, y int) {
|
||||||
@ -13,6 +15,20 @@ func (b *Buffer) WriteString(str string, x, y int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 (b *Buffer) WriteMultiLineString(str string, x, y int) {
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
for dy, line := range lines {
|
||||||
|
if dy >= b.height {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.WriteString(line, x, y+dy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fill fills the whole buffer with c
|
// Fill fills the whole buffer with c
|
||||||
func (b *Buffer) Fill(c rune) {
|
func (b *Buffer) Fill(c rune) {
|
||||||
for _, col := range b.data {
|
for _, col := range b.data {
|
||||||
|
Loading…
Reference in New Issue
Block a user