Skip to content

Commit

Permalink
🎨 great new way to reference code
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed May 6, 2024
1 parent 3cd766c commit 9960f1c
Showing 1 changed file with 3 additions and 165 deletions.
168 changes: 3 additions & 165 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,7 @@ Simplest way to line up and fire off tasks

![Simple](/simple.gif)

```go
package main

import (
"fmt"
"github.com/fumeapp/taskin"
"time"
)

func main() {

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(1 * time.Second)
}
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(1 * time.Second)
}
return fmt.Errorf("task 2 failed")
},
},
})
err := tasks.Run()

if err != nil {
panic(err)
}
}
```
https://github.com/fumeapp/taskin/blob/3cd766c21e5eaba5edb33f38d3781d6cf814f9f9/examples/simple/main.go#L11-L33

Using a progress bar for a task

Expand All @@ -80,133 +41,10 @@ Customize colors, spinner, and progress bar

![Custom](/custom.gif)

```go
package main

import (
"fmt"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/spinner"
"github.com/fumeapp/taskin"
"time"
)

func main() {

tasks := taskin.New(taskin.Tasks{
{
Title: "Task 1",
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",
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",
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,
ProgressOption: progress.WithScaledGradient("#6667AB", "#34D399"),
})
err := tasks.Run()

if err != nil {
panic(err)
}
}


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

Add multiple tasks to a single task

![Multi](/multi.gif)

```go
package main

import (
"fmt"
"github.com/fumeapp/taskin"
"time"
)

func main() {

tasks := taskin.New(taskin.Tasks{
{
Title: "Mow the lawn",
Task: func(t *taskin.Task) error {
for i := 0; i < 3; i++ {
t.Title = fmt.Sprintf("Mow the lawn: [%d/3] passes", i+1)
time.Sleep(500 * time.Millisecond)
}
return nil
},
},
{
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
},
},
{
Title: "Pluck the leghorns",
Task: func(t *taskin.Task) error {
for i := 0; i < 3; i++ {
t.Title = fmt.Sprintf(" [%d/3] leghorns plucked", i+1)
time.Sleep(500 * time.Millisecond)
}
return nil
},
},
},
},
{
Title: "Paint the house",
Task: func(t *taskin.Task) error {
for i := 0; i < 3; i++ {
t.Progress(i+1, 5)
t.Title = fmt.Sprintf("Paint the house: [%d/3] walls painted", i+1)
time.Sleep(500 * time.Millisecond)
}
return nil
},
},
}, taskin.Defaults)
err := tasks.Run()

if err != nil {
panic(err)
}
}

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

0 comments on commit 9960f1c

Please sign in to comment.