Skip to content

Commit b2c4573

Browse files
authored
Fix PTY layout problems (#3658)
- **PR Description** This fixes two layout problems with pagers that draw a horizontal line across the entire width of the view (e.g. delta): - sometimes the width of that line was one character too long or too short in the staged changes view - when changing from a file or directory that has only staged or only unstaged changes to one that has both, the length of the horizontal line was totally off and only redraw correctly at the next refresh
2 parents c401f34 + 8b8343b commit b2c4573

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

pkg/gui/gui.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,3 +959,12 @@ func (gui *Gui) onWorker(f func(gocui.Task) error) {
959959
func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions {
960960
return gui.helpers.WindowArrangement.GetWindowDimensions(informationStr, appStatus)
961961
}
962+
963+
func (gui *Gui) afterLayout(f func() error) {
964+
select {
965+
case gui.afterLayoutFuncs <- f:
966+
default:
967+
// hopefully this never happens
968+
gui.c.Log.Error("afterLayoutFuncs channel is full, skipping function")
969+
}
970+
}

pkg/gui/gui_common.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,7 @@ func (self *guiCommon) GetInitialKeybindingsWithCustomCommands() ([]*types.Bindi
189189
}
190190

191191
func (self *guiCommon) AfterLayout(f func() error) {
192-
select {
193-
case self.gui.afterLayoutFuncs <- f:
194-
default:
195-
// hopefully this never happens
196-
self.gui.c.Log.Error("afterLayoutFuncs channel is full, skipping function")
197-
}
192+
self.gui.afterLayout(f)
198193
}
199194

200195
func (self *guiCommon) RunningIntegrationTest() bool {

pkg/gui/main_panels.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ func (gui *Gui) runTaskForView(view *gocui.View, task types.UpdateTask) error {
2020
return gui.newCmdTask(view, v.Cmd, v.Prefix)
2121

2222
case *types.RunPtyTask:
23-
return gui.newPtyTask(view, v.Cmd, v.Prefix)
23+
gui.afterLayout(func() error {
24+
return gui.newPtyTask(view, v.Cmd, v.Prefix)
25+
})
26+
return nil
2427
}
2528

2629
return nil

pkg/gui/pty.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"github.com/samber/lo"
1616
)
1717

18-
func (gui *Gui) desiredPtySize() *pty.Winsize {
19-
width, height := gui.Views.Main.Size()
18+
func (gui *Gui) desiredPtySize(view *gocui.View) *pty.Winsize {
19+
width, height := view.Size()
2020

2121
return &pty.Winsize{Cols: uint16(width), Rows: uint16(height)}
2222
}
@@ -25,11 +25,12 @@ func (gui *Gui) onResize() error {
2525
gui.Mutexes.PtyMutex.Lock()
2626
defer gui.Mutexes.PtyMutex.Unlock()
2727

28-
for _, ptmx := range gui.viewPtmxMap {
28+
for viewName, ptmx := range gui.viewPtmxMap {
2929
// TODO: handle resizing properly: we need to actually clear the main view
3030
// and re-read the output from our pty. Or we could just re-run the original
3131
// command from scratch
32-
if err := pty.Setsize(ptmx, gui.desiredPtySize()); err != nil {
32+
view, _ := gui.g.View(viewName)
33+
if err := pty.Setsize(ptmx, gui.desiredPtySize(view)); err != nil {
3334
return utils.WrapError(err)
3435
}
3536
}
@@ -44,7 +45,7 @@ func (gui *Gui) onResize() error {
4445
// pseudo-terminal meaning we'll get the behaviour we want from the underlying
4546
// command.
4647
func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
47-
width, _ := gui.Views.Main.Size()
48+
width, _ := view.Size()
4849
pager := gui.git.Config.GetPager(width)
4950
externalDiffCommand := gui.Config.GetUserConfig().Git.Paging.ExternalDiffCommand
5051

@@ -69,7 +70,7 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
6970
var ptmx *os.File
7071
start := func() (*exec.Cmd, io.Reader) {
7172
var err error
72-
ptmx, err = pty.StartWithSize(cmd, gui.desiredPtySize())
73+
ptmx, err = pty.StartWithSize(cmd, gui.desiredPtySize(view))
7374
if err != nil {
7475
gui.c.Log.Error(err)
7576
}

0 commit comments

Comments
 (0)