Add better doc comments to data.go
This commit is contained in:
parent
49eff984ab
commit
08ed977234
26
data.go
26
data.go
@ -3,18 +3,25 @@ package xgbsel
|
|||||||
import "io"
|
import "io"
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
// Data represents a polymorphic data structure
|
// Data represents X selection data.
|
||||||
type Data interface {
|
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
|
Supported () []Target
|
||||||
}
|
}
|
||||||
|
|
||||||
// Target represents an X selection target. It defines the type of data stored
|
// 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:
|
// 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
|
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
|
||||||
type Target string
|
type Target string
|
||||||
|
|
||||||
|
// Confidence represents how accurate a conversion from a target to a MIME type
|
||||||
|
// is.
|
||||||
type Confidence int; const (
|
type Confidence int; const (
|
||||||
ConfidenceNone Confidence = iota
|
ConfidenceNone Confidence = iota
|
||||||
ConfidencePartial
|
ConfidencePartial
|
||||||
@ -23,9 +30,10 @@ type Confidence int; const (
|
|||||||
|
|
||||||
// ToMime converts the specified target to a MIME type. Because a single MIME
|
// ToMime converts the specified target to a MIME type. Because a single MIME
|
||||||
// type may correspond to several targets, a confidence value is returned
|
// 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
|
// representing how one-to-one of a match it is. If some data is represented by
|
||||||
// targets, they can be checked one after the other and the one with the highest
|
// multiple targets, they can each be checked individually and the one with the
|
||||||
// confidence value chosen.
|
// 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) {
|
func (target Target) ToMime () (string, Confidence) {
|
||||||
// TODO: add other stuff. reference this table:
|
// TODO: add other stuff. reference this table:
|
||||||
// https://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2
|
// 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
|
// MimeToTargets returns a slice of targets that correspond to a specified MIME
|
||||||
// type.
|
// 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 {
|
func MimeToTargets (mime string) []Target {
|
||||||
targets := []Target { Target(mime) }
|
targets := []Target { Target(mime) }
|
||||||
switch mime {
|
switch mime {
|
||||||
|
Loading…
Reference in New Issue
Block a user