feat: change multiline prompt via multiprompt function (closes #13)

pull/24/head
TorchedSammy 2021-04-05 18:07:47 -04:00
parent 4c63009f56
commit 84d55a38b0
3 changed files with 11 additions and 2 deletions

7
lua.go
View File

@ -25,6 +25,7 @@ func LuaInit() {
l.SetGlobal("_ver", lua.LString(version)) l.SetGlobal("_ver", lua.LString(version))
l.SetGlobal("prompt", l.NewFunction(hshprompt)) l.SetGlobal("prompt", l.NewFunction(hshprompt))
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
l.SetGlobal("alias", l.NewFunction(hshalias)) l.SetGlobal("alias", l.NewFunction(hshalias))
// Add fs module to Lua // Add fs module to Lua
@ -76,6 +77,12 @@ func hshprompt(L *lua.LState) int {
return 0 return 0
} }
func hshmlprompt(L *lua.LState) int {
multilinePrompt = L.ToString(1)
return 0
}
func hshalias(L *lua.LState) int { func hshalias(L *lua.LState) int {
alias := L.ToString(1) alias := L.ToString(1)
source := L.ToString(2) source := L.ToString(2)

View File

@ -21,6 +21,8 @@ const version = "0.3.0-dev"
var l *lua.LState var l *lua.LState
// User's prompt, this will get set when lua side is initialized // User's prompt, this will get set when lua side is initialized
var prompt string var prompt string
var multilinePrompt = "> "
// Map of builtin/custom commands defined in the commander lua module // Map of builtin/custom commands defined in the commander lua module
var commands = map[string]bool{} var commands = map[string]bool{}
// Command aliases // Command aliases
@ -113,7 +115,7 @@ func main() {
} }
func ContinuePrompt(prev string) (string, error) { func ContinuePrompt(prev string) (string, error) {
fmt.Printf("> ") fmt.Print(multilinePrompt)
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)

View File

@ -162,7 +162,7 @@ func StartMultiline(prev string, sb *strings.Builder) bool {
// save input from previous prompts // save input from previous prompts
if sb.String() == "" { sb.WriteString(prev + "\n") } if sb.String() == "" { sb.WriteString(prev + "\n") }
fmt.Printf("sh> ") fmt.Print(multilinePrompt)
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)