2016-02-16 11:55:19 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-12-12 16:55:00 +03:00
|
|
|
"git.internal/re/readline"
|
2016-02-16 11:55:19 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
rl, err := readline.NewEx(&readline.Config{
|
|
|
|
Prompt: "> ",
|
|
|
|
HistoryFile: "/tmp/readline-multiline",
|
|
|
|
DisableAutoSaveHistory: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer rl.Close()
|
|
|
|
|
|
|
|
var cmds []string
|
|
|
|
for {
|
|
|
|
line, err := rl.Readline()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
line = strings.TrimSpace(line)
|
|
|
|
if len(line) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
cmds = append(cmds, line)
|
2016-04-21 05:06:19 +03:00
|
|
|
if !strings.HasSuffix(line, ";") {
|
2016-02-16 11:55:19 +03:00
|
|
|
rl.SetPrompt(">>> ")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
cmd := strings.Join(cmds, " ")
|
|
|
|
cmds = cmds[:0]
|
|
|
|
rl.SetPrompt("> ")
|
|
|
|
rl.SaveHistory(cmd)
|
|
|
|
println(cmd)
|
|
|
|
}
|
|
|
|
}
|