Enable to use stderr as output with option
This commit is contained in:
parent
15a5ff0630
commit
f2a63bd1c1
|
@ -225,6 +225,14 @@ func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// OptionUseStderr to set stderr as output
|
||||
func OptionUseStderr() Option {
|
||||
return func(p *Prompt) error {
|
||||
p.renderer.out.UseStderr()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// New returns a Prompt with powerful auto-completion.
|
||||
func New(executor Executor, completer Completer, opts ...Option) *Prompt {
|
||||
pt := &Prompt{
|
||||
|
|
|
@ -145,4 +145,7 @@ type ConsoleWriter interface {
|
|||
|
||||
// SetColor sets text and background colors. and specify whether text is bold.
|
||||
SetColor(fg, bg Color, bold bool)
|
||||
|
||||
// UseStderr sets stderr as output
|
||||
UseStderr()
|
||||
}
|
||||
|
|
|
@ -40,6 +40,11 @@ func (w *PosixWriter) Flush() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UseStderr to set stderr as output
|
||||
func (w *PosixWriter) UseStderr() {
|
||||
w.fd = syscall.Stderr
|
||||
}
|
||||
|
||||
var _ ConsoleWriter = &PosixWriter{}
|
||||
|
||||
// NewStandardOutputWriter returns ConsoleWriter object to write to stdout.
|
||||
|
|
|
@ -270,6 +270,11 @@ func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribu
|
|||
return
|
||||
}
|
||||
|
||||
// UseStderr to set stderr as output
|
||||
func (w *VT100Writer) UseStderr() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
var displayAttributeParameters = map[DisplayAttribute][]byte{
|
||||
DisplayReset: {'0'},
|
||||
DisplayBold: {'1'},
|
||||
|
|
|
@ -25,6 +25,11 @@ func (w *WindowsWriter) Flush() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UseStderr to set stderr as output
|
||||
func (w *WindowsWriter) UseStderr() {
|
||||
w.out = colorable.NewColorableStderr()
|
||||
}
|
||||
|
||||
var _ ConsoleWriter = &WindowsWriter{}
|
||||
|
||||
// NewStandardOutputWriter returns ConsoleWriter object to write to stdout.
|
||||
|
|
Loading…
Reference in New Issue