Print progress at once off a terminal, keep stderr to one writer (closes #13)
check / check (push) Successful in 1m25s
check / check (push) Successful in 1m25s
On a pipe, a file or /dev/null each scan phase now prints its zero-state line the moment it starts instead of after its first finished item, so a slow first read under cron no longer leaves the log silent. Terminal detection uses golang.org/x/term, now a direct dependency listed in the README; the old character-device test took /dev/null for a terminal. The walk spinner no longer redraws from the library's own goroutine; it advances only as items complete, so a redraw cannot garble a warning. Building the bar moved into newBar so the terminal display can be tested without a terminal. Lint suppressed: gosec on two test file opens, paralleltest on three tests that replace os.Stderr. Model: opus-5-5
This commit is contained in:
@@ -113,7 +113,8 @@ Goals, in order:
|
||||
`sfdupes`.
|
||||
- Dependencies: standard library, `github.com/spf13/cobra` for the
|
||||
CLI, **one progress-bar library**
|
||||
(`github.com/schollz/progressbar/v3`), and **one SQLite driver**
|
||||
(`github.com/schollz/progressbar/v3`), `golang.org/x/term` to tell
|
||||
whether stderr is a terminal, and **one SQLite driver**
|
||||
(`modernc.org/sqlite`, pure Go, so builds keep cgo disabled).
|
||||
`github.com/spf13/viper` is permitted if configuration-file support
|
||||
is ever needed, but is not currently used. No other third-party
|
||||
@@ -533,10 +534,13 @@ hash: [12345/98765] 12% |████ | 92 files/s elapsed 2:32 eta 17:54
|
||||
|
||||
Additional requirements:
|
||||
|
||||
- When stderr is not a TTY, do not emit ANSI redraws: print a plain
|
||||
one-line progress update no more often than every 5 seconds instead.
|
||||
- When stderr is not a terminal (a pipe, a file, `/dev/null`), do not
|
||||
emit ANSI redraws: print a plain one-line progress update the moment
|
||||
each phase starts, then no more often than every 5 seconds.
|
||||
- Progress updates are driven from the main goroutine and must be
|
||||
non-blocking with respect to the worker pool.
|
||||
non-blocking with respect to the worker pool. Nothing redraws in the
|
||||
background (the spinner advances only as items complete), so a
|
||||
warning printed during a phase always lands on its own line.
|
||||
- `report` and `trees` modes need no progress display, only their
|
||||
stderr summaries.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user