go-prompt icon indicating copy to clipboard operation
go-prompt copied to clipboard

Does it support to read multi-lines seperated by '\'?

Open jievince opened this issue 3 years ago • 3 comments

jievince avatar Aug 17 '20 01:08 jievince

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.

c-bata avatar Aug 17 '20 04:08 c-bata

Any idea will this be supported in future?

VijayanB avatar Sep 22 '20 18:09 VijayanB

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.

coanor avatar Dec 07 '20 01:12 coanor