types

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Black   Colour = '0' // Black colour -- ANSI.
	Red     Colour = '1' // Red colour -- ANSI.
	Green   Colour = '2' // Green colour -- ANSI.
	Yellow  Colour = '3' // Yellow colour -- ANSI.
	Blue    Colour = '4' // Blue colour -- ANSI.
	Magenta Colour = '5' // Magenta colour -- ANSI.
	Cyan    Colour = '6' // Cyan colour -- ANSI.
	White   Colour = '7' // White colour -- ANSI.
	Default Colour = '9' // Default colour -- ANSI.

	Normal     int = 0 // Reset all attributes.
	Bold       int = 1 // Bold -- VT100.
	Faint      int = 2 // Faint, decreased intensity -- ECMA-48 2e.
	Italic     int = 3 // Italicizsed -- ECMA-48 2e.
	Underline  int = 4 // Underlined -- VT100.
	Blink      int = 5 // Blinking -- VT100.
	Inverse    int = 6 // Inverse video -- VT100.
	Strikethru int = 7 // Crossed-out characters -- ECMA-48 3e.

)

CSI Pm [; Pm ...] m -- Character Attributes (SGR).

Variables

View Source
var (
	// Error condition that signals an invalid time duration of some kind.
	//
	// This error is usually wrapped around a descriptive message string.
	ErrInvalidDuration error = errors.Base("invalid time duration")

	// Error condition that signals that a duration is not a string value.
	//
	// This error is used by `Set` as well as JSON and YAML methods.
	ErrDurationNotString error = errors.Base("duration must be a string")

	// Error condition that signals that a duration is out of bounds.
	//
	// This is used by `Validate`.
	ErrOutOfBounds error = errors.Base("duration out of bounds")
)
View Source
var (
	// Error condition that signals an invalid RFC3339 timestamp  of some
	// kind.
	//
	// This error is usually wrapped around a descriptive message string.
	ErrInvalidRFC3339 error = errors.Base("invalid RFC3339 timestamp")

	// Error condition that signals that an RFC3339 timestamp is not a
	// string format.
	//
	// This error is used by `Set` as well as JSON and YAML methods.
	ErrRFC3339NotString error = errors.Base("RFC3339 timestamp  must be a string")
)

Functions

func CurrentZone added in v0.5.10

func CurrentZone() (string, int)

Return the current timezone for the host.

func PrettyFormat added in v0.5.10

func PrettyFormat(dur Duration) string

Format a time duration in pretty format.

Example, a duration of 72 minutes becomes "1 hour(s), 12 minute(s)".

func TimeToMySQL added in v0.5.10

func TimeToMySQL(val time.Time) string

Convert a `time.Time` value to a MySQL timestamp for queries.

Types

type ColorString added in v0.1.1

type ColorString struct {
	// contains filtered or unexported fields
}

Colour string.

Generates a string that, with the right terminal type, display text using various character attributes.

To find out more, consult your nearest DEC VT340 programmer's manual or the latest ECMA-48 standard.

func NewColorString added in v0.5.10

func NewColorString() *ColorString

Make a new coloured string.

func NewColorStringWithColors added in v0.5.10

func NewColorStringWithColors(
	data string,
	foreg, backg Colour,
) *ColorString

Make a new coloured string with the given attributes.

func (*ColorString) AddAttr added in v0.5.10

func (cs *ColorString) AddAttr(index int) *ColorString

Add a specific attribute.

This ignores the "Normal" attribute. To clear attributes, use `SetNormal` or `Clear`.

func (*ColorString) Clear added in v0.5.10

func (cs *ColorString) Clear() *ColorString

Reset all attributes.

func (*ColorString) RemoveAttr added in v0.5.10

func (cs *ColorString) RemoveAttr(index int) *ColorString

Remove a specific attribute.

This ignores the "Normal" attribute. To clear attributes, use `SetNormal` or `Clear`.

func (*ColorString) SetBG added in v0.1.1

func (cs *ColorString) SetBG(col Colour) *ColorString

Set the background colour.

func (cs *ColorString) SetBlink() *ColorString

Set the blink attribute.

func (*ColorString) SetBold added in v0.5.10

func (cs *ColorString) SetBold() *ColorString

Set the bold attribute.

func (*ColorString) SetFG added in v0.1.1

func (cs *ColorString) SetFG(col Colour) *ColorString

Set the foreground colour.

func (*ColorString) SetFaint added in v0.5.10

func (cs *ColorString) SetFaint() *ColorString

Set the faint attribute.

func (*ColorString) SetInverse added in v0.5.10

func (cs *ColorString) SetInverse() *ColorString

Set the inverse video attribute.

func (*ColorString) SetItalic added in v0.5.10

func (cs *ColorString) SetItalic() *ColorString

Set the italic attribute.

func (*ColorString) SetNormal added in v0.5.10

func (cs *ColorString) SetNormal() *ColorString

Set the attribute to normal.

This removes all other attributes.

func (*ColorString) SetStrikethru added in v0.5.10

func (cs *ColorString) SetStrikethru() *ColorString

Set the strikethrough attribute.

func (*ColorString) SetString added in v0.1.1

func (cs *ColorString) SetString(val string) *ColorString

Set the string to display.

func (*ColorString) SetUnderline added in v0.5.10

func (cs *ColorString) SetUnderline() *ColorString

Set the underline attribute.

func (*ColorString) String added in v0.1.1

func (cs *ColorString) String() string

Convert to a string.

Warning: the resulting string will contain escape sequences for use with a compliant terminal or terminal emulator.

type Colour added in v0.5.10

type Colour rune

ECMA-48 colour descriptor type.

type Datum added in v1.0.5

type Datum = any

type Duration added in v0.5.9

type Duration time.Duration

Enhanced time duration type.

func NewFromDuration added in v0.5.10

func NewFromDuration(duration string) (Duration, error)

func (Duration) Duration added in v0.5.9

func (obj Duration) Duration() time.Duration

Coerce a duration to a `time.Duration` value.

func (Duration) MarshalJSON added in v0.5.9

func (obj Duration) MarshalJSON() ([]byte, error)

JSON marshalling method.

func (Duration) MarshalYAML added in v0.5.9

func (obj Duration) MarshalYAML() (any, error)

YAML marshalling method.

func (*Duration) Set added in v0.5.9

func (obj *Duration) Set(str string) error

Set the duration to that of the given string.

This method uses `time.ParseDuration`, so any string that `time` understands may be used.

If the string value fails parsing, then `ErrInvalidDuration` is returned.

func (*Duration) SetYAML added in v0.5.9

func (obj *Duration) SetYAML(value any) error

Set the duration value from a YAML value.

If the passed YAML value is not a string, then `ErrDurationNotString` is returned.

Will also return any error condition from the `Set` method.

func (Duration) String added in v0.5.9

func (obj Duration) String() string

Coerce a duration to a string value.

func (Duration) Type added in v0.5.9

func (obj Duration) Type() string

Return the data type name for CLI flag parsing purposes.

func (*Duration) UnmarshalJSON added in v0.5.9

func (obj *Duration) UnmarshalJSON(data []byte) error

JSON unmarshalling method.

func (*Duration) UnmarshalYAML added in v0.5.9

func (obj *Duration) UnmarshalYAML(value *yaml.Node) error

YAML unmarshalling method.

func (Duration) Validate added in v0.5.9

func (obj Duration) Validate(minDuration, maxDuration time.Duration) error

Validate a duration.

This ensures a duration is within a given range.

If validation fails, then `ErrOutOfBounds` is returned.

type Mailbox

type Mailbox struct {
	// contains filtered or unexported fields
}

Mailbox structure.

This is a cheap implementation of a mailbox.

It uses two semaphores to control read and write access, and contains a single datum.

This is *not* a queue!

func NewMailbox

func NewMailbox() *Mailbox

Create and return a new empty mailbox.

Note: this acquires the `readAvailable` semaphore.

func (*Mailbox) Empty added in v1.0.5

func (m *Mailbox) Empty() bool

Is the mailbox empty like my heart?

func (*Mailbox) Full

func (m *Mailbox) Full() bool

Does the mailbox contain a value?

func (*Mailbox) Get

func (m *Mailbox) Get() (Datum, bool)

Get an element from the mailbox. Defaults to using a context with a deadline of 5 seconds.

func (*Mailbox) GetWithContext

func (m *Mailbox) GetWithContext(ctx context.Context) (Datum, bool)

Get an element from the mailbox using the provided context.

It is recommended to use a context that has a timeout deadline.

func (*Mailbox) Put

func (m *Mailbox) Put(elem Datum) bool

Put an element into the mailbox.

func (*Mailbox) PutWithContext added in v1.0.5

func (m *Mailbox) PutWithContext(ctx context.Context, elem Datum) bool

Put an element into the mailbox using a context.

func (*Mailbox) Reset added in v1.0.5

func (m *Mailbox) Reset()

Reset the mailbox.

func (*Mailbox) TryGet added in v1.0.5

func (m *Mailbox) TryGet() (Datum, bool)

Try to get an element from the mailbox.

func (*Mailbox) TryPut added in v1.0.5

func (m *Mailbox) TryPut(item Datum) bool

Try to put an element into the mailbox.

type Pair

type Pair struct {
	First  any
	Second any
}

Pair structure.

This is a cheap implementation of a pair (aka two-value tuple).

func NewEmptyPair

func NewEmptyPair() *Pair

Create a new empty pair.

func NewPair

func NewPair(first any, second any) *Pair

Create a new pair.

func (*Pair) String

func (p *Pair) String() string

Return a string representation of the pair.

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Queue structure.

This is a cheap implementation of a FIFO queue.

func NewBoundedQueue

func NewBoundedQueue(bounds int) *Queue

Create a queue that is bounded to a specific size.

func NewQueue

func NewQueue() *Queue

Create a new empty queue.

func (*Queue) Empty added in v1.0.5

func (q *Queue) Empty() bool

Is the queue empty?

func (*Queue) Full

func (q *Queue) Full() bool

Is the queue full?

func (*Queue) Get

func (q *Queue) Get() (Datum, bool)

Remove an element from the end of the queue and return it.

func (*Queue) Len

func (q *Queue) Len() int

Return the number of elements in the queue.

func (*Queue) Put

func (q *Queue) Put(elem Datum) bool

Append an element to the queue. Returns `false` if there is no more room in the queue.

type RFC3339 added in v0.5.10

type RFC3339 time.Time

RFC 3339 time type.

func Parse added in v0.5.10

func Parse(data string) (RFC3339, error)

Parse the given string for an RFC3339 timestamp.

If the timestamp is not a valid RFC3339 timestamp, then `ErrInvalidRFC3339` is returned.

func RFC3339FromUnix added in v1.0.5

func RFC3339FromUnix(unix int64) RFC3339

Convert a Unix timestamp to an RFC3339 timestamp.

func (RFC3339) Add added in v0.5.10

func (obj RFC3339) Add(d time.Duration) RFC3339

Add a `time.Duration` value to the timestamp, returning a new timestamp.

func (RFC3339) After added in v0.5.10

func (obj RFC3339) After(t time.Time) bool

Is the given time after the time in the timestamp?

func (RFC3339) Before added in v0.5.10

func (obj RFC3339) Before(t time.Time) bool

Is the given time before the time in the timestamp?

func (RFC3339) Equal added in v0.5.10

func (obj RFC3339) Equal(t time.Time) bool

Is the given time equal to the time in the timestamp?

func (RFC3339) Format added in v0.5.10

func (obj RFC3339) Format(format string) string

Format the timestamp with the given format.

func (RFC3339) IsDST added in v0.5.10

func (obj RFC3339) IsDST() bool

Does the timestamp correspond to a time where DST is in effect?

func (RFC3339) IsZero added in v0.5.10

func (obj RFC3339) IsZero() bool

Is the timestamp a zero value?

func (RFC3339) MarshalJSON added in v0.5.10

func (obj RFC3339) MarshalJSON() ([]byte, error)

JSON marshalling method.

func (RFC3339) MarshalYAML added in v0.5.10

func (obj RFC3339) MarshalYAML() (any, error)

YAML marshalling method.

func (RFC3339) MySQL added in v0.5.10

func (obj RFC3339) MySQL() string

Return a string that can be used in MySQL queries.

func (*RFC3339) Set added in v0.5.10

func (obj *RFC3339) Set(str string) error

Set the RFC3339 timestamp to that of the given string.

If the string value fails to parse, then `ErrInvalidRFC3339` is returned.

func (*RFC3339) SetYAML added in v0.5.10

func (obj *RFC3339) SetYAML(value any) error

Set the RFC3339 value from a YAML value.

If the passed YAML value is not a string, then `ErrRFC3339NotString` is returned.

Will also return any error condition from the `Set` method.

func (RFC3339) String added in v0.5.10

func (obj RFC3339) String() string

Coerce an RFC3339 time value to a string.

func (RFC3339) Sub added in v0.5.10

func (obj RFC3339) Sub(t time.Time) time.Duration

Subtract a `time.Time` value from the timestamp, returning a `time.Duration`.

func (RFC3339) Time added in v0.5.10

func (obj RFC3339) Time() time.Time

Coerce an RFC3339 time value to a `time.Time` value.

func (RFC3339) Type added in v0.5.10

func (obj RFC3339) Type() string

Return the data type name for CLI flag parsing purposes.

func (RFC3339) UTC added in v0.5.10

func (obj RFC3339) UTC() time.Time

Return the UTC time for the timestamp.

RFC3339 timestamps are always UTC internally, so `UTC` is provided as a courtesy.

func (RFC3339) Unix added in v0.5.10

func (obj RFC3339) Unix() int64

Return the Unix time for the timestamp.

func (*RFC3339) UnmarshalJSON added in v0.5.10

func (obj *RFC3339) UnmarshalJSON(data []byte) error

JSON unmarshalling method.

func (*RFC3339) UnmarshalYAML added in v0.5.10

func (obj *RFC3339) UnmarshalYAML(value *yaml.Node) error

YAML unmarshalling method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL