📋 Add user-friendly tasks to your terminal
Tip
All output is Github Action friendly!
You can view the output of each example here
go get github.com/fumeapp/taskin
Simplest way to line up and fire off tasks
|
tasks := taskin.New(taskin.Tasks{ |
|
{ |
|
Title: "Task 1", |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 3; i++ { |
|
t.Title = fmt.Sprintf("Task 1: [%d/3] seconds have passed", i+1) |
|
time.Sleep(500 * time.Millisecond) |
|
} |
|
return nil |
|
}, |
|
}, |
|
{ |
|
Title: "Task 2", |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 3; i++ { |
|
t.Title = fmt.Sprintf("Task 2: [%d/3] seconds have passed", i+1) |
|
time.Sleep(500 * time.Millisecond) |
|
} |
|
return fmt.Errorf("task 2 failed") |
|
}, |
|
}, |
|
}, taskin.Defaults) |
|
err := tasks.Run() |
Using a progress bar for a task
|
tasks := taskin.New(taskin.Tasks{ |
|
{ |
|
Title: "Progress", |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 5; i++ { |
|
t.Progress(i+1, 5) |
|
t.Title = fmt.Sprintf("Progress [%d/%d]", i+1, 5) |
|
time.Sleep(1 * time.Second) |
|
} |
|
return nil |
|
}, |
|
}, |
|
}, taskin.Defaults) |
|
err := tasks.Run() |
Customize colors, spinner, and progress bar
|
tasks := taskin.New(taskin.Tasks{ |
|
{ |
|
Title: "Task 1", |
|
// sleep for 3 seconds then return nil |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 2; i++ { |
|
t.Title = fmt.Sprintf("Task 1 - [%d/%d]", i+1, 2) |
|
time.Sleep(1 * time.Second) |
|
} |
|
return nil |
|
}, |
|
}, |
|
{ |
|
Title: "Task 2 Progress", |
|
// sleep for 3 seconds then return nil |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 5; i++ { |
|
t.Progress(i+1, 5) |
|
t.Title = fmt.Sprintf("Task 2 - [%d/%d]", i+1, 5) |
|
time.Sleep(1 * time.Second) |
|
} |
|
return nil |
|
}, |
|
}, |
|
{ |
|
Title: "Task 3", |
|
// sleep for 3 seconds then return nil |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 2; i++ { |
|
t.Title = fmt.Sprintf("Task 3 - [%d/%d]", i+1, 2) |
|
time.Sleep(1 * time.Second) |
|
} |
|
return nil |
|
}, |
|
}, |
|
}, taskin.Config{ |
|
Spinner: spinner.Moon, |
|
ProgressOptions: []progress.Option{ |
|
progress.WithScaledGradient("#6667AB", "#34D399"), |
|
}, |
|
}) |
|
err := tasks.Run() |
Nest tasks inside tasks
|
Title: "Pluck the Chickens", |
|
Tasks: taskin.Tasks{ |
|
{ |
|
Title: "Pluck the silkies", |
|
Task: func(t *taskin.Task) error { |
|
for i := 0; i < 3; i++ { |
|
t.Title = fmt.Sprintf(" [%d/3] silkies plucked", i+1) |
|
time.Sleep(500 * time.Millisecond) |
|
} |
|
return nil |
|
}, |
|
}, |
The *taskin.Task
struct passeed into your task has some useful properties that you can use to customize the task view.
Already demonstrated in most of the examples, you can change t.Title
at any time
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
}