Skip to content

chore: refactoring access to the terminal#620

Merged
creativeprojects merged 15 commits intomasterfrom
terminal
Apr 7, 2026
Merged

chore: refactoring access to the terminal#620
creativeprojects merged 15 commits intomasterfrom
terminal

Conversation

@creativeprojects
Copy link
Copy Markdown
Owner

@creativeprojects creativeprojects commented Apr 5, 2026

Access the terminal via an instance of term.Terminal instead of using the term package globals

- 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.
Copilot AI review requested due to automatic review settings April 5, 2026 14:44
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 76.08696% with 143 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.76%. Comparing base (e0b36f0) to head (2816684).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
commands_display.go 22.92% 36 Missing and 1 partial ⚠️
term/terminal.go 74.74% 21 Missing and 3 partials ⚠️
term/terminal_option.go 60.47% 15 Missing and 2 partials ⚠️
commands.go 33.33% 14 Missing ⚠️
term/default.go 46.15% 7 Missing ⚠️
util/write/async.go 91.18% 3 Missing and 3 partials ⚠️
util/write/file_option.go 40.00% 6 Missing ⚠️
schedule/handler_systemd.go 68.75% 5 Missing ⚠️
util/ansi/colors.go 44.44% 5 Missing ⚠️
util/ansi/linewriter.go 93.33% 3 Missing and 1 partial ⚠️
... and 11 more
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     
Flag Coverage Δ
unittests 79.04% <76.09%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go with a new util.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.

Comment thread util/reader.go Outdated
Comment thread term/nil_reader.go
Comment thread util/filewriter.go Outdated
Comment thread util/filewriter.go Outdated
Comment thread util/filewriter.go Outdated
Comment thread util/filewriter.go Outdated
Comment thread term/default.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread main.go Outdated
Comment thread logger.go Outdated
Comment thread util/filewriter.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread term/default_test.go
Comment thread term/default_test.go
Comment thread util/write/async.go
Comment thread util/write/async.go
Comment thread util/write/file.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread util/write/async.go
Comment thread util/write/async.go
Comment thread util/write/file.go
@creativeprojects creativeprojects merged commit 395db19 into master Apr 7, 2026
8 checks passed
@creativeprojects creativeprojects deleted the terminal branch April 7, 2026 15:38
@creativeprojects creativeprojects added this to the v0.34.0 milestone Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants