diff --git a/.gitignore b/.gitignore index f1c37ad..c525b60 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +build/ .task/ diff --git a/Taskfile.yml b/Taskfile.yml index 34dfb3f..77b972d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,53 +2,13 @@ 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: - default: - desc: fmt, vet, and build - deps: - - fmt - - analyze - - build-all - fmt: desc: Format go files sources: - "**/*.go" cmds: - 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: internal: true cmds: @@ -89,18 +49,3 @@ tasks: - task: cmd-build vars: 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 diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/build/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/cli/context/signal.go b/cli/context/signal.go deleted file mode 100644 index cf8f620..0000000 --- a/cli/context/signal.go +++ /dev/null @@ -1,21 +0,0 @@ -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 -} diff --git a/cli/spin/spin.go b/cli/spin/spin.go index d5570fa..2896335 100644 --- a/cli/spin/spin.go +++ b/cli/spin/spin.go @@ -82,24 +82,18 @@ func (s *spin) SetMessage(msg string) { } func (s *spin) Err() error { - switch { - case errors.Is(s.err, context.Canceled): + if errors.Is(s.err, context.Canceled) { return nil - case errors.Is(s.err, context.DeadlineExceeded): + } else if errors.Is(s.err, context.DeadlineExceeded) { return nil - case errors.Is(s.err, tea.ErrProgramKilled): + } else if errors.Is(s.err, tea.ErrProgramKilled) { return nil } return s.err } func Spin(ctx context.Context, message string) Spinner { - p := tea.NewProgram( - newModel(message), - tea.WithContext(ctx), - tea.WithoutSignalHandler(), - tea.WithInput(nil), - ) + p := tea.NewProgram(newModel(message), tea.WithContext(ctx)) s := &spin{p: p, finished: make(chan struct{}, 1)} go func() { _, err := s.p.Run() diff --git a/cmd/cool-down/main.go b/cmd/cool-down/main.go index 234a06a..18487b1 100644 --- a/cmd/cool-down/main.go +++ b/cmd/cool-down/main.go @@ -4,15 +4,12 @@ import ( "context" "codeberg.org/danjones000/utils/chill" - c "codeberg.org/danjones000/utils/cli/context" e "codeberg.org/danjones000/utils/cli/err" "codeberg.org/danjones000/utils/cli/spin" ) func main() { - ctx, done := c.SelfCancelingCotext(context.Background()) - defer done() - ctx = chill.Chill(ctx) + ctx := chill.Chill(context.Background()) s := spin.Spin(ctx, "Waiting for CPU to cool...") err := s.Wait() e.HandleErr(err) diff --git a/convids/methods.go b/convids/methods.go index 8162848..69ce198 100644 --- a/convids/methods.go +++ b/convids/methods.go @@ -38,7 +38,10 @@ func (s *Show) matchRegexp(path string) (f bool, err error) { if s.re == nil { p := s.Pattern if s.Anime { - p = animePattern + strings.TrimPrefix(p, "^") + if strings.HasPrefix(p, "^") { + p = strings.TrimPrefix(p, "^") + } + p = animePattern + p } else if !strings.HasPrefix(p, "^") { p = "^" + p } @@ -68,7 +71,7 @@ func (d *Data) AllShows(silent bool) iter.Seq[*Show] { continue } if !silent { - fmt.Printf("Checking %s shows\n\n", show) + fmt.Println("Checking", show, "shows\n") } for s := range sh.All() { if s == nil {