RFC: writesto(cmd) do io ... end #6945
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a recent thread on the mailing list about how to use a pager like
less
in the REPL. I was curious to see how we would page toless
directly, and it took me a bit more digging than I would have liked.This patch simplifies writing to a process by adding a new method to
writesto
that takes a functionf(io)
, much likeopen
and friends, so that you can do e.g.to page output through
less
.(I thought about a different name, like
writeall
, but overloadingwritesto
makes it easier to discover the alternative asynchronous form ofwritesto
.An alternative would be to overload
open
to either read or write from a command. But in this case I would get rid ofwritesto
andreadsfrom
entirely and replace them byopen(cmd, "w")
andopen(cmd, "r")
.