2021-05-17 23:03:56 +00:00
|
|
|
// +build !hilbiline
|
|
|
|
|
2021-10-16 15:31:01 +00:00
|
|
|
package main
|
|
|
|
|
2021-05-17 23:03:56 +00:00
|
|
|
// Here we define a generic interface for readline and hilbiline,
|
|
|
|
// making them interchangable during build time
|
|
|
|
// this is normal readline
|
|
|
|
|
|
|
|
import "github.com/bobappleyard/readline"
|
|
|
|
|
|
|
|
type LineReader struct {
|
|
|
|
Prompt string
|
|
|
|
}
|
|
|
|
|
|
|
|
// other gophers might hate this naming but this is local, shut up
|
|
|
|
func NewLineReader(prompt string) *LineReader {
|
|
|
|
readline.Completer = readline.FilenameCompleter
|
2021-10-13 14:42:35 +00:00
|
|
|
readline.LoadHistory(defaultHistPath)
|
2021-05-17 23:03:56 +00:00
|
|
|
|
|
|
|
return &LineReader{
|
|
|
|
Prompt: prompt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (lr *LineReader) Read() (string, error) {
|
2021-10-14 02:53:09 +00:00
|
|
|
hooks.Em.Emit("command.precmd", nil)
|
2021-05-17 23:03:56 +00:00
|
|
|
return readline.String(lr.Prompt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (lr *LineReader) SetPrompt(prompt string) {
|
|
|
|
lr.Prompt = prompt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (lr *LineReader) AddHistory(cmd string) {
|
|
|
|
readline.AddHistory(cmd)
|
2021-10-13 14:42:35 +00:00
|
|
|
readline.SaveHistory(defaultHistPath)
|
2021-05-17 23:03:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 01:00:01 +00:00
|
|
|
func (lr *LineReader) ClearInput() {
|
|
|
|
readline.ReplaceLine("", 0)
|
|
|
|
readline.RefreshLine()
|
|
|
|
}
|
|
|
|
|