grain
grain copied to clipboard
stdlib: Add `input` function
In python there is the input function which makes reading inputs syncronously from the command line super easy. This helps to position python in an especially useful place for learning to program and writing simple interactive programs. It would be great if we could add a function like this, currently this behaviour could be done through stdin but exposing a nice user friendly function would greatly help with developer experience.
I think the desired type for this would be input(prompt="") => string, if we ever get async capabilities in grain, it would also be great if this was an async function.
We may want to consider adding some sort of console library that contains functions like this and possibly additional printing utils like printTable.
Additions: Some other additions if we have a library for this would be the following:
inputNumber(prompt="", retry=false) => Result<Number, Exception>inputConfirm(prompt="", retry=false) => Option<Bool>- This would handle a standardyes/noprompt I think especially in the cli world we see these same styles of inputs again and again and it would be really nice to provide some builtins for these common use cases.retrywould basically prompt until a valid response is inputted
Requires #1583
I also agree that this should be in its own library, including things like readLine, etc.