Skip to content

Commit

Permalink
fix: only print newline before error on signal
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Dec 31, 2024
1 parent 9d9442c commit 7a40eb2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ const (

var sparklineTicks = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}

type signalError struct {
signal os.Signal
}

func (e signalError) Error() string {
return fmt.Sprintf("received signal: %v", e.signal)
}

func (e signalError) Is(target error) bool {
_, ok := target.(signalError)
return ok
}

type config struct {
arguments []string
command string
Expand Down Expand Up @@ -351,7 +364,7 @@ func main() {
cfg := parseArgs()

if err := run(cfg); err != nil {
if cfg.outputPath == defaultOutputPath && !cfg.newlines {
if !cfg.newlines && cfg.outputPath == defaultOutputPath && errors.Is(err, signalError{}) {
fmt.Fprintln(os.Stderr)
}

Expand Down Expand Up @@ -492,7 +505,7 @@ func run(cfg config) error {
case sig := <-sigChan:
cancel()

return fmt.Errorf("received signal: %v", sig)
return signalError{signal: sig}
}

// Get the complete final stats.
Expand Down

0 comments on commit 7a40eb2

Please sign in to comment.