taskin

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

README


📋 Add user-friendly tasks to your terminal


Multi

Release Go Report Card Go Reference Lint Tests PRs Welcome Examples Phorm

[!TIP]

All output is Github Action friendly! You can view the output of each example here

Installation

go get github.com/fumeapp/taskin

Examples

Simplest way to line up and fire off tasks

https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/examples/simple/main.go#L11-L33

Simple

Using a progress bar for a task

https://github.com/fumeapp/taskin/blob/06b4d112f7d2dcf9fb4ee9b210f0be2d5cda03b5/examples/progress/main.go#L11-L24

Progress

Customize colors, spinner, and progress bar

https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/examples/custom/main.go#L13-L54

Custom

Nest tasks inside tasks

https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/examples/multi/main.go#L23-L34

Multi

Usage inside a task

The *taskin.Task struct passeed into your task has some useful properties that you can use to customize the task view.

Change the title

Already demonstrated in most of the examples, you can change t.Title at any time

Hide a view

Sometimes you might need to temporarily hide you task view in order to prompt a user for input. You can do this by toggling the task.HideView boolean.

Task: func(T *taskin.Task ) error {
	t.HideView = true
	if err := PromptForInput(); err != nil {
		t.HideView = false
        return err
    }
    t.HideView = false
	t.Title = "Input received"
	return nil
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Defaults = Config{
	Options: ConfigOptions{
		ExitOnFailure: true,
	},
	Spinner: spinner.Dot,
	ProgressOptions: []progress.Option{
		progress.WithDefaultGradient(),
		progress.WithoutPercentage(),
		progress.WithWidth(10),
	},
	Colors: ConfigColors{
		Spinner:       lipgloss.Color("214"),
		Pending:       lipgloss.Color("lightgrey"),
		Success:       lipgloss.Color("46"),
		Failure:       lipgloss.Color("196"),
		ParentStarted: lipgloss.Color("214"),
	},
	Chars: ConfigChars{
		ParentStarted: "»",
		NotStarted:    "•",
		Success:       "✔",
		Failure:       "✘",
	},
}

Functions

func Color added in v0.1.5

func Color(c lipgloss.TerminalColor, r string) string

func IsCI added in v0.1.3

func IsCI() bool

Types

type Config

type Config struct {
	Options         ConfigOptions
	Spinner         spinner.Spinner
	Colors          ConfigColors
	ProgressOptions []progress.Option
	Chars           ConfigChars
}

type ConfigChars

type ConfigChars struct {
	ParentStarted string
	NotStarted    string
	Success       string
	Failure       string
}

type ConfigColors

type ConfigColors struct {
	Spinner       lipgloss.Color
	Pending       lipgloss.Color
	Success       lipgloss.Color
	Failure       lipgloss.Color
	ParentStarted lipgloss.Color
}

type ConfigOptions

type ConfigOptions struct {
	ExitOnFailure bool
}

type Model added in v0.1.5

type Model struct {
	Runners       Runners
	HideView      bool
	Shutdown      bool
	ShutdownError error
}

func (*Model) Init added in v0.1.5

func (m *Model) Init() tea.Cmd

func (*Model) SetShutdown added in v0.1.5

func (m *Model) SetShutdown(err error)

func (*Model) Update added in v0.1.5

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Model) View added in v0.1.5

func (m *Model) View() string

type Runner

type Runner struct {
	Task     Task
	State    TaskState
	Spinner  *spinner.Model
	Config   Config
	Children Runners
}

func NewRunner

func NewRunner(task Task, cfg Config) Runner

type Runners

type Runners []Runner

func New

func New(tasks Tasks, cfg Config) Runners

func (*Runners) Run

func (r *Runners) Run() error

type Task

type Task struct {
	Title        string
	Task         func(*Task) error
	ShowProgress TaskProgress
	Bar          progress.Model
	Config       Config
	Tasks        Tasks
	HideView     bool
}

func (*Task) Progress

func (task *Task) Progress(current, total int)

type TaskProgress

type TaskProgress struct {
	Current int
	Total   int
}

type TaskState

type TaskState int
const (
	NotStarted TaskState = iota
	Running
	Completed
	Failed
)

type Tasks

type Tasks []Task

type TerminateWithError added in v0.1.5

type TerminateWithError struct {
	Error error
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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