diff --git a/oviewer/document.go b/oviewer/document.go index 0ecf88b7..e2b6bba2 100644 --- a/oviewer/document.go +++ b/oviewer/document.go @@ -177,7 +177,7 @@ type Document struct { nonMatch bool // pauseFollow indicates if follow mode is paused. pauseFollow bool - // pauseFollowNum is the line number where follow mode was paused. + // pauseLastNum is the line number where follow mode was paused. pauseLastNum int // General is the General settings. General General @@ -207,7 +207,7 @@ type store struct { eof int32 // size is the number of bytes read. size int64 - // offset + // offset is the current byte offset in the file. offset int64 // formfeedTime adds time on formfeed. formfeedTime bool @@ -428,18 +428,18 @@ func (m *Document) CurrentLN() int { // Export exports the document in the specified range. func (m *Document) Export(w io.Writer, start int, end int) error { - return m.export(w, start, end, m.store.export) + return m.exportRange(w, start, end, false) } // ExportPlain exports the document in the specified range without ANSI escape sequences. func (m *Document) ExportPlain(w io.Writer, start int, end int) error { - return m.export(w, start, end, m.store.exportPlain) + return m.exportRange(w, start, end, true) } -// storeExportFunc is a function type for exporting lines from a chunk. -type storeExportFunc func(w io.Writer, chunk *chunk, start int, end int) error - -func (m *Document) export(w io.Writer, start int, end int, exportFunc storeExportFunc) error { +// exportRange exports the document in the specified range. +// If plain is true, it writes plain text (no ANSI escapes), otherwise +// it preserves ANSI escape sequences. +func (m *Document) exportRange(w io.Writer, start int, end int, plain bool) error { end = min(end, m.BufEndNum()-1) startChunk, startCn := chunkLineNum(start) endChunk, endCn := chunkLineNum(end) @@ -451,7 +451,13 @@ func (m *Document) export(w io.Writer, start int, end int, exportFunc storeExpor ecn = endCn + 1 } chunk := m.store.chunks[chunkNum] - if err := exportFunc(w, chunk, scn, ecn); err != nil { + var err error + if plain { + err = m.store.exportPlain(w, chunk, scn, ecn) + } else { + err = m.store.export(w, chunk, scn, ecn) + } + if err != nil { return err } scn = 0 @@ -472,7 +478,7 @@ func (m *Document) BufEndNum() int { return int(atomic.LoadInt32(&m.store.endNum)) } -// BufEndNum return last line number. +// storeEndNum returns the last line number from the main store, ignoring follow mode. func (m *Document) storeEndNum() int { return int(atomic.LoadInt32(&m.store.endNum)) } diff --git a/oviewer/oviewer.go b/oviewer/oviewer.go index ce96bb28..415b0efc 100644 --- a/oviewer/oviewer.go +++ b/oviewer/oviewer.go @@ -662,8 +662,8 @@ func (root *Root) SetConfig(config Config) { // view mode. if config.ViewMode != "" { - viewMode, overwrite := config.Mode[config.ViewMode] - if overwrite { + viewMode, ok := config.Mode[config.ViewMode] + if ok { root.settings = updateRunTimeSettings(root.settings, viewMode) } else { root.setMessageLogf("view mode not found: %s", config.ViewMode) diff --git a/oviewer/search.go b/oviewer/search.go index d651b803..c4c4ad75 100644 --- a/oviewer/search.go +++ b/oviewer/search.go @@ -485,7 +485,10 @@ func (root *Root) cancelWait(cancel context.CancelFunc) error { // cancelKeys sets the cancel key. func cancelKeys(c *cbind.Configuration, cancelKeys []string, cancelApp func(_ *tcell.EventKey) *tcell.EventKey) (*cbind.Configuration, error) { for _, k := range cancelKeys { - c.Set(k, cancelApp) + err := c.Set(k, cancelApp) + if err != nil { + return nil, fmt.Errorf("cancelKeys: %w", err) + } } return c, nil } diff --git a/oviewer/store.go b/oviewer/store.go index eb69bce6..004c95bd 100644 --- a/oviewer/store.go +++ b/oviewer/store.go @@ -360,6 +360,7 @@ func (s *store) appendFormFeed(chunk *chunk) { } } +// export exports the lines including ANSI escape sequences. func (s *store) export(w io.Writer, chunk *chunk, start int, end int) error { s.mu.RLock() defer s.mu.RUnlock()