From 18ff4644df8e47e6fe77a38fa4c8b3c751a082de Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 9 Jun 2021 22:25:27 -0400 Subject: [PATCH] Fix double-EOF for mlr hex from terminal --- go/src/auxents/hex.go | 14 ++++++++++++-- go/todo.txt | 1 - 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/go/src/auxents/hex.go b/go/src/auxents/hex.go index e06e0aead..07a571279 100644 --- a/go/src/auxents/hex.go +++ b/go/src/auxents/hex.go @@ -99,7 +99,8 @@ func hexDumpFile(istream *os.File, doRaw bool) { } // io.ErrUnexpectedEOF is the normal case when the file size isn't an - // exact multiple of our buffer size. + // exact multiple of our buffer size. We'll break the loop after + // hex-dumping this last, partial fragment. if err != nil && err != io.ErrUnexpectedEOF { fmt.Fprintln(os.Stderr, "mlr hex:", err) os.Exit(1) @@ -141,7 +142,16 @@ func hexDumpFile(istream *os.File, doRaw bool) { // Print line end fmt.Printf("\n") - offset += numBytesRead + // Break the loop if this was the last, partial fragment. If we don't + // break here we'll go back to the top of the loop and try the next + // read and get EOF -- which works fine if the input is a file. But if + // the input is at the terminal, the user will have to control-D twice + // which will be unsettling. + if numBytesRead < bufferSize { + eof = true + break + } + offset += numBytesRead } } diff --git a/go/todo.txt b/go/todo.txt index f15e8fc92..4f885851c 100644 --- a/go/todo.txt +++ b/go/todo.txt @@ -5,7 +5,6 @@ TOP OF LIST: * --nr-progress-mod * mlr -k * * gha binaries * cli-audits * doc6 * survey * check issues * * split up mlr -h -* mlr hex double eof -- ? * snk postntn ----------------------------------------------------------------