-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
builder.go
37 lines (30 loc) · 858 Bytes
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package styling
import (
"golang.org/x/xerrors"
"github.com/gotd/td/telegram/message/entity"
)
type textBuilder struct {
*entity.Builder
}
func (b *textBuilder) Perform(text StyledTextOption, texts ...StyledTextOption) error {
b.GrowEntities(len(texts) + 1)
length := text.size
for i := range texts {
length += texts[i].size
}
b.GrowText(length)
if err := text.perform(b); err != nil {
return xerrors.Errorf("perform first styling option: %w", err)
}
for idx, opt := range texts {
if err := opt.perform(b); err != nil {
return xerrors.Errorf("perform %d styling option: %w", idx, err)
}
}
return nil
}
// Perform performs all options to the given builder.
func Perform(builder *entity.Builder, text StyledTextOption, texts ...StyledTextOption) error {
tb := &textBuilder{Builder: builder}
return tb.Perform(text, texts...)
}