peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Add functional options to bring your own stdin writer #154

Closed hinshun closed 2 years ago

hinshun commented 2 years ago

I have a use case where I need to take back control of os.Stdin occasionally, so I would like to pass in my own io.Writer.

peterh commented 2 years ago

This changes the API in a backwards-incompatible way, and therefore I cannot accept this pull request.

If you need to take back control of stdin, you can either close and re-open Liner, or you can use TerminalMode to capture the state before and after NewLiner, and ApplyMode the before to regain control, remembering to ApplyMode the after state before calling liner.Prompt again.

hinshun commented 2 years ago

Happy to close the PR, but wondering what part of it is backwards-incompatible? All calls liner.NewLiner() will continue to work.

peterh commented 2 years ago

You're right that most simple uses will continue to work. However, if anybody assigns NewLiner to a function pointer, the type of liner.NewLiner won't match any more. (Admittedly this is extremely niche and unlikely to affect anybody, but "unlikely" isn't the same as "can't".)