📋 Add user-friendly tasks to your terminal
![Multi](https://github.com/multi.gif)
![Phorm](https://camo.githubusercontent.com/1da025d47fc5a6b8d95d7edd7fa8d4194bc5b7d6085c779ef3a0120772d38414/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50686f726d2d41736b2d70696e6b)
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() |
![Simple](https://github.com/simple.gif)
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() |
![Progress](https://github.com/progress.gif)
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() |
![Custom](https://github.com/custom.gif)
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 |
|
}, |
|
}, |
![Multi](https://github.com/multi.gif)
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
}