fix: hilbish.read overriding history

windows-fixes
TorchedSammy 2022-03-06 14:38:27 -04:00
parent 764e2372a2
commit 4ef6c7d5c0
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 13 additions and 9 deletions

2
api.go
View File

@ -206,7 +206,7 @@ func getenv(key, fallback string) string {
// --- @param prompt string
func hlread(L *lua.LState) int {
luaprompt := L.CheckString(1)
lualr := newLineReader("")
lualr := newLineReader("", true)
lualr.SetPrompt(luaprompt)
input, err := lualr.Read()

View File

@ -114,7 +114,7 @@ func main() {
go handleSignals()
luaInit()
lr = newLineReader("")
lr = newLineReader("", false)
// If user's config doesn't exixt,
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
// Read default from current directory

6
rl.go
View File

@ -15,8 +15,11 @@ type lineReader struct {
var fileHist *fileHistory
// other gophers might hate this naming but this is local, shut up
func newLineReader(prompt string) *lineReader {
func newLineReader(prompt string, noHist bool) *lineReader {
rl := readline.NewInstance()
// we don't mind hilbish.read rl instances having completion,
// but it cant have shared history
if !noHist {
fh, err := newFileHistory()
fileHist = fh // go stupid
if err != nil {
@ -24,6 +27,7 @@ func newLineReader(prompt string) *lineReader {
}
rl.SetHistoryCtrlR("file", fileHist)
rl.HistoryAutoWrite = false
}
rl.ShowVimMode = false
rl.ViModeCallback = func(mode readline.ViMode) {
modeStr := ""