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 // --- @param prompt string
func hlread(L *lua.LState) int { func hlread(L *lua.LState) int {
luaprompt := L.CheckString(1) luaprompt := L.CheckString(1)
lualr := newLineReader("") lualr := newLineReader("", true)
lualr.SetPrompt(luaprompt) lualr.SetPrompt(luaprompt)
input, err := lualr.Read() input, err := lualr.Read()

View File

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

18
rl.go
View File

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