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 --- @param str string
*/ */
func hlprompt(L *lua.LState) int { func hlprompt(L *lua.LState) int {
prompt = L.CheckString(1) prompt := L.CheckString(1)
if lr != nil { lr.SetPrompt(fmtPrompt(prompt))
lr.SetPrompt(fmtPrompt())
}
return 0 return 0
} }

View File

@ -114,6 +114,7 @@ func main() {
go handleSignals() go handleSignals()
luaInit() luaInit()
lr = newLineReader("")
// 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
@ -162,12 +163,10 @@ func main() {
os.Exit(0) os.Exit(0)
} }
lr = newLineReader("")
input: input:
for interactive { for interactive {
running = false running = false
lr.SetPrompt(fmtPrompt())
input, err := lr.Read() input, err := lr.Read()
if err == io.EOF { if err == io.EOF {
@ -225,7 +224,7 @@ func continuePrompt(prev string) (string, error) {
} }
// This semi cursed function formats our prompt (obviously) // This semi cursed function formats our prompt (obviously)
func fmtPrompt() string { func fmtPrompt(prompt string) string {
host, _ := os.Hostname() host, _ := os.Hostname()
cwd, _ := os.Getwd() cwd, _ := os.Getwd()