Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain exec output #1276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ func (p *Program) exec(c ExecCommand, fn ExecCallback) {

// Execute system command.
if err := c.Run(); err != nil {
p.renderer.resetLinesRendered()
_ = p.RestoreTerminal() // also try to restore the terminal.
if fn != nil {
go p.Send(fn(err))
}
return
}

// Maintain the existing output from the command
p.renderer.resetLinesRendered()

// Have the program re-capture input.
err := p.RestoreTerminal()
if fn != nil {
Expand Down
1 change: 1 addition & 0 deletions nil_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ func (n nilRenderer) setWindowTitle(_ string) {}
func (n nilRenderer) reportFocus() bool { return false }
func (n nilRenderer) enableReportFocus() {}
func (n nilRenderer) disableReportFocus() {}
func (n nilRenderer) resetLinesRendered() {}
2 changes: 2 additions & 0 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type renderer interface {

// disableReportFocus stops reporting focus events to the program.
disableReportFocus()

resetLinesRendered()
}

// repaintMsg forces a full repaint.
Expand Down
4 changes: 4 additions & 0 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ func (r *standardRenderer) clearIgnoredLines() {
r.ignoreLines = nil
}

func (r *standardRenderer) resetLinesRendered() {
r.linesRendered = 0
}

// insertTop effectively scrolls up. It inserts lines at the top of a given
// area designated to be a scrollable region, pushing everything else down.
// This is roughly how ncurses does it.
Expand Down