types

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CSI Pm m -- Character Attributes (SGR).
	NORMAL        = 0 // Normal (default), VT100.
	BOLD          = 1 // Bold, VT100.
	FAINT         = 2 // Faint, decreased intensity, ECMA-48 2nd.
	ITALICS       = 3 // Italicized, ECMA-48 2nd.
	UNDERLINE     = 4 // Underlined, VT100.
	BLINK         = 5 // Blink, VT100.
	INVERSE       = 7 // Inverse, VT100.
	STRIKETHROUGH = 9 // Crossed-out characters, ECMA-48 3rd.

	BLACK   = 0
	RED     = 1
	GREEN   = 2
	YELLOW  = 3
	BLUE    = 4
	MAGENTA = 5
	CYAN    = 6
	WHITE   = 7
	DEFAULT = 9
)
View Source
const (
	// Amount of time to delay semaphore acquisition loops.
	MailboxDelaySleep  time.Duration = 50 * time.Millisecond
	DefaultCtxDeadline time.Duration = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorString added in v0.1.1

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

func MakeColorString added in v0.1.1

func MakeColorString() *ColorString

func MakeColorStringWithAttrs added in v0.3.3

func MakeColorStringWithAttrs(data string, attr, fg, bg int) *ColorString

func (*ColorString) SetAttr added in v0.1.1

func (cs *ColorString) SetAttr(attr int)

func (*ColorString) SetBG added in v0.1.1

func (cs *ColorString) SetBG(col int)

func (*ColorString) SetFG added in v0.1.1

func (cs *ColorString) SetFG(col int)

func (*ColorString) SetString added in v0.1.1

func (cs *ColorString) SetString(val string)

func (*ColorString) String added in v0.1.1

func (cs *ColorString) String() string

type Error

type Error struct {
	Module  string
	Message string
}

Custom error structure.

This is compatible with the `error` interface and provides `Unwrap` support.

func NewError

func NewError(module string, format string, args ...interface{}) *Error

Create a new error object.

func NewErrorAndLog

func NewErrorAndLog(module string, format string, args ...interface{}) *Error

Create a new error object and immediately log it.

func (*Error) Error

func (e *Error) Error() string

Return a human-readable string representation of the error.

func (*Error) Log

func (e *Error) Log()

Log the error.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

Convert the error to a JSON string.

func (*Error) String

func (e *Error) String() string

Return a human-readable string representation of the error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap the error.

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 `preventRead` semaphore.

func (*Mailbox) Full

func (m *Mailbox) Full() bool

Does the mailbox contain a value?

func (*Mailbox) Get

func (m *Mailbox) Get() (interface{}, 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) (interface{}, bool)

func (*Mailbox) Put

func (m *Mailbox) Put(elem interface{})

Put an element into the mailbox.

type Pair

type Pair struct {
	First  interface{}
	Second interface{}
}

Pair structure.

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

I wish generics were a thing.

func NewEmptyPair

func NewEmptyPair() *Pair

Create a new empty pair.

func NewPair

func NewPair(first interface{}, second interface{}) *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 LIFO queue.

func NewBoundedQueue

func NewBoundedQueue(bounds int) *Queue

func NewQueue

func NewQueue() *Queue

Create a new empty queue.

func (*Queue) Full

func (q *Queue) Full() bool

Is the queue full?

func (*Queue) Get

func (q *Queue) Get() (interface{}, 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 interface{}) bool

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

Jump to

Keyboard shortcuts

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