term: process bytes returned with a read error

The io.Reader contract permits Read to return both data and a non-nil
error. readLine currently returns the error before processing the data,
which can discard the final complete line when a reader returns data
with io.EOF.

Append returned bytes to the input buffer and save the accompanying
error. Report the error after the buffered input has been processed,
preserving it across ReadLine calls when the input contains a complete
line.

Add a regression test for a reader that returns "line\r" and io.EOF in
the same call.

Fixes golang/go#80661

Change-Id: I34ac28731ec40f3398b9c0990e19cc17b737ba9e
Reviewed-on: https://go-review.googlesource.com/c/term/+/808420
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 files changed
tree: e34026091614cdf7a32824c82a940a16370c6f03
  1. codereview.cfg
  2. CONTRIBUTING.md
  3. go.mod
  4. go.sum
  5. LICENSE
  6. PATENTS
  7. README.md
  8. term.go
  9. term_plan9.go
  10. term_test.go
  11. term_unix.go
  12. term_unix_bsd.go
  13. term_unix_other.go
  14. term_unsupported.go
  15. term_windows.go
  16. terminal.go
  17. terminal_test.go
README.md

Go terminal/console support

Go Reference

This repository provides Go terminal and console support packages.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/term.

The main issue tracker for the term repository is located at https://go.dev/issues. Prefix your issue with “x/term:” in the subject line, so it is easy to find.