go-prompt
go-prompt copied to clipboard
Does it support to read multi-lines seperated by '\'?
No. It is still not supported.
mattn is not a maintainer of this project though he is a contributor. You don't need to mention him.
Any idea will this be supported in future?
I do it like this:
// setup prompt with a live prompt
p := prompt.New(myRun, myCompleter, prompt.OptionLivePrefix(myLivePrompt), ... /* other options */)
...
var multiLines []string // cache multi-lines during edit
func myLivePrompt() (string, bool) {
if len(multiLines) >=1 {
return ">", true // like shell multi-line prompt
}
return "my-prompt > ", true
}
func myRun(cmd string) {
s := strings.TrimSpace(cmd)
switch strings.ToUpper(s) {
case "...": return; // cases you should handle for special commands
default:
s = strings.Join(strings.Fields(s), " ") // remove dup spaces
if strings.HasSuffix("\\") {
multiLines = append(multiLines, strings.TrimSuffix("\\"))
} else {
multiLines = append(multiLines, s)
handle(strings.Join(multiLines, "\n")) // run your code to handle multiLines
multiLines = []string{} // clear multiLines cache
}
}
}
The defect is, We can't nevigate among multi-lines.