You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reading a line from a terminal can only be interrupted by the user pressing CTRL+D or CTRL+C. API does not allow the reading to be interrupted via other means. This creates an impossible scenario if other goroutine should be the source of interrupt.
Closing an underlying file (os.Stdin) does not work as expected. A user is still required to touch at least a single key for the closure be detected. And, of course, closing stdin in itself is problematic in more complex programs.
I would like to propose adding a new method Terminal.Close which would terminate blocking ReadLine call, or adding ReadLineWithContext to achieve the same just using context.Context.
I don't think this is possible by default, as the function would still be blocked on the read without a way to interrupt it properly. see #24842 and #26579 for related workarounds.
Proposal Details
Reading a line from a terminal can only be interrupted by the user pressing CTRL+D or CTRL+C. API does not allow the reading to be interrupted via other means. This creates an impossible scenario if other goroutine should be the source of interrupt.
Closing an underlying file (
os.Stdin
) does not work as expected. A user is still required to touch at least a single key for the closure be detected. And, of course, closing stdin in itself is problematic in more complex programs.I would like to propose adding a new method
Terminal.Close
which would terminate blockingReadLine
call, or addingReadLineWithContext
to achieve the same just usingcontext.Context
.The text was updated successfully, but these errors were encountered: