Added Mentioner and clarifications

This commit adds the Mentioner interface. The objective is to have a
clickable mention string similar to that in Discord, that when pressed
will popup a small box containing the given user info.

In the future, Mentioner may be expanded to add Avatar capabilities, but
for now, it can be added using text segments.

This commit also clarified that segments can implement multiple
interfaces. This is done to allow segments such as Mentioner to also be
colored using Colorer.

Frontend implementations should, instead of a type switch, use multiple
if statements separately. This may introduce a lot more boilerplate code.
This commit is contained in:
diamondburned 2020-07-07 13:26:39 -07:00
parent 0abbf861bc
commit ecbd4515a2
1 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,9 @@ func (r Rich) String() string {
// this to determine when the format starts and ends. They will also assert this
// interface to any other formatting interface, including Linker, Colorer and
// Attributor.
//
// Note that a segment may implement multiple interfaces. For example, a
// Mentioner may also implement Colorer.
type Segment interface {
Bounds() (start, end int)
}
@ -63,6 +66,15 @@ type Avatarer interface {
AvatarText() string
}
// Mentioner implies that the segment can be clickable, and when clicked it
// should open up a dialog containing information from MentionInfo().
type Mentioner interface {
Segment
// MentionInfo returns the popup information of the mentioned segment. This
// is typically user information or something similar to that context.
MentionInfo() Rich
}
// Colorer is a text color format that a segment could implement. This is to be
// applied directly onto the text.
type Colorer interface {