fix: handle prompt properly and remove global

windows-fixes
TorchedSammy 2022-03-04 21:54:47 -04:00
parent 237bc19f68
commit 6b9bbb615d
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 4 additions and 7 deletions

6
api.go
View File

@ -174,10 +174,8 @@ These will be formatted and replaced with the appropriate values.
--- @param str string
*/
func hlprompt(L *lua.LState) int {
prompt = L.CheckString(1)
if lr != nil {
lr.SetPrompt(fmtPrompt())
}
prompt := L.CheckString(1)
lr.SetPrompt(fmtPrompt(prompt))
return 0
}

View File

@ -114,6 +114,7 @@ func main() {
go handleSignals()
luaInit()
lr = newLineReader("")
// If user's config doesn't exixt,
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
// Read default from current directory
@ -162,12 +163,10 @@ func main() {
os.Exit(0)
}
lr = newLineReader("")
input:
for interactive {
running = false
lr.SetPrompt(fmtPrompt())
input, err := lr.Read()
if err == io.EOF {
@ -225,7 +224,7 @@ func continuePrompt(prev string) (string, error) {
}
// This semi cursed function formats our prompt (obviously)
func fmtPrompt() string {
func fmtPrompt(prompt string) string {
host, _ := os.Hostname()
cwd, _ := os.Getwd()