Compare commits

..

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

4 changed files with 6 additions and 24 deletions

View File

@ -69,12 +69,6 @@ func (b *Buffer[T]) Height() int {
return b.height return b.height
} }
// Offset returns the offset of b relative to its parent buffer.
// Offset returns zeros if b has no parent
func (b *Buffer[T]) Offset() (x, y int) {
return b.x, b.y
}
// OffsetX returns the horizontal offset of b relative to its parent buffer. // OffsetX returns the horizontal offset of b relative to its parent buffer.
// OffsetX returns 0 if b has no parent // OffsetX returns 0 if b has no parent
func (b *Buffer[T]) OffsetX() int { func (b *Buffer[T]) OffsetX() int {

6
go.mod
View File

@ -1,7 +1,3 @@
module git.tordarus.net/tordarus/buf2d module git.tordarus.net/Tordarus/buf2d
go 1.18 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 ( import (
"strings" "strings"
"github.com/mattn/go-runewidth"
) )
// 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
// It returns the amount of runes in str func WriteString(b *Buffer[rune], str string, x, y int) {
func WriteString(b *Buffer[rune], str string, x, y int) (width int) {
dx := x dx := x
for _, r := range str { for _, r := range str {
if dx >= b.Width() { if dx >= b.width {
return return
} }
b.Set(dx, y, r) 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) // WriteMultiLineString writes a multi-line string to the buffer at position (x,y)