-
Notifications
You must be signed in to change notification settings - Fork 3
EN03_Change_output
HAYAMA_Kaoru edited this page Oct 11, 2023
·
1 revision
You can change the output destination by setting io.Writer
in the .Writer
field of the Editor
structure
By default, os.Stdout
is automatically set, but if it is expected to be used in an environment such as Windows where escape sequences are not enabled, an io.Writer
that emulates an ANSI Escape sequence such as go-colorable can be set here. (recommended)
import (
"github.com/mattn/go-colorable"
)
// ;
editor := &readline.Editor{
// ;
Writer: colorable.NewColorableStdout(),
// ;
}
There is a similar field called .Out
, which is a .Writer
field buffered with bufio.Writer
and set using the .ReadLine
method, etc. Since this .Out
is mainly used after that, changing the .Writer
once it is set has no effect.