mirror of https://github.com/Hilbis/Hilbish
feat: make prompt optional in hilbish.read
parent
3bec2c91a8
commit
3ee2b03330
18
api.go
18
api.go
|
@ -250,23 +250,27 @@ func hlcwd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read(prompt) -> input?
|
// read(prompt?) -> input?
|
||||||
// Read input from the user, using Hilbish's line editor/input reader.
|
// Read input from the user, using Hilbish's line editor/input reader.
|
||||||
// This is a separate instance from the one Hilbish actually uses.
|
// This is a separate instance from the one Hilbish actually uses.
|
||||||
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
// --- @param prompt string
|
// --- @param prompt string
|
||||||
func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
luaprompt := c.Arg(0)
|
||||||
return nil, err
|
if typ := luaprompt.Type(); typ != rt.StringType && typ != rt.NilType {
|
||||||
|
return nil, errors.New("expected #1 to be a string")
|
||||||
}
|
}
|
||||||
luaprompt, err := c.StringArg(0)
|
prompt, ok := luaprompt.TryString()
|
||||||
if err != nil {
|
if !ok {
|
||||||
return nil, err
|
// if we are here and `luaprompt` is not a string, it's nil
|
||||||
|
// substitute with an empty string
|
||||||
|
prompt = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
lualr := &lineReader{
|
lualr := &lineReader{
|
||||||
rl: readline.NewInstance(),
|
rl: readline.NewInstance(),
|
||||||
}
|
}
|
||||||
lualr.SetPrompt(luaprompt)
|
lualr.SetPrompt(prompt)
|
||||||
|
|
||||||
input, err := lualr.Read()
|
input, err := lualr.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue