grain icon indicating copy to clipboard operation
grain copied to clipboard

stdlib: Add `input` function

Open spotandjake opened this issue 1 year ago • 2 comments

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 standard yes/no prompt 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. retry would basically prompt until a valid response is inputted

spotandjake avatar Mar 22 '24 21:03 spotandjake

Requires #1583

ospencer avatar Apr 05 '24 20:04 ospencer

I also agree that this should be in its own library, including things like readLine, etc.

ospencer avatar Apr 05 '24 20:04 ospencer