Add better doc comments to data.go

This commit is contained in:
Sasha Koshka 2024-07-05 23:27:53 -04:00
parent 49eff984ab
commit 08ed977234

26
data.go
View File

@ -3,18 +3,25 @@ package xgbsel
import "io"
import "strings"
// Data represents a polymorphic data structure
// Data represents X selection data.
type Data interface {
Convert (Target) (reader io.ReadSeekCloser, ok bool)
// Convert converts the data to the specified target and returns it. If
// the target is not supported, this behavior will return false for ok.
Convert (Target) (reader io.ReadSeekCloser, ok bool)
// Supported returns a slice of targets that Convert can accept. This
// can just be the result of MimeToTargets.
Supported () []Target
}
// Target represents an X selection target. It defines the type of data stored
// within an X selection. This data may be a mime type, or a more specific name
// within an X selection. This data may be a MIME type, or a more specific name
// that is unique to X. A list of these names can be found here:
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
type Target string
// Confidence represents how accurate a conversion from a target to a MIME type
// is.
type Confidence int; const (
ConfidenceNone Confidence = iota
ConfidencePartial
@ -23,9 +30,10 @@ type Confidence int; const (
// ToMime converts the specified target to a MIME type. Because a single MIME
// type may correspond to several targets, a confidence value is returned
// representing how good of a match it is. If data is represented by multiple
// targets, they can be checked one after the other and the one with the highest
// confidence value chosen.
// representing how one-to-one of a match it is. If some data is represented by
// multiple targets, they can each be checked individually and the one with the
// highest confidence value can be chosen. If a target cannot be converted to a
// MIME type, ("", ConfidenceNone) is returned.
func (target Target) ToMime () (string, Confidence) {
// TODO: add other stuff. reference this table:
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
@ -58,8 +66,10 @@ func (target Target) ToMime () (string, Confidence) {
}
}
// MimeToTargets returns a list of targets that correspond to a specified MIME
// type.
// MimeToTargets returns a slice of targets that correspond to a specified MIME
// type. The MIME type itself is always the first item of the slice. All targets
// returned by this function are guaranteed to convert to the given MIME type
// when ToMime is called on them.
func MimeToTargets (mime string) []Target {
targets := []Target { Target(mime) }
switch mime {