New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: add *input* builtin function #40194
Comments
Thanks. This seems like a function that could easily live in a third party library. The standard library doesn't have any package or set of functions for interactive I/O. https://golang.org/doc/faq#x_in_std (Note that your suggested implementation is not safe, as the buffered |
Thank you very much for your response. Im already working on a module with the fixes (I hope). |
Closing as declined. |
@davecheney To be clear I didn't mean my comment to decline the proposal entirely. I was raising an objection. If @dotoscat wants to respond we can reopen this. |
My mistake, I interpreted #40194 (comment) as @dotoscat had moved on to implementing this in their own package. |
After some tries with Scan, Scanf and Scanln I come to the conclussion to use reader := bufio.NewReader(os.Stdin) as a global. Something like this
which works if os.Stdin is the output from another program and is harmless if os.Stdin is a tty.
So the implementation of input would be
And excuse me for this, there is a problem that happens with string.TrimRight though
The output is
The output is being stepped on, which don't happen without strings.TrimRight or any other strings functions I attach the files for the reproducible example. |
@dotoscat Do you still want to propose a change to the standard library? |
Yes
El mié., 15 jul. 2020 23:16, Ian Lance Taylor <notifications@github.com>
escribió:
… @dotoscat <https://github.com/dotoscat> Do you still want to propose a
change to the standard library?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40194 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECOFU75DYRONEWDDWU7AA3R3YMCPANCNFSM4OY2KEXA>
.
|
Reopened. Please do consider https://golang.org/doc/faq#x_in_std . Why does the proposed function belong in the standard library? Thanks. |
After thinking about it carefully I don't see any reason to the proposed function be part of the standard library. Thank you for your attention. |
Hello. I don't know whether this is the correct place for this proposal.
input would be a convenience function for a quick interaction with the user from the command line, similar to Python's
I think its implementation could be this simple:
Example of use
The text was updated successfully, but these errors were encountered: