mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
Improve console input EOF handling
Related to #126. Need some Windows tester to tell me how it works.
This commit is contained in:
parent
61f35db554
commit
5a33eda766
14
m/pager.go
14
m/pager.go
@ -422,6 +422,12 @@ func (p *Pager) StartPaging(screen twin.Screen) {
|
||||
log.Trace("Pager starting")
|
||||
defer log.Trace("Pager done")
|
||||
|
||||
defer func() {
|
||||
if p.reader.err != nil {
|
||||
log.Warnf("Reader reported an error: %s", p.reader.err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
unprintableStyle = p.UnprintableStyle
|
||||
ConsumeLessTermcapEnvs()
|
||||
|
||||
@ -528,6 +534,10 @@ func (p *Pager) StartPaging(screen twin.Screen) {
|
||||
case twin.EventResize:
|
||||
// We'll be implicitly redrawn just by taking another lap in the loop
|
||||
|
||||
case twin.EventExit:
|
||||
log.Debug("Got a Twin exit event, exiting")
|
||||
return
|
||||
|
||||
case eventMoreLinesAvailable:
|
||||
if p.mode.isViewing() && p.Following {
|
||||
p.scrollToEnd()
|
||||
@ -544,10 +554,6 @@ func (p *Pager) StartPaging(screen twin.Screen) {
|
||||
log.Warnf("Unhandled event type: %v", event)
|
||||
}
|
||||
}
|
||||
|
||||
if p.reader.err != nil {
|
||||
log.Warnf("Reader reported an error: %s", p.reader.err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// After the pager has exited and the normal screen has been restored, you can
|
||||
|
@ -30,6 +30,14 @@ type EventResize struct {
|
||||
// This interface intentionally left blank
|
||||
}
|
||||
|
||||
// If we're unable to continue showing the screen, we'll send this event and
|
||||
// drop out.
|
||||
//
|
||||
// Ref: https://github.com/walles/moar/issues/126
|
||||
type EventExit struct {
|
||||
// This interface intentionally left blank
|
||||
}
|
||||
|
||||
func (eventRune *EventRune) Rune() rune {
|
||||
return eventRune.rune
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
package twin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -206,6 +208,14 @@ func (screen *UnixScreen) mainLoop() {
|
||||
for {
|
||||
count, err := screen.ttyIn.Read(buffer)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// This happens when the terminal window is closed
|
||||
var event Event = EventExit{}
|
||||
screen.events <- event
|
||||
return
|
||||
}
|
||||
|
||||
// Unknown error
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user