Compare commits

...

5 commits

Author SHA1 Message Date
f41ac8575f 🚀 Add install-cool-down build target
cool-down seems stable now
2024-11-01 12:09:50 -05:00
fd68ffbbf8 🐛 Program should still halt even with spinner 2024-10-29 11:28:47 -05:00
f7fca3ba73 🛠 Add default task 2024-10-28 20:07:19 -05:00
36ad4b260e 🛠 Add static analysis 2024-10-28 20:01:03 -05:00
31ebd4ed91 🛠 Add .gitignore to build directory 2024-10-28 11:30:52 -05:00
7 changed files with 94 additions and 11 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
build/
.task/ .task/

View file

@ -2,13 +2,53 @@
version: '3' version: '3'
vars:
GOBIN_ENV:
sh: go env GOBIN
GOPATH_ENV:
sh: go env GOPATH
BIN: '{{if .GOBIN_ENV}}{{.GOBIN_ENV}}{{else}}{{.GOPATH_ENV}}/bin{{end}}'
tasks: tasks:
default:
desc: fmt, vet, and build
deps:
- fmt
- analyze
- build-all
fmt: fmt:
desc: Format go files desc: Format go files
sources: sources:
- "**/*.go" - "**/*.go"
cmds: cmds:
- go fmt ./... - go fmt ./...
vet:
desc: Vet go code
sources:
- '**/*.go'
cmds:
- go vet ./...
critic:
desc: Critique go code
sources:
- '**/*.go'
cmds:
- gocritic check ./...
staticcheck:
desc: Static check go code
sources:
- '**/*.go'
cmds:
- staticcheck ./...
analyze:
desc: Do static analysis
deps:
- vet
- critic
- staticcheck
cmd-build: cmd-build:
internal: true internal: true
cmds: cmds:
@ -49,3 +89,18 @@ tasks:
- task: cmd-build - task: cmd-build
vars: vars:
CMD: "*" CMD: "*"
install-cool-down:
desc: Installs the cool-down command
source:
- cmd/cool-down/**/*.go
- chill/*.go
- cli/context/*.go
- cli/err/*.go
- cli/spin/*.go
- go.mod
- go.sum
generates:
- '{{.BIN}}/cool-down'
cmds:
- go install ./cmd/cool-down

2
build/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore

21
cli/context/signal.go Normal file
View file

@ -0,0 +1,21 @@
package context
import (
"context"
"os"
"os/signal"
"syscall"
)
func SelfCancelingCotext(ctx context.Context) (context.Context, context.CancelFunc) {
c, done := context.WithCancel(ctx)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
go func() {
for range ch {
done()
}
}()
return c, done
}

View file

@ -82,18 +82,24 @@ func (s *spin) SetMessage(msg string) {
} }
func (s *spin) Err() error { func (s *spin) Err() error {
if errors.Is(s.err, context.Canceled) { switch {
case errors.Is(s.err, context.Canceled):
return nil return nil
} else if errors.Is(s.err, context.DeadlineExceeded) { case errors.Is(s.err, context.DeadlineExceeded):
return nil return nil
} else if errors.Is(s.err, tea.ErrProgramKilled) { case errors.Is(s.err, tea.ErrProgramKilled):
return nil return nil
} }
return s.err return s.err
} }
func Spin(ctx context.Context, message string) Spinner { func Spin(ctx context.Context, message string) Spinner {
p := tea.NewProgram(newModel(message), tea.WithContext(ctx)) p := tea.NewProgram(
newModel(message),
tea.WithContext(ctx),
tea.WithoutSignalHandler(),
tea.WithInput(nil),
)
s := &spin{p: p, finished: make(chan struct{}, 1)} s := &spin{p: p, finished: make(chan struct{}, 1)}
go func() { go func() {
_, err := s.p.Run() _, err := s.p.Run()

View file

@ -4,12 +4,15 @@ import (
"context" "context"
"codeberg.org/danjones000/utils/chill" "codeberg.org/danjones000/utils/chill"
c "codeberg.org/danjones000/utils/cli/context"
e "codeberg.org/danjones000/utils/cli/err" e "codeberg.org/danjones000/utils/cli/err"
"codeberg.org/danjones000/utils/cli/spin" "codeberg.org/danjones000/utils/cli/spin"
) )
func main() { func main() {
ctx := chill.Chill(context.Background()) ctx, done := c.SelfCancelingCotext(context.Background())
defer done()
ctx = chill.Chill(ctx)
s := spin.Spin(ctx, "Waiting for CPU to cool...") s := spin.Spin(ctx, "Waiting for CPU to cool...")
err := s.Wait() err := s.Wait()
e.HandleErr(err) e.HandleErr(err)

View file

@ -38,10 +38,7 @@ func (s *Show) matchRegexp(path string) (f bool, err error) {
if s.re == nil { if s.re == nil {
p := s.Pattern p := s.Pattern
if s.Anime { if s.Anime {
if strings.HasPrefix(p, "^") { p = animePattern + strings.TrimPrefix(p, "^")
p = strings.TrimPrefix(p, "^")
}
p = animePattern + p
} else if !strings.HasPrefix(p, "^") { } else if !strings.HasPrefix(p, "^") {
p = "^" + p p = "^" + p
} }
@ -71,7 +68,7 @@ func (d *Data) AllShows(silent bool) iter.Seq[*Show] {
continue continue
} }
if !silent { if !silent {
fmt.Println("Checking", show, "shows\n") fmt.Printf("Checking %s shows\n\n", show)
} }
for s := range sh.All() { for s := range sh.All() {
if s == nil { if s == nil {