tasks

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const COMMAND_START_THRESHOLD = time.Millisecond * 10

we use this to check if the system is under stress right now. Hopefully this makes sense on other machines

View Source
const THROTTLE_TIME = time.Millisecond * 30

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncHandler added in v0.30.1

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

the purpose of an AsyncHandler is to ensure that if we have multiple long-running requests, we only handle the result of the latest one. For example, if I am searching for 'abc' and I have to type 'a' then 'b' then 'c' and each keypress dispatches a request to search for things with the string so-far, we'll be searching for 'a', 'ab', and 'abc', and it may be that 'abc' comes back first, then 'ab', then 'a' and we don't want to display the result for 'a' just because it came back last. AsyncHandler keeps track of the order in which things were dispatched so that we can ignore anything that comes back late.

func NewAsyncHandler added in v0.30.1

func NewAsyncHandler(onWorker func(func(gocui.Task) error)) *AsyncHandler

func (*AsyncHandler) Do added in v0.30.1

func (self *AsyncHandler) Do(f func() func())

type Cmd added in v0.63.0

type Cmd interface {
	Wait() error
	String() string
	// Terminate makes the process stop early, as gracefully as the platform
	// allows. It doesn't wait for the process to exit.
	Terminate() error
}

Cmd abstracts over a started external process. *exec.Cmd satisfies the bulk of it via ExecCmd, but pty implementations can supply their own types — on Windows, ConPTY has to spawn via CreateProcess directly and can't use *exec.Cmd (see golang/go#62708).

type ExecCmd added in v0.63.0

type ExecCmd struct {
	*exec.Cmd
}

ExecCmd adapts *exec.Cmd to Cmd.

func (ExecCmd) Terminate added in v0.64.0

func (c ExecCmd) Terminate() error

Terminate sends SIGTERM on Unix. On Windows it does nothing, so a stopped command keeps running until it next writes to its (by then closed) output pipe.

type LinesToRead added in v0.38.0

type LinesToRead struct {
	// The total number of lines the task should have read once this request is
	// satisfied. This is an absolute count from the start of the task, not a
	// delta: the task keeps track of how many lines it has already read and only
	// reads the shortfall, so a request for a total at or below what has already
	// been read reads nothing. -1 means read all the way to the end.
	Total int

	// Number of lines after which we have read enough to fill the view, and can
	// do an initial refresh. Only set for the initial read request; -1 for
	// subsequent requests.
	InitialRefreshAfter int

	// Function to call after reading the lines is done
	Then func()
}

type TaskOpts added in v0.39.0

type TaskOpts struct {
	// Channel that tells the task to stop, because another task wants to run.
	Stop chan struct{}

	// Only for tasks which are long-running, where we read more lines sporadically.
	// We use this to keep track of when a user's action is complete (i.e. all views
	// have been refreshed to display the results of their action)
	InitialContentLoaded func()
}

type ViewBufferManager

type ViewBufferManager struct {
	Log *logrus.Entry
	// contains filtered or unexported fields
}

func NewViewBufferManager

func NewViewBufferManager(
	log *logrus.Entry,
	writer io.Writer,
	beforeStart func(),
	refreshView func(),
	onEndOfInput func(),
	onNewKey func(),
	newGocuiTask func() gocui.Task,
	onUIThread func(f func() error) error,
) *ViewBufferManager

func (*ViewBufferManager) Close

func (self *ViewBufferManager) Close()

Close closes the task manager, killing whatever task may currently be running

func (*ViewBufferManager) GetTaskKey added in v0.30.1

func (self *ViewBufferManager) GetTaskKey() string

func (*ViewBufferManager) NewCmdTask

func (self *ViewBufferManager) NewCmdTask(start func() (Cmd, io.Reader), prefix string, linesToRead LinesToRead, onDoneFn func()) func(TaskOpts) error

func (*ViewBufferManager) NewTask

func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error

func (*ViewBufferManager) ReadLines

func (self *ViewBufferManager) ReadLines(totalLines int)

ReadLines asks the task to ensure it has read at least totalLines lines in total. Because the count is absolute rather than a delta, repeated requests (e.g. as the user scrolls down, back up, and down again) don't re-read lines that have already been read: the task only ever reads the shortfall.

func (*ViewBufferManager) ReadToEnd added in v0.50.0

func (self *ViewBufferManager) ReadToEnd(then func())

Jump to

Keyboard shortcuts

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