print statement should allow for escaping stuff

This commit is contained in:
Aidan 2020-07-17 22:38:15 -07:00
parent d0e3946aff
commit 77ce00970f
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 35 additions and 4 deletions

View file

@ -31,6 +31,22 @@ const (
def_prompt string = "λ "
)
// useful for when input contains escape sequences
// not checking delims cause thats up to the user who defines their prompts
func parseString(in string) string {
in = "\"" + in + "\""
out, err := strconv.Unquote(in)
if err != nil {
log.Log(log.ERR,
"Couldnt parse (pre?)prompt",
"init")
return ""
}
return out
}
func setLogLvl(vars ast.VarTable) {
var loglvl string
@ -80,7 +96,7 @@ func main() {
prompt_t := ast.GetVar("SHS_STATIC_PROMPT", vars)
if prompt_t != nil {
prompt = prompt_t.Value()
prompt = parseString(prompt_t.Value())
} else {
prompt = def_prompt
}
@ -110,7 +126,7 @@ func main() {
if dyn_prompt != nil {
p_tok := dyn_prompt.CallFunction(nil, vars, funcs)
if p_tok != nil && p_tok.Tag == ast.STRING {
prePrompt = p_tok.Value()
prePrompt = parseString(p_tok.Value())
}
}