1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 12:16:54 +02:00

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.
This commit is contained in:
Stefan Haller 2024-06-12 16:52:27 +02:00
parent c401f34530
commit f98da780de

View File

@ -15,8 +15,8 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
) )
func (gui *Gui) desiredPtySize() *pty.Winsize { func (gui *Gui) desiredPtySize(view *gocui.View) *pty.Winsize {
width, height := gui.Views.Main.Size() width, height := view.Size()
return &pty.Winsize{Cols: uint16(width), Rows: uint16(height)} return &pty.Winsize{Cols: uint16(width), Rows: uint16(height)}
} }
@ -25,11 +25,12 @@ func (gui *Gui) onResize() error {
gui.Mutexes.PtyMutex.Lock() gui.Mutexes.PtyMutex.Lock()
defer gui.Mutexes.PtyMutex.Unlock() defer gui.Mutexes.PtyMutex.Unlock()
for _, ptmx := range gui.viewPtmxMap { for viewName, ptmx := range gui.viewPtmxMap {
// TODO: handle resizing properly: we need to actually clear the main view // TODO: handle resizing properly: we need to actually clear the main view
// and re-read the output from our pty. Or we could just re-run the original // and re-read the output from our pty. Or we could just re-run the original
// command from scratch // command from scratch
if err := pty.Setsize(ptmx, gui.desiredPtySize()); err != nil { view, _ := gui.g.View(viewName)
if err := pty.Setsize(ptmx, gui.desiredPtySize(view)); err != nil {
return utils.WrapError(err) return utils.WrapError(err)
} }
} }
@ -44,7 +45,7 @@ func (gui *Gui) onResize() error {
// pseudo-terminal meaning we'll get the behaviour we want from the underlying // pseudo-terminal meaning we'll get the behaviour we want from the underlying
// command. // command.
func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error { func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
width, _ := gui.Views.Main.Size() width, _ := view.Size()
pager := gui.git.Config.GetPager(width) pager := gui.git.Config.GetPager(width)
externalDiffCommand := gui.Config.GetUserConfig().Git.Paging.ExternalDiffCommand externalDiffCommand := gui.Config.GetUserConfig().Git.Paging.ExternalDiffCommand
@ -69,7 +70,7 @@ func (gui *Gui) newPtyTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
var ptmx *os.File var ptmx *os.File
start := func() (*exec.Cmd, io.Reader) { start := func() (*exec.Cmd, io.Reader) {
var err error var err error
ptmx, err = pty.StartWithSize(cmd, gui.desiredPtySize()) ptmx, err = pty.StartWithSize(cmd, gui.desiredPtySize(view))
if err != nil { if err != nil {
gui.c.Log.Error(err) gui.c.Log.Error(err)
} }