peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

How to reserve previous content in the same line #97

Closed yc90s closed 6 years ago

yc90s commented 6 years ago

Description

liner will overwrite the same line of output. How can I reserve the previous content?

Example

line := liner.NewLiner()
defer line.Close()

fmt.Print("===don't overwrite this=== ")
if name, err := line.Prompt("What is your name? "); err != nil {
      log.Println(err)
} 

When you enter a <Backspace>, the content will be overwirted.

peterh commented 6 years ago

Liner controls the entire command line. If you want something to appear before the editable field, it must be a part of the prompt.

eg. your example would be

peterh commented 6 years ago

eg. your example would be

prefix := "===don't overwrite this=== "
line.Prompt(prefix + "What is your name? ")
yc90s commented 6 years ago

Can't join it to the prompt, because it's printed somewhere else. Anyway, thank you for reply