chore: refactoring access to the terminal#620
Conversation
- Removed the Size method from the Terminal struct as it was no longer needed. - Updated the wrapper to directly use the terminal's Stdout and Stderr methods instead of the term package. - Replaced term output handling in tests with direct terminal instances to improve clarity and maintainability. - Ensured that FlushAllOutput is called on the terminal instance in relevant places. - Adjusted tests to instantiate the terminal correctly, ensuring consistent output handling across test cases.
…emove deprecated functions
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #620 +/- ##
==========================================
+ Coverage 80.41% 80.76% +0.35%
==========================================
Files 150 164 +14
Lines 11796 12116 +320
==========================================
+ Hits 9485 9785 +300
- Misses 1827 1836 +9
- Partials 484 495 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
This PR refactors terminal/console I/O to use an explicit *term.Terminal (and Context.terminal) instead of package-level globals, while also extracting/adding reusable util primitives (ANSI-aware formatting, sync reader/writer wrappers, and an async file writer) used by logging and command output.
Changes:
- Introduces
term.Terminal(options, recorder, default terminal accessor) and migrates commands/wrappers/schedulers/self-update to use it. - Replaces the previous deferred file writer in
logger.gowith a newutil.NewAsyncFileWriter, and adds util sync reader/writer helpers. - Adds ANSI helpers (
util/ansi) and updates help/display formatting to use them.
Reviewed changes
Copilot reviewed 57 out of 57 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| wrapper.go | Routes restic command stdout/stderr + flush behavior through ctx.terminal. |
| wrapper_test.go | Updates tests to construct Context{terminal: ...} and avoid global terminal state. |
| wrapper_streamsource.go | Uses ctx.terminal.Stderr() for stdin-command error output. |
| util/writer.go | Adds Flusher, FlushWriter, and a generic mutex-protected SyncWriter. |
| util/writer_test.go | Tests for FlushWriter and SyncWriter behavior and concurrency. |
| util/reader.go | Adds filter readers/readclosers and a generic mutex-protected SyncReader. |
| util/reader_test.go | Tests for filter readers/readclosers and SyncReader concurrency. |
| util/filewriter.go | Adds NewAsyncFileWriter to batch writes to a file asynchronously. |
| util/filewriter_test.go | Tests async file writer modes (flush/interval/append/truncate/perm/etc.). |
| util/ansi/escape.go | Defines ANSI escape constants and sequence helpers. |
| util/ansi/escape_test.go | Tests ANSI sequence helpers. |
| util/ansi/colors.go | Adds common ANSI color helpers and 256-color builders. |
| util/ansi/colors_test.go | Tests 256-color sequence generation. |
| util/ansi/runes.go | Adds visible-length calculations ignoring ANSI escapes. |
| util/ansi/runes_test.go | Tests visible-length behavior with ANSI sequences. |
| util/ansi/linewriter.go | Adds ANSI/UTF8-aware line-wrapping writer. |
| util/ansi/linewriter_test.go | Tests wrapping behavior across plain/ANSI/unicode/real-world text. |
| update.go | Moves self-update prompting/output to ctx.terminal. |
| update_test.go | Updates self-update tests to pass a terminal instance. |
| term/test/main.go | Small manual demo for terminal color + is-terminal detection. |
| term/terminal.go | Implements Terminal (I/O, color wrapping, prompt/password, flushing). |
| term/terminal_test.go | Adds tests for terminal prompting, output capture, and colorable writers. |
| term/terminal_option.go | Adds functional options (stdin/stdout/stderr/colors/recorders). |
| term/term.go | Removes old global-terminal API implementation. |
| term/term_test.go | Removes tests for the old global-terminal API. |
| term/recorder.go | Adds recorder piping stdout/stderr into a target writer. |
| term/nil_reader.go | Adds a fallback stdin reader implementation. |
| term/default.go | Adds global default terminal getter/setter + terminal size helper. |
| shell/util.go | Adds LineOutputFilter helper for filtering output by lines. |
| serve.go | Removes unused writer parameter from serve command entry points. |
| serve_test.go | Indirectly relies on updated serve signatures/terminal plumbing (via compilation). |
| schtasks/taskscheduler.go | Uses term.Get().Stdout() for status output formatting. |
| schtasks/permission.go | Uses term.Get().ReadPassword() for password prompting. |
| schedule/schedules.go | Passes a terminal explicitly into schedule display helpers. |
| schedule/schedules_test.go | Updates schedule display tests to use a terminal with captured stdout. |
| schedule/handler_windows.go | Uses default terminal for Windows schedule display. |
| schedule/handler_systemd.go | Uses terminal for systemd schedule output and systemctl/journalctl stdio. |
| schedule/handler_systemd_test.go | Updates tests to pass/capture terminal output. |
| schedule/handler_darwin.go | Uses default terminal for launchd schedule display + output formatting. |
| schedule/handler_crond.go | Uses default terminal for cron schedule display. |
| own_commands.go | Updates own command action signature to use commandContext (terminal lives in context). |
| own_commands_test.go | Updates tests to capture output via terminal instead of passing writers. |
| main.go | Initializes and propagates terminal via term.Set(...) and ctx.WithTerminal(...). |
| logger.go | Replaces old deferred writer with util.NewAsyncFileWriter and redirects command output via terminal. |
| logger_test.go | Updates flusher type and parseCommandOutput usage with terminal. |
| integration_test.go | Avoids global term output; captures output via a terminal with custom stdout. |
| flags.go | Uses term.Size() for wrapped usage calculation. |
| context.go | Adds Context.terminal and WithTerminal(...). |
| config/info.go | Minor refactor to avoid reusing a mutable property set instance. |
| config/flag.go | Adds pointer handling in stringify to support reflect.Pointer and nil pointers. |
| config/flag_test.go | Updates expectation: pointer values should stringify to the underlying value. |
| commands.go | Updates own-command plumbing to write via ctx.terminal and removes writer params. |
| commands_test.go | Updates command tests to construct terminals for output capture. |
| commands_schedule.go | Removes writer params from schedule commands and relies on context terminal. |
| commands_schedule_test.go | Updates schedule command integration tests to use term.Set + terminal stdout capture. |
| commands_generate.go | Routes generated content output through ctx.terminal. |
| commands_display.go | Switches display formatting to util/ansi and terminal-aware writer wrapping. |
| commands_display_test.go | Updates display tests to capture/strip ANSI via terminal configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…filewriter and reader
… concurrency safety; remove deprecated reader functions
…file writer tests
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 56 out of 56 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 66 out of 66 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…flush test for file writer
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 66 out of 66 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… with error checks
Access the terminal via an instance of
term.Terminalinstead of using thetermpackage globals