Skip to content

Commit f98da78

Browse files
committed
Fix possible off-by-one error wrt PTY size
All PTYs were created with the size of the main view, on the assumption that main and secondary always have the same size. That's not true though; in horizontal split mode, the width of the two views can differ by one because of rounding, and when using a pager that draws a horizontal line across the width of the view, this is visible and looks very ugly.
1 parent c401f34 commit f98da78

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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)