ExecProcess with AltScreen shows output of previous run of ExecProcess for a few milliseconds #1464
|
I'm doing a simple thing that allows one to select a git commit from a list, and then launch a diff tool to show it. This is all cobbled together from the tutorial and the exec/altscreen examples, but changing the I have a hard-coded list of commits SHAs in the initial model. When I pick a commit from the list and pass it into a Any ideas how I could get it to not show the wrong output when running |
Replies: 1 comment
|
This is a known quirk of how
The straightforward workaround is to clear the screen inside the command itself: func openDiff(sha string) tea.Cmd {
c := exec.Command("bash", "-c", "printf '\\033[2J\\033[H' && git show "+sha+" | delta --paging always")
return tea.ExecProcess(c, func(err error) tea.Msg {
return diffFinishedMsg{err}
})
}The Alternatively, keep it simpler with c := exec.Command("bash", "-c", "clear; git show "+sha+" | delta --paging always")If you're already running inside AltScreen, the root cause is the same — bubbletea doesn't clear before handing off to the subprocess, so the old frame is still visible until the child process draws over it. |
This is a known quirk of how
ExecProcesshands off to the external process. When bubbletea suspends its renderer and passes control to the child process, the terminal still has whatever was last drawn in it — the new process hasn't written anything yet, so for a few milliseconds you see the stale content.tea.Sequence(tea.ClearScreen, diffCmd)doesn't reliably fix this because the clear is queued through bubbletea's renderer and may not be flushed to the terminal before the handoff happens.The straightforward workaround is to clear the screen inside the command itself: