2020-10-05 03:45:34 +00:00
|
|
|
package segutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/diamondburned/cchat/text"
|
|
|
|
)
|
|
|
|
|
|
|
|
// helper global functions
|
|
|
|
|
2020-10-07 01:53:15 +00:00
|
|
|
func Write(rich *text.Rich, content string, segs ...text.Segment) (start, end int) {
|
|
|
|
start = len(rich.Content)
|
|
|
|
end = len(rich.Content) + len(content)
|
|
|
|
rich.Content += content
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-05 03:45:34 +00:00
|
|
|
func WriteBuf(w *bytes.Buffer, b []byte) (start, end int) {
|
|
|
|
start = w.Len()
|
|
|
|
w.Write(b)
|
|
|
|
end = w.Len()
|
|
|
|
return start, end
|
|
|
|
}
|
|
|
|
|
|
|
|
func WriteStringBuf(w *bytes.Buffer, b string) (start, end int) {
|
|
|
|
start = w.Len()
|
|
|
|
w.WriteString(b)
|
|
|
|
end = w.Len()
|
|
|
|
return start, end
|
|
|
|
}
|
|
|
|
|
|
|
|
func Add(r *text.Rich, seg ...text.Segment) {
|
|
|
|
r.Segments = append(r.Segments, seg...)
|
|
|
|
}
|