mirror of
https://github.com/restic/restic.git
synced 2025-12-12 03:22:07 +00:00
termstatus: allow retrieving the underlying 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.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
var _ Terminal = &MockTerminal{}
|
||||||
|
|
||||||
type MockTerminal struct {
|
type MockTerminal struct {
|
||||||
Output []string
|
Output []string
|
||||||
Errors []string
|
Errors []string
|
||||||
@@ -20,3 +24,7 @@ func (m *MockTerminal) SetStatus(lines []string) {
|
|||||||
func (m *MockTerminal) CanUpdateStatus() bool {
|
func (m *MockTerminal) CanUpdateStatus() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockTerminal) OutputRaw() io.Writer {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
// Terminal is used to write messages and display status lines which can be
|
// Terminal is used to write messages and display status lines which can be
|
||||||
// updated. See termstatus.Terminal for a concrete implementation.
|
// updated. See termstatus.Terminal for a concrete implementation.
|
||||||
type Terminal interface {
|
type Terminal interface {
|
||||||
@@ -7,4 +9,5 @@ type Terminal interface {
|
|||||||
Error(line string)
|
Error(line string)
|
||||||
SetStatus(lines []string)
|
SetStatus(lines []string)
|
||||||
CanUpdateStatus() bool
|
CanUpdateStatus() bool
|
||||||
|
OutputRaw() io.Writer
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ import (
|
|||||||
"golang.org/x/text/width"
|
"golang.org/x/text/width"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/terminal"
|
"github.com/restic/restic/internal/terminal"
|
||||||
|
"github.com/restic/restic/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ ui.Terminal = &Terminal{}
|
||||||
|
|
||||||
// Terminal is used to write messages and display status lines which can be
|
// Terminal is used to write messages and display status lines which can be
|
||||||
// updated. When the output is redirected to a file, the status lines are not
|
// updated. When the output is redirected to a file, the status lines are not
|
||||||
// printed.
|
// printed.
|
||||||
@@ -83,6 +86,13 @@ func (t *Terminal) CanUpdateStatus() bool {
|
|||||||
return t.canUpdateStatus
|
return t.canUpdateStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutputRaw returns the output writer. Should only be used if there is no
|
||||||
|
// other option. Must not be used in combination with Print, Error, SetStatus
|
||||||
|
// or any other method that writes to the terminal.
|
||||||
|
func (t *Terminal) OutputRaw() io.Writer {
|
||||||
|
return t.wr
|
||||||
|
}
|
||||||
|
|
||||||
// Run updates the screen. It should be run in a separate goroutine. When
|
// Run updates the screen. It should be run in a separate goroutine. When
|
||||||
// ctx is cancelled, the status lines are cleanly removed.
|
// ctx is cancelled, the status lines are cleanly removed.
|
||||||
func (t *Terminal) Run(ctx context.Context) {
|
func (t *Terminal) Run(ctx context.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user