Documentation
¶
Index ¶
- Constants
- func QuotedArgs(args []string) string
- type ExecJob
- type FinalizedJobs
- type Job
- type JobLimiter
- type JobResultMessage
- type JobRunner
- type JobRunnerOpts
- type JobRunners
- func (j JobRunners) Finalize() (FinalizedJobs, bool)
- func (j JobRunners) Init() tea.Cmd
- func (j JobRunners) SetJobHeight(height int) tea.Cmd
- func (j JobRunners) SetTotalHeight(totalHeight int) tea.Cmd
- func (j JobRunners) Stop() tea.Cmd
- func (j JobRunners) Update(msg tea.Msg) (JobRunners, tea.Cmd)
- func (j JobRunners) View() string
- type JobStopMessage
- type LineBuffer
- type LineWriter
Constants ¶
const MaxLineBufferHeight = 128
MaxLineBufferHeight is the maximum number of lines that can be buffered in the LineBuffer.
const TimeTakenAccuracy = time.Millisecond
TimeTakenAccuracy is the accuracy for displaying the time taken for a job. This is only useful for time.Duration.String.
Variables ¶
This section is empty.
Functions ¶
func QuotedArgs ¶
QuotedArgs returns a string representation of the arguments, each quoted if needed. It is similar to strconv.Quote.
Types ¶
type ExecJob ¶
ExecJob is a job that wraps an exec.Cmd.
func NewExecJobs ¶
NewExecJobs creates a new ExecJob for each command.
func (*ExecJob) SetCustomString ¶
SetCustomString sets a custom string representation for the job.
type FinalizedJobs ¶
type FinalizedJobs []*JobResultMessage
FinalizedJobs contains the results of jobs. It is always of length equal to the number of jobs that have been run, but jobs that have not yet completed will have a nil value in the slice.
func (FinalizedJobs) Errors ¶
func (j FinalizedJobs) Errors() []error
Errors collects all the errors from the job result messages in the slice.
func (FinalizedJobs) HasError ¶
func (j FinalizedJobs) HasError() bool
HasError checks if any of the job result messages in the slice contain an error.
func (FinalizedJobs) IsDone ¶
func (j FinalizedJobs) IsDone() bool
IsDone checks if all the job result messages in the slice are done, meaning there is no nil values.
func (FinalizedJobs) NumFinishedJobs ¶
func (j FinalizedJobs) NumFinishedJobs() int
NumFinishedJobs counts the number of jobs that have completed.
type Job ¶
type Job interface {
fmt.Stringer
StdoutPipe() (io.ReadCloser, error)
StderrPipe() (io.ReadCloser, error)
// Start initiates the job and returns an error if it fails to start.
Start() error
// Stop stops the job and returns an error if it fails to stop.
Stop() error
// Wait blocks until the job completes and returns an error if it fails.
Wait() error
}
Job defines the interface for a job that can be run concurrently. It is defined as a subset of the standard library's os/exec.Cmd interface.
type JobLimiter ¶
type JobLimiter struct {
// contains filtered or unexported fields
}
JobLimiter is a simple semaphore implementation that can be used to limit the number of concurrent jobs running at any given time.
A zero value JobLimiter will not limit the number of concurrent jobs.
func NewJobLimiter ¶
func NewJobLimiter(limit int) JobLimiter
NewJobLimiter creates a new JobLimiter.
type JobResultMessage ¶
JobResultMessage is a message that contains the result of a job.
func (*JobResultMessage) HasError ¶
func (j *JobResultMessage) HasError() bool
HasError returns true if the job has an error.
func (*JobResultMessage) IsDone ¶
func (j *JobResultMessage) IsDone() bool
IsDone returns true if the job has finished running.
func (*JobResultMessage) IsStarted ¶
func (j *JobResultMessage) IsStarted() bool
IsStarted returns true if the job has started running. A finished job is still considered started, so this will return true.
type JobRunner ¶
type JobRunner struct {
// contains filtered or unexported fields
}
JobRunner is a running Job instance.
func NewJobRunner ¶
func NewJobRunner(job Job, id string, opts JobRunnerOpts) *JobRunner
NewJobRunner creates a new JobRunner.
type JobRunnerOpts ¶
type JobRunnerOpts struct {
JobLimiter JobLimiter
LastLines int
OutputDir string
CombinedOutputs bool
}
type JobRunners ¶
type JobRunners struct {
// contains filtered or unexported fields
}
JobRunners is a collection of JobRunner instances.
func NewJobRunners ¶
func NewJobRunners[JobT Job](jobs []JobT, opts JobRunnerOpts) JobRunners
NewJobRunners creates a slice of JobRunner instances from a slice of Job.
func (JobRunners) Finalize ¶
func (j JobRunners) Finalize() (FinalizedJobs, bool)
Finalize returns the job results if all jobs are done. If not, it returns nil and false. If all jobs are done, it returns the results and true.
func (JobRunners) Init ¶
func (j JobRunners) Init() tea.Cmd
func (JobRunners) SetJobHeight ¶
func (j JobRunners) SetJobHeight(height int) tea.Cmd
SetJobHeight returns a command that sets the height for each job runner. It overrides [SetTotalHeight].
func (JobRunners) SetTotalHeight ¶
func (j JobRunners) SetTotalHeight(totalHeight int) tea.Cmd
SetTotalHeight returns a command that sets the total height for all the job runners. It overrides [SetJobHeight].
func (JobRunners) Stop ¶
func (j JobRunners) Stop() tea.Cmd
Stop returns a tea.Cmd that will stop all the jobs in the JobRunners collection.
func (JobRunners) Update ¶
func (j JobRunners) Update(msg tea.Msg) (JobRunners, tea.Cmd)
func (JobRunners) View ¶
func (j JobRunners) View() string
type JobStopMessage ¶
type JobStopMessage struct {
Job *JobRunner
}
JobStopMessage is a message that is sent to signal a job to stop running.
type LineBuffer ¶
LineBuffer is a UI element that buffers the last few lines of text.
func (LineBuffer) Init ¶
func (l LineBuffer) Init() tea.Cmd
func (LineBuffer) LineWriter ¶
func (l LineBuffer) LineWriter() LineWriter
LineWriter returns a LineWriter that writes lines to [l].
func (LineBuffer) SetHeight ¶
func (l LineBuffer) SetHeight(height int) tea.Cmd
SetHeight sets the height of the line buffer. The height can not be higher than
func (LineBuffer) Update ¶
func (l LineBuffer) Update(msg tea.Msg) (LineBuffer, tea.Cmd)
func (LineBuffer) View ¶
func (l LineBuffer) View() string
View returns the buffered lines as a single string.
type LineWriter ¶
LineWriter is an interface for writing lines of text. It is used to write lines to different outputs, such as a buffer or a file.