-
Notifications
You must be signed in to change notification settings - Fork 3
EN04_Prompt
HAYAMA_Kaoru edited this page Oct 11, 2023
·
1 revision
The .PromptWriter
field allows you to set a function that creates the string that should be printed at the prompt.
※ Previously, this was specified in a field called Prompt
, but this has been discontinued.
editor := &readline.Editor{
// ;
PromptWriter: func(w io.Writer) (int, error) {
return io.WriteString(w, "\x1B[1;36m$ \x1B[0m") // print `$ ` with cyan
},
// ;
}
A Function set with .PromptWriter
are evaluated every time a prompt is displayed. Please output the prompt to io.Writer
using fmt.Fprintf
etc..
The return value (int,error)
is currently unused.
It was originally created with the intention of having the user provide the character width for the prompt. However, in many cases, the number of bytes != character width, which was essentially meaningless. So, the (*Editor) ReadLine
method stores the output with strings.Builder
and counts the width of it. Therefore you does not have to count now.