Compare commits
	
		
			5 commits
		
	
	
		
			
				2d70d8994e
			
			...
			
				f41ac8575f
			
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f41ac8575f | |||
| fd68ffbbf8 | |||
| f7fca3ba73 | |||
| 36ad4b260e | |||
| 31ebd4ed91 | 
					 7 changed files with 94 additions and 11 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1,2 +1 @@ | ||||||
| build/ |  | ||||||
| .task/ | .task/ | ||||||
|  |  | ||||||
							
								
								
									
										55
									
								
								Taskfile.yml
									
										
									
									
									
								
							
							
						
						
									
										55
									
								
								Taskfile.yml
									
										
									
									
									
								
							|  | @ -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
									
								
							
							
						
						
									
										2
									
								
								build/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | * | ||||||
|  | !.gitignore | ||||||
							
								
								
									
										21
									
								
								cli/context/signal.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								cli/context/signal.go
									
										
									
									
									
										Normal 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 | ||||||
|  | } | ||||||
|  | @ -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() | ||||||
|  |  | ||||||
|  | @ -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) | ||||||
|  |  | ||||||
|  | @ -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 { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue