1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-12-26 22:16:54 +00:00
cchat-discord/internal/segments/renderer/inline.go

29 lines
539 B
Go
Raw Normal View History

package renderer
import (
2020-12-20 05:44:26 +00:00
"github.com/diamondburned/ningen/v2/md"
)
// InlineState assists in keeping a stateful inline segment builder.
type InlineState struct {
// TODO: use a stack to allow overlapping
Start, End int
Attributes md.Attribute
}
func (i *InlineState) Add(attr md.Attribute) {
i.Attributes |= attr
}
func (i *InlineState) Remove(attr md.Attribute) {
i.Attributes &= ^attr
}
func (i InlineState) Copy() InlineState {
return i
}
func (i InlineState) Empty() bool {
return i.Attributes == 0 || i.Start < i.End
}