-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spinner): improve context, action, output, tests (#292)
* feat(spinner): make action return an error * fix: improvements * fix: remove default action * chore: ref * docs: fix example Signed-off-by: Carlos Alexandro Becker <[email protected]> * context Signed-off-by: Carlos Alexandro Becker <[email protected]> * docs: fix example Signed-off-by: Carlos Alexandro Becker <[email protected]> * fix: the spinner can actually always have a context Signed-off-by: Carlos Alexandro Becker <[email protected]> * feat: allow a writer too * fix: example * fix: spinner * chore: update examples * chore: code review * Update spinner/spinner.go Co-authored-by: Christian Rocha <[email protected]> * test: fix * test: improvements * fix: tests on ci * feat: update go, spinner.Output, more tests * test: sleeps * Update spinner.go Co-authored-by: ccoVeille <[email protected]> * Update spinner.go Co-authored-by: ccoVeille <[email protected]> * Update spinner/spinner_test.go Co-authored-by: ccoVeille <[email protected]> * chore: fmt --------- Signed-off-by: Carlos Alexandro Becker <[email protected]> Co-authored-by: Christian Rocha <[email protected]> Co-authored-by: ccoVeille <[email protected]>
- Loading branch information
1 parent
c7ebc8a
commit f07ae1a
Showing
8 changed files
with
215 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/charmbracelet/huh | ||
|
||
go 1.21 | ||
go 1.22 | ||
|
||
require ( | ||
github.com/catppuccin/go v0.2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/charmbracelet/huh/spinner" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
err := spinner.New(). | ||
Context(ctx). | ||
ActionWithErr(func(context.Context) error { | ||
time.Sleep(5 * time.Second) | ||
return nil | ||
}). | ||
Accessible(false). | ||
Run() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
fmt.Println("Done!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/charmbracelet/huh/spinner" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
err := spinner.New(). | ||
Context(ctx). | ||
Action(func() { | ||
time.Sleep(time.Minute) | ||
}). | ||
Accessible(rand.Int()%2 == 0). | ||
Run() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
fmt.Println("Done!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/charmbracelet/huh/spinner | ||
|
||
go 1.19 | ||
go 1.22 | ||
|
||
require ( | ||
github.com/charmbracelet/bubbles v0.20.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.