Skip to content

Replace Printf/Verbosef/Warnf with termstatus#5510

Merged
MichaelEischer merged 46 commits into
restic:masterfrom
MichaelEischer:termstatus-everywhere-print-functions
Sep 21, 2025
Merged

Replace Printf/Verbosef/Warnf with termstatus#5510
MichaelEischer merged 46 commits into
restic:masterfrom
MichaelEischer:termstatus-everywhere-print-functions

Conversation

@MichaelEischer

@MichaelEischer MichaelEischer commented Sep 15, 2025

Copy link
Copy Markdown
Member

What does this PR change? What problem does it solve?

Restic currently has two ways to print to stdout. The first is using the global functions Printf/Verbosef/Warnf (+variants). The newer way is to use a termstatus.Terminal, which provides proper support for status bars. This PR converts all users of the global functions to use termstatus. A follow-up PR will further reduce the input/output handling by removing stdout/stderr from globalOptions and merging those into termstatus.Terminal along with the corresponding helpers.

Printf is replaced with printer.S, Verbosef with printer.P and Verboseff with printer.V. Those functions don't need a trailing newline character, so it's removed except for cases where multiple newlines are intended. Progress bars are now consistently created using termstatus. The changes are mostly mechanical, such that there should be no major change in behavior for users. The mechanical changes were made using Cursor.

There is a new OutputRaw() method for termstatus.Terminal, which is also no longer buffered. The new output method is intended for commands that need precise control over how data is printed on stdout. This primarily applies to the cat, dump and find commands.

Test cases now consistently use withTermstatus to setup the necessary termstatus.Terminal object. While setupTermstatus() could also be used for now, it will become mandatory with the follow-up PR.

Commands that do not support JSON on any meaningful way, do not pass the JSON flag to newTerminalProgressPrinter. All others do.

TODOs:

  • check JSON output behavior of functions
  • basic manual test of all modified commands

Was the change previously discussed in an issue or on the forum?

No. I wanted to unify the output code for quite a while, but didn't get around to it.

Checklist

  • I have added tests for all code changes.
  • [ ] I have added documentation for relevant changes (in the manual).
  • [ ] There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I'm done! This pull request is ready for review.

There's not much use in doing so as nearly every write call was paired
with a flush call. Thus, just use an unbuffered writer.
This is intended for special cases where it must be guaranteed that the
output on stdout exactly matches what was written to the io.Writer.
@MichaelEischer MichaelEischer force-pushed the termstatus-everywhere-print-functions branch from 508699e to f712781 Compare September 18, 2025 20:58

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM.

@MichaelEischer MichaelEischer merged commit 4a7b122 into restic:master Sep 21, 2025
11 checks passed
@MichaelEischer MichaelEischer deleted the termstatus-everywhere-print-functions branch September 21, 2025 14:42
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.

1 participant