Proposal Details

The documentation recommends getting the file descriptor with the following:

oldState, err := term.MakeRaw(int(os.Stdin.Fd()))

os.Stdin.Fd returns a uintptr, which can't (technically) be safely cast to an int. This appears to be because on windows, the value may be non-numeric. It isn't clear that this lib handles that case, and the use of int obscures that.

term should take a uintptr as its fd and handle cross-platform terminal behavior gracefully. If it isn't going to do that, the docs should be updated to make it clear that x/term really only applies to unix terminals.

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: ianlancetaylor

Thanks, but we can't make a change like this. It would break existing working programs. Updating the documentation is fine, and does not require an issue to be filed.

Comment From: tstirrat15

@ianlancetaylor cool, I'm happy to make that change. Where does the documentation live? It isn't clear from https://pkg.go.dev/golang.org/x/term or https://github.com/golang/go/tree/master/doc or https://go.dev/doc/contribute or https://cs.opensource.google/go/x/term (seems to be read-only?) where I might find the relevant repository.

Comment From: ianlancetaylor

The relevant repo is https://go.googlesource.com/term. Thanks.