terminal

package module
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 18 Imported by: 13

README

Ask DeepWiki

terminal

Fortio's terminal has 2 distinct components and a number of utilities built on the second one.

Readline style terminal and more vs Low level ansipixels terminal control and drawing:

fortio.org/terminal

Go Reference

fortio.org/terminal is a readline style library. It handles prompts, edit (like Ctrl-A for beginning of line etc...), navigating through history using arrow keys, loading and saving history from file, etc... It works on everywhere go does (including macOS, Windows (using Terminal app), Linux).

See example/main.go for a rather complete example/demo.

See the godoc above for details.

The grol command line repl and others use this.

The implementations currently is a wrapper fully encapsulating golang.org/x/term, with configurable History and new features like the interrupts handling (filters Ctrl-C ahead of term' reads)

fortio.org/terminal/ansipixels

Go Reference

A much lower level library that allow direct control of both the input and the output of the terminal, including mouse tracking, clicks, drag events and modifiers, mousewheel decoding/querying and many functions to emit the corresponding ANSI escape codes (colors, cursor positioning etc). It include basic named colors, RGB colors, and Hue,Saturation,Luminance conversion to RGB as well as RGB to closest 256 color conversion for non truecolor terminals, in ansipixels/tcolor sub package.

Do feel free to use fortio.org/progressbar as well

See fortio.org/tclock for an additional demo of what this can do.

FPS

The tagged release of ansipixels used to includes a standalone binary, fps, that uses that package to test your terminal frames per second capabilities.

See the source github.com/fortio/fps/fps.go

You can get the binary from fps releases

Or just run (path is unchanged/preserved from original location)

CGO_ENABLED=0 go install fortio.org/terminal/fps@latest  # to install or just
CGO_ENABLED=0 go run fortio.org/terminal/fps@latest  # to run without install

or even

docker run -ti fortio/fps # but that's obviously slower

or

brew install fortio/tap/fps

Use the -image flag to pass a different image to load as background. Or use -i and fps is now just a terminal image viewer (in addition to keys, you can now zoom using the mousewheel, click to move the image - see ? for help).

Pass an optional maxfps as argument.

E.g fps -image my.jpg 60 will run at 60 fps with my.jpg as background.

After hitting any key to start the measurement, you can also resize the window at any time and fps will render with the new size. Use q to stop.

fps screenshot

Image viewer screenshot:

fps image viewer

Detailed statistics are saved in a JSON files and can be visualized or compared by running fortio report

fps fortio histogram

Hot (!) off the press a new -fire mode for fps (with space to toggle on/off and i to turn off the text):

FPS Fire mode
Usage

Additional flags/command help:

fps 0.27.0 usage:
        fps [flags] [maxfps] or fps -i imagefiles...
or 1 of the special arguments
        fps {help|envhelp|version|buildinfo}
flags:
  -color
        If your terminal supports color, this will load image in (216) colors instead of monochrome
  -fire
        Show fire animation instead of RGB around the image
  -gray
        Convert the image to grayscale
  -i    Arguments are now images files to show, no FPS test (hit any key to continue)
  -image string
        Image file to display in monochrome in the background instead of the default one
  -n number of frames
        Start immediately an FPS test with the specified number of frames (default is interactive)
  -nobox
        Don't draw the box around the image, make the image full screen instead of 1 pixel less on all sides
  -nojson
        Don't output json file with results that otherwise get produced and can be visualized with fortio report
  -nomouse
        Disable mouse tracking
  -truecolor
        If your terminal supports truecolor, this will load image in truecolor (24bits) instead of monochrome (default true)

Game of life

See life/ for a classic Conway's game of life black and white demo (with resizing, mouse edits, etc... supported).

Same installation as above, just replace fps by life.

life screenshot

Blackjack

See blackjack/ for a classic blackjack game against dealer.

Same installation as above, just replace fps by blackjack.

blackjack screenshot

Brick

Play an old time favorite, or watch replays of saved games... or even let the computer play!

See the options below.

brick screenshot

brick 0.20.0 usage:
	brick [flags]
or 1 of the special arguments
	brick {help|envhelp|version|buildinfo}
flags:
  -autoplay
    	Computer plays mode
  -fps float
    	Frames per second (default 30)
  -lives int
    	Number of lives - 0 is infinite (default 3)
  -nodeath
    	No death mode
  -nosave
    	Don't save the game as JSON (default is to save)
  -replay game
    	Replay a game from a JSON file
  -seed seed
    	Random number generator seed, default (0) is time based

Like for the others, to try if you have go:

go run fortio.org/terminal/brick@latest

or pick a binary from the releases

Nocolor

nocolor is a very simple unix style filter (source code, uses ansipixels.AnsiClean): it removes all ansi codes from the input stream and writes the filtered version, color free, to stdout.

To install if you have go:

go install fortio.org/terminal/nocolor@latest
# then
somethingProducingColors | nocolor

Or on a mac

brew install fortio/tap/nocolor

Or pick a binary from the releases

Documentation

Overview

Package terminal provides a library to interact with ansi/v100 style terminals, readline style. It wraps golang.org/x/term and adds history, prompt, auto-completion and interrupt handling (control-C and signals). It also provides a way to suspend the terminal (restore normal mode) to run sub commands and resume it back to raw mode. It also provides a way to share a single InterruptReader between multiple users of the terminal (for instance both Terminal.ReadLine and AnsiPixels.ReadOrResizeOrSignal can share it). See example/main.go for an example of usage.

Index

Constants

View Source
const CtrlC = 3 // Control-C is ascii 3 (C is 3rd letter of the alphabet)
View Source
const DefaultHistoryCapacity = 99

DefaultHistoryCapacity is the default number of entries in the history (99). History index 1-99 prints using %02d.

View Source
const IsUnix = true

Variables

View Source
var (
	ErrUserInterrupt = NewErrInterrupted("terminal interrupted by user")
	ErrStopped       = NewErrInterrupted("interrupt reader stopped") // not really an error more of a marker.
	ErrSignal        = NewErrInterrupted("signal received")
)
View Source
var DefaultReaderTimeout = 250 * time.Millisecond

DefaultReaderTimeout is the default timeout for the timeout reader.

View Source
var ErrDataTruncated = errors.New("data truncated")

Functions

func CRLFWrite added in v0.57.0

func CRLFWrite(out io.Writer, buf []byte) (n int, err error)

func LoggerSetup added in v0.38.0

func LoggerSetup(out io.Writer)

LoggerSetup sets up fortio logger (and thus stdlib "log" too) to write to the terminal as needed to preserve prompt/work in raw mode (ie add \r before \n). If stderr has been redirected, it doesn't do anything (logs to json in said case).

func ReadWithTimeout added in v0.17.0

func ReadWithTimeout(fd int, tv *unix.Timeval, buf []byte) (int, error)

func SleepWithContext added in v0.8.0

func SleepWithContext(ctx context.Context, duration time.Duration) error

func TimeoutToTimeval added in v0.8.1

func TimeoutToTimeval(timeout time.Duration) *unix.Timeval

Types

type AutoCompleteCallback

type AutoCompleteCallback func(t *Terminal, line string, pos int, key rune) (newLine string, newPos int, ok bool)

AutoCompleteCallback is called with "this" terminal as first argument so AutoCompleteCallback can use t.Out etc. (compared to the original x/term callback).

type Bufio added in v0.57.0

type Bufio interface {
	FlushWriter
	io.StringWriter
	io.ByteWriter
	WriteRune(r rune) (n int, err error)
}

type CRLFWriter added in v0.38.0

type CRLFWriter struct {
	// Out is the underlying writer to write to.
	Out io.Writer
}

func (*CRLFWriter) Flush added in v0.57.0

func (w *CRLFWriter) Flush() error

func (*CRLFWriter) Write added in v0.38.0

func (w *CRLFWriter) Write(buf []byte) (n int, err error)

type FlushWriter added in v0.57.0

type FlushWriter interface {
	io.Writer
	Flush() error
}

type FlushableBytesBuffer added in v0.57.0

type FlushableBytesBuffer struct {
	bytes.Buffer
}

func (*FlushableBytesBuffer) Flush added in v0.57.0

func (b *FlushableBytesBuffer) Flush() error

type FlushableStringBuilder added in v0.57.0

type FlushableStringBuilder struct {
	strings.Builder
}

func (*FlushableStringBuilder) Flush added in v0.57.0

func (b *FlushableStringBuilder) Flush() error

type InterruptReader added in v0.8.0

type InterruptReader struct {
	In *os.File // stdin typically
	// contains filtered or unexported fields
}

InterruptReader is a reader that can be interrupted by Ctrl-C or signals. It supports both blocking and non-blocking modes based on the timeout value provided during initialization. When stopped the reads are directly to the underlying timeoutreader.

func GetSharedInput added in v0.36.0

func GetSharedInput(maxRead time.Duration) *InterruptReader

GetSharedInput returns a shared input that can be used by multiple callers wanting to interact with the terminal in raw mode. For instance both Terminal.ReadLine and AnsiPixels.ReadOrResizeOrSignal can share it. It also changes the timeout for the timeout reader to the maxRead duration if different than before. If 0 timeout is used, it can't be changed later and the reader will block on reads (raw/simple os.Stdin mode).

func NewInterruptReader added in v0.8.0

func NewInterruptReader(reader *os.File, bufSize int, timeout time.Duration) *InterruptReader

NewInterruptReader creates a new interrupt reader. It needs to be Start()ed to start reading from the underlying reader to intercept Ctrl-C and listen for interrupt signals. When not started, it just reads directly from the underlying timeout reader (which can be blocking if timeout is 0). Use GetSharedInput() to get a shared interrupt reader across libraries/caller. Using 0 as the timeout disables most layers and uses the underlying reader directly (blocking IOs). When not in blocking mode, one of [Start] or [StartDirect] must be called after creating it to add the intermediate layer. Note doing it in NewInterruptReader() allows for logger configuration to happen single threaded and thus avoid races.

func (*InterruptReader) ChangeTimeout added in v0.36.0

func (ir *InterruptReader) ChangeTimeout(timeout time.Duration)

func (*InterruptReader) Close added in v0.36.0

func (ir *InterruptReader) Close() error

Close restores the terminal to its original state and closes the underlying timeout reader. That ends the polling goroutine in non select OSes/mode but doesn't impact the underlying stream (os.Stdin). It also returns the terminal to normal mode.

func (*InterruptReader) InEOF added in v0.36.0

func (ir *InterruptReader) InEOF() bool

func (*InterruptReader) NormalMode added in v0.36.0

func (ir *InterruptReader) NormalMode() error

NormalMode sets the terminal to normal mode. It's a no-op if the terminal is already in normal mode.

func (*InterruptReader) PrimeReadImmediate added in v0.62.0

func (ir *InterruptReader) PrimeReadImmediate(p []byte)

func (*InterruptReader) Raw added in v0.36.0

func (ir *InterruptReader) Raw() bool

Raw returns true if the terminal is currently in raw mode.

func (*InterruptReader) RawMode added in v0.36.0

func (ir *InterruptReader) RawMode() error

RawMode sets the terminal to raw mode. It's a no-op if the terminal is already in raw mode. Must typically defer ir.NormalMode() after calling this to avoid leaving the terminal in raw mode upon exit/panic.

func (*InterruptReader) Read added in v0.8.0

func (ir *InterruptReader) Read(p []byte) (int, error)

Read implements io.Reader interface.

func (*InterruptReader) ReadBlocking added in v0.59.0

func (ir *InterruptReader) ReadBlocking(p []byte) (int, error)

ReadBlocking reads from the underlying reader in blocking mode (without timeout).

func (*InterruptReader) ReadImmediate added in v0.59.0

func (ir *InterruptReader) ReadImmediate() (int, error)

ReadImmediate returns immediately with something readily available to read, if any, that happened since PrimeReadImmediate. On unix it means a select with 0 timeout, on windows it means checking the goroutine channel for something already read. Call is split into 2 parts for when not being able to select.

func (*InterruptReader) ReadLine added in v0.37.0

func (ir *InterruptReader) ReadLine() (string, error)

ReadLine reads until \r or \n (for use when not in rawmode). It returns the line (without the \r, \n, or \r\n).

func (*InterruptReader) ReadNonBlocking added in v0.36.0

func (ir *InterruptReader) ReadNonBlocking(p []byte) (int, error)

ReadNonBlocking will read what is available already or return 0, nil if nothing is available.

func (*InterruptReader) ReadWithTimeout added in v0.58.0

func (ir *InterruptReader) ReadWithTimeout(p []byte) (int, error)

ReadWithTimeout reads directly from the underlying reader, bypassing the interrupt handling but still subject to the timeout set on said underlying reader.

func (*InterruptReader) Start added in v0.8.0

Start or restart (after a cancel/interrupt) the interrupt reader.

func (*InterruptReader) StartDirect added in v0.59.0

func (ir *InterruptReader) StartDirect()

StartDirect ensures the underlying reader is started (in case of non blocking mode), this is used by [ansipixels.Open].

func (*InterruptReader) Stop added in v0.9.0

func (ir *InterruptReader) Stop()

type InterruptedError added in v0.8.1

type InterruptedError struct {
	DetailedReason string
	OriginalError  error
}

func NewErrInterrupted added in v0.8.1

func NewErrInterrupted(reason string) InterruptedError

func NewErrInterruptedWithErr added in v0.8.1

func NewErrInterruptedWithErr(reason string, err error) InterruptedError

func (InterruptedError) Error added in v0.8.1

func (e InterruptedError) Error() string

func (InterruptedError) Unwrap added in v0.8.1

func (e InterruptedError) Unwrap() error

type SyncWriter added in v0.57.0

type SyncWriter struct {
	// Out is the underlying writer to write to.
	Out Bufio
	// contains filtered or unexported fields
}

SyncWriter is a threadsafe wrapper around a most of the APIs of bufio.Writer.

func (*SyncWriter) Flush added in v0.57.0

func (w *SyncWriter) Flush() error

func (*SyncWriter) Lock added in v0.57.0

func (w *SyncWriter) Lock()

Lock: Shares the underlying lock.

func (*SyncWriter) Unlock added in v0.57.0

func (w *SyncWriter) Unlock()

Unlock: Shares the underlying lock.

func (*SyncWriter) Write added in v0.57.0

func (w *SyncWriter) Write(buf []byte) (n int, err error)

func (*SyncWriter) WriteByte added in v0.57.0

func (w *SyncWriter) WriteByte(c byte) error

func (*SyncWriter) WriteRune added in v0.57.0

func (w *SyncWriter) WriteRune(r rune) (n int, err error)

func (*SyncWriter) WriteString added in v0.57.0

func (w *SyncWriter) WriteString(s string) (n int, err error)

type SystemTimeoutReader added in v0.62.0

type SystemTimeoutReader = TimeoutReaderUnixFD

type TermHistory added in v0.32.0

type TermHistory struct {

	// AutoHistory, if true, causes lines to be automatically added to the history (through term's History.Add()).
	// If false, call AddToHistory to add lines to the history for instance only adding
	// successful commands. Defaults to true. This is controlled through AutoHistory(bool).
	AutoHistory bool
	// contains filtered or unexported fields
}

TermHistory is a ring buffer of strings.

func NewHistory added in v0.32.0

func NewHistory(capacity int) *TermHistory

NewHistory creates a new ring buffer of strings with the given capacity.

func (*TermHistory) Add added in v0.32.0

func (th *TermHistory) Add(a string)

Add is the term.History interface implementation and conditionally adds a string to the ring buffer based on the autoHistory flag.

func (*TermHistory) At added in v0.32.0

func (th *TermHistory) At(n int) string

At returns the value passed to the nth previous call to Add. If n is zero then the immediately prior value is returned, if one, then the next most recent, and so on. If such an element doesn't exist then ok is false.

func (*TermHistory) Len added in v0.32.0

func (th *TermHistory) Len() int

Len returns the current number of elements in the ring.

func (*TermHistory) Replace added in v0.32.0

func (th *TermHistory) Replace(a string) string

Replace theoretically could panic on an empty ring buffer but it's harmless on strings.

func (*TermHistory) UnconditionalAdd added in v0.32.0

func (th *TermHistory) UnconditionalAdd(a string)

UnconditionalAdd unconditionally add a string to the ring buffer.

type Terminal

type Terminal struct {
	// Use this for any output to the screen/console so the required \r are added in raw mode
	// the prompt and command edit is refresh as needed when input comes in.
	Out io.Writer
	// Cancellable context after Open(). Use it to cancel the terminal reading or check for done.
	Context context.Context //nolint:containedctx // To avoid Open() returning 4 values.
	Cancel  context.CancelFunc

	// [InterruptReader.Read] can read from the underlying terminal instead of a full line with history and prompt.
	// Can be used to read single keystrokes or events still in raw mode, without waiting for a new line.
	// [InterruptReader.ReadNonBlocking] reads from the underlying terminal if there is data available.
	// Can be used to check for single keystrokes or events still in raw mode,
	// while refreshing the output (ie without blocking).
	IntrReader *InterruptReader

	// Terminal (last updated) width.
	Width int
	// Terminal (last updated) height.
	Height int
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context) (*Terminal, error)

Open opens stdin as a terminal, do `defer terminal.Close()` to restore the terminal to its original state upon exit. fortio.org/log (and thus stdlib "log") will be redirected to the terminal in a manner that preserves the prompt. A default 250ms InterruptReader is used if not set already. New cancellable context is set, use it to cancel the terminal reading or check for done for control-c or signal. You can also call [Setup] to customize the terminal with a custom InterruptReader and/or a custom history.

func (*Terminal) AddToHistory added in v0.4.0

func (t *Terminal) AddToHistory(commands ...string)

AddToHistory add commands to the TermHistory.

func (*Terminal) AutoHistory added in v0.5.0

func (t *Terminal) AutoHistory() bool

AutoHistory returns the current auto history setting.

func (*Terminal) Close

func (t *Terminal) Close() error

Close restores the terminal to its original state. Must be called at exit to avoid leaving the terminal in raw mode. Safe to call multiple times. Will save the history to the history file if one was set using [SetHistoryFile] and the capacity is > 0.

func (*Terminal) History added in v0.4.0

func (t *Terminal) History() []string

History returns the current history state.

func (*Terminal) IsTerminal

func (t *Terminal) IsTerminal() bool

func (*Terminal) LastWasPaste added in v0.39.0

func (t *Terminal) LastWasPaste() bool

LastWasPaste returns true if the last ReadLine was a multiline paste.

func (*Terminal) NewHistory added in v0.4.0

func (t *Terminal) NewHistory(capacity int)

NewHistory creates/resets the history to a new one with the given capacity. Using 0 as capacity will disable history reading and writing but not change the underlying history state from it's DefaultHistoryCapacity.

func (*Terminal) ReadLine

func (t *Terminal) ReadLine() (string, error)

ReadLine reads a line from the terminal using the setup prompt and history and edit capabilities. Returns the line and an error if any. io.EOF is returned when the user presses Control-D. ErrInterrupted is returned when the user presses Control-C or a signal is received. We forward to term.ReadLine when in raw mode, otherwise we read until \n or \r. x/term.ReadLine unfortunately doesn't support \n, so we need to handle that ourselves.

func (*Terminal) ReplaceLatest added in v0.5.0

func (t *Terminal) ReplaceLatest(command string) string

ReplaceLatest replaces the current history with the given commands, returns the previous value. Enables to add invalid commands to the history for editing purpose and replace them with the corrected version. Returns the replaced entry.

func (*Terminal) ResetInterrupts added in v0.8.0

func (t *Terminal) ResetInterrupts(ctx context.Context) (context.Context, context.CancelFunc)

ResetInterrupts resets and restarts if you want to continue after an interrupt.

func (*Terminal) Resume added in v0.9.0

func (*Terminal) SaveHistory added in v0.64.1

func (t *Terminal) SaveHistory()

SaveHistory saves the current history to the history file set by [SetHistoryFile]. This is also called automatically by [Close]. This method allows callers to flush history at any time (e.g., before a WASM page unload).

func (*Terminal) SetAutoCompleteCallback

func (t *Terminal) SetAutoCompleteCallback(f AutoCompleteCallback)

SetAutoCompleteCallback sets the callback called for each key press. Can be used to implement auto completion. See example/main.go for an example.

func (*Terminal) SetAutoHistory added in v0.5.0

func (t *Terminal) SetAutoHistory(enabled bool)

SetAutoHistory enables/disables auto history (default is enabled).

func (*Terminal) SetHistoryFile

func (t *Terminal) SetHistoryFile(f string) error

SetHistoryFile sets up a file to load and save history from/to. File is being read when this is called. If no error is returned, the file will also be automatically updated on Close().

func (*Terminal) SetPrompt

func (t *Terminal) SetPrompt(s string)

SetPrompt sets or change the prompt.

func (*Terminal) Setup added in v0.36.0

func (t *Terminal) Setup(ctx context.Context) error

func (*Terminal) Suspend added in v0.9.0

func (t *Terminal) Suspend()

Suspend temporarily suspends/resumes the terminal back to normal (for example to run a sub process). use defer t.Resume() after calling Suspend() to put the terminal back in raw mode.

func (*Terminal) UpdateSize added in v0.30.0

func (t *Terminal) UpdateSize() error

UpdateSize refreshes the terminal size to current size (so wrapping works). This is called automatically when the terminal is opened, but can be called again if the terminal size changes (e.g. when resizing the window).

type TimeoutReader added in v0.8.1

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

TimeoutReader wraps an io.Reader (typically os.Stdin) to provide read operations with a timeout using a persistent background reader goroutine and internal buffering. It also allows a reset/restart without loosing data to a leftover/pending read if the reset is triggered by say reading a ^C from the input (which will unblock the read).

func NewTimeoutReader added in v0.17.0

func NewTimeoutReader(stream io.Reader, timeout time.Duration) *TimeoutReader

NewTimeoutReader creates a new TimeoutReader with a persistent background reader. The timeout applies to each Read call waiting for new data. A duration of 0 or less is invalid and will panic.

func (*TimeoutReader) ChangeTimeout added in v0.17.0

func (tr *TimeoutReader) ChangeTimeout(newTimeout time.Duration)

ChangeTimeout updates the timeout duration for subsequent Read calls when waiting for new data from the background reader. If called currently it will block until the current read completes.

func (*TimeoutReader) Close added in v0.33.0

func (tr *TimeoutReader) Close() error

Close signals the background reader goroutine to stop and waits for it to exit. It purposely doesn't close the underlying file unless in blocking mode and it implements io.Closer.

func (*TimeoutReader) IsClosed added in v0.36.0

func (tr *TimeoutReader) IsClosed() bool

IsClosed returns true if Close() has been called (and for the other implementation a new one should be created).

func (*TimeoutReader) PrimeReadImmediate added in v0.62.0

func (tr *TimeoutReader) PrimeReadImmediate(buf []byte)

PrimeReadImmediate starts a read to be returned later by ReadImmediate.

func (*TimeoutReader) Read added in v0.17.0

func (tr *TimeoutReader) Read(buf []byte) (int, error)

Read attempts to read into the buffer buf. It first reads from an internal buffer. If the buffer is empty, it waits up to the configured timeout for new data from the background reader. Returns the number of bytes read and an error. If a timeout occurs while waiting for new data, it returns (0, nil), indicating no data read and no error. Note: You should not call Read() with a smaller buffer than the first one when it returns early due to timeout as to avoid extra allocations the inflight buffer will be used and thus could have more data than the new buffer, it will be lost/truncated in that case and the error ErrDataTruncated will be returned.

func (*TimeoutReader) ReadBlocking added in v0.59.0

func (tr *TimeoutReader) ReadBlocking(buf []byte) (int, error)

ReadBlocking is like Read but makes sure something (or an error) is returned/read.

func (*TimeoutReader) ReadImmediate added in v0.59.0

func (tr *TimeoutReader) ReadImmediate() (int, error)

ReadImmediate to return immediately what was read since PrimeReadImmediate if any. Data is returned into the buffer provided in PrimeReadImmediate.

func (*TimeoutReader) ReadWithTimeout added in v0.62.0

func (tr *TimeoutReader) ReadWithTimeout(buf []byte) (int, error)

ReadWithTimeout is an alias to TimeoutReader.Read for the InputReader interface compatibility.

type TimeoutReaderUnixFD added in v0.62.0

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

func NewSystemTimeoutReader added in v0.62.0

func NewSystemTimeoutReader(stream *os.File, timeout time.Duration) *TimeoutReaderUnixFD

func NewTimeoutReaderUnixFD added in v0.62.0

func NewTimeoutReaderUnixFD(stream *os.File, timeout time.Duration) *TimeoutReaderUnixFD

func (*TimeoutReaderUnixFD) ChangeTimeout added in v0.62.0

func (tr *TimeoutReaderUnixFD) ChangeTimeout(timeout time.Duration)

ChangeTimeout on unix should be called from same goroutine as any Read* or not concurrently.

func (*TimeoutReaderUnixFD) Close added in v0.62.0

func (tr *TimeoutReaderUnixFD) Close() (err error)

Close closes the underlying stream if we are in blocking mode. nop otherwise.

func (*TimeoutReaderUnixFD) IsClosed added in v0.62.0

func (tr *TimeoutReaderUnixFD) IsClosed() bool

IsClosed returns true if Close() has been called (and for the other implementation a new one should be created). Always false on unix/select mode because we can keep using it forever, unlike the goroutine based one. Unless we are in blocking mode and Close() was called.

func (*TimeoutReaderUnixFD) PrimeReadImmediate added in v0.62.0

func (tr *TimeoutReaderUnixFD) PrimeReadImmediate(buf []byte)

func (*TimeoutReaderUnixFD) Read added in v0.62.0

func (tr *TimeoutReaderUnixFD) Read(buf []byte) (int, error)

func (*TimeoutReaderUnixFD) ReadBlocking added in v0.62.0

func (tr *TimeoutReaderUnixFD) ReadBlocking(buf []byte) (int, error)

func (*TimeoutReaderUnixFD) ReadImmediate added in v0.62.0

func (tr *TimeoutReaderUnixFD) ReadImmediate() (int, error)

func (*TimeoutReaderUnixFD) ReadWithTimeout added in v0.62.0

func (tr *TimeoutReaderUnixFD) ReadWithTimeout(buf []byte) (int, error)

Directories

Path Synopsis
Package ansipixels provides terminal drawing and key reading abilities.
Package ansipixels provides terminal drawing and key reading abilities.
linetest command
tcolor
Package tcolor provides ANSI color codes and utilities for terminal colors.
Package tcolor provides ANSI color codes and utilities for terminal colors.
cli
cli
* A more interesting/real example is https://github.com/grol-io/grol * but this demonstrates most of the features of the terminal package.
* A more interesting/real example is https://github.com/grol-io/grol * but this demonstrates most of the features of the terminal package.
fps module
cli
nocolor is a simple utility to filter out all Ansi (color, cursor movement, etc...) sequences from stdin to stdout.
nocolor is a simple utility to filter out all Ansi (color, cursor movement, etc...) sequences from stdin to stdout.

Jump to

Keyboard shortcuts

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