Replace Printf/Verbosef/Warnf with termstatus#5510
Merged
MichaelEischer merged 46 commits intoSep 21, 2025
Merged
Conversation
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.
508699e to
f712781
Compare
Considering the flag would result in a mostly empty terminal output, which is probably worse than text output instead of JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Printfis replaced withprinter.S,Verbosefwithprinter.PandVerboseffwithprinter.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 fortermstatus.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 thecat,dumpandfindcommands.Test cases now consistently use
withTermstatusto setup the necessarytermstatus.Terminalobject. WhilesetupTermstatus()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:
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 documentation for relevant changes (in the manual).[ ] There's a new file inchangelog/unreleased/that describes the changes for our users (see template).