Compare commits

..

No commits in common. "main" and "v1.1.6" have entirely different histories.
main ... v1.1.6

3 changed files with 6 additions and 18 deletions

6
go.mod
View File

@ -1,7 +1,3 @@
module git.tordarus.net/tordarus/buf2d
module git.tordarus.net/Tordarus/buf2d
go 1.18
require github.com/mattn/go-runewidth v0.0.14
require github.com/rivo/uniseg v0.2.0 // indirect

4
go.sum
View File

@ -1,4 +0,0 @@
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

View File

@ -2,23 +2,19 @@ package buf2d
import (
"strings"
"github.com/mattn/go-runewidth"
)
// 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.
// It returns the amount of runes in str
func WriteString(b *Buffer[rune], str string, x, y int) (width int) {
// 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() {
if dx >= b.width {
return
}
b.Set(dx, y, r)
dx += runewidth.RuneWidth(r)
dx++
}
return dx - x
}
// WriteMultiLineString writes a multi-line string to the buffer at position (x,y)