Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oviewer/doclist.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (root *Root) insertDocument(ctx context.Context, num int, m *Document) {
root.DocList = append(root.DocList[:num+1], append([]*Document{m}, root.DocList[num+1:]...)...)
root.mu.Unlock()

go root.waitForEOF(m)

root.setDocumentNum(ctx, num+1)
root.setMessageLogf("insert %s%s", m.FileName, m.Caption)
}
Expand Down
17 changes: 17 additions & 0 deletions oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,25 @@ func (root *Root) applySelectionRange(y int, start int, end int, selectState Mou
}
}

func (root *Root) quitCheck() bool {
if !root.Config.QuitSmall {
return false
}
if !root.docSmall() {
return false
}
if root.DocumentLen() == 1 && !root.Config.QuitSmallFilter {
root.Config.IsWriteOnExit = true
return true
}
return false
}

// notifyEOFReached notifies that EOF has been reached.
func (root *Root) notifyEOFReached(m *Document) {
if root.Config.NotifyEOF == 0 {
return
}
root.setMessagef("EOF reached %s", m.FileName)
root.notify(root.Config.NotifyEOF)
}
Expand Down
9 changes: 4 additions & 5 deletions oviewer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (root *Root) event(ctx context.Context, ev tcell.Event) bool {
case *eventSearchMove:
root.searchGo(ctx, ev.ln, ev.searcher)
case *eventReachEOF:
// Quit if small doc and config allows
if root.quitCheck() {
return true
}
root.notifyEOFReached(ev.m)

// Input confirmation action event.
Expand Down Expand Up @@ -386,10 +390,6 @@ func (root *Root) sendReachEOF(m *Document) {

// monitorEOF monitors the EOF of the document.
func (root *Root) monitorEOF() {
if root.Config.NotifyEOF == 0 {
return
}
log.Println("monitorEOF")
for _, m := range root.DocList {
go root.waitForEOF(m)
}
Expand All @@ -403,5 +403,4 @@ func (root *Root) waitForEOF(m *Document) {
m.cond.L.Unlock()
}
root.sendReachEOF(m)
log.Println("EOF reached", m.FileName)
}
6 changes: 6 additions & 0 deletions oviewer/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (root *Root) nextSection(ctx context.Context) {
root.setMessage("No more next sections")
}
}

if root.Config.QuitSmall {
// Reset quitSmallCountDown to avoid quitting when a key is pressed.
root.Config.QuitSmall = false
root.setMessage("Quit small mode canceled")
}
}

// prevSection moves up to the delimiter of the previous section.
Expand Down
11 changes: 5 additions & 6 deletions oviewer/oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,6 @@ func (root *Root) Run() error {
return err
}

// Quit if fits on screen.
if root.Config.QuitSmall && root.DocumentLen() == 1 && root.docSmall() {
root.Config.IsWriteOnExit = true
return nil
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
sigSuspend := registerSIGTSTP()
Expand Down Expand Up @@ -834,6 +828,11 @@ func (root *Root) prepareRun(ctx context.Context) error {

root.setViewModeConfig()
root.prepareAllDocuments()
// follow mode or follow all disables quit if the output fits on one screen.
if root.Doc.FollowMode || root.FollowAll {
root.Config.QuitSmall = false
root.Config.QuitSmallFilter = false
}
// Quit by filter result. This is evaluated lazily.
if root.Config.QuitSmallFilter {
root.quitSmallCountDown = QuitSmallCountDown
Expand Down
Loading