diff options
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/commit_files_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 15 | ||||
-rw-r--r-- | pkg/gui/pty.go | 21 | ||||
-rw-r--r-- | pkg/gui/reflog_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/stash_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/tasks_adapter.go | 49 |
8 files changed, 89 insertions, 8 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 63458926b..5fa7a4683 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -50,7 +50,7 @@ func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error { cmd := gui.OSCommand.ExecutableFromString( gui.GitCommand.ShowCommitFileCmdStr(commitFile.Sha, commitFile.Name, false), ) - if err := gui.newCmdTask("main", cmd); err != nil { + if err := gui.newPtyTask("main", cmd); err != nil { gui.Log.Error(err) } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index fe6b7acb9..0c901d085 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -67,7 +67,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { cmd := gui.OSCommand.ExecutableFromString( gui.GitCommand.ShowCmdStr(commit.Sha), ) - if err := gui.newCmdTask("main", cmd); err != nil { + if err := gui.newPtyTask("main", cmd); err != nil { gui.Log.Error(err) } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 4e00dc523..6bd2c7076 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -62,7 +62,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { gui.getSecondaryView().Title = gui.Tr.SLocalize("StagedChanges") cmdStr := gui.GitCommand.DiffCmdStr(file, false, true) cmd := gui.OSCommand.ExecutableFromString(cmdStr) - if err := gui.newCmdTask("secondary", cmd); err != nil { + if err := gui.newPtyTask("secondary", cmd); err != nil { return err } } else { @@ -76,7 +76,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { cmdStr := gui.GitCommand.DiffCmdStr(file, false, !file.HasUnstagedChanges && file.HasStagedChanges) cmd := gui.OSCommand.ExecutableFromString(cmdStr) - if err := gui.newCmdTask("main", cmd); err != nil { + if err := gui.newPtyTask("main", cmd); err != nil { return err } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 70c3c3f51..9289c4e31 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -211,6 +211,9 @@ type guiState struct { Searching searchingState ScreenMode int SideView *gocui.View + Ptmx *os.File + PrevMainWidth int + PrevMainHeight int } // for now the split view will always be on @@ -247,6 +250,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma }, ScreenMode: SCREEN_NORMAL, SideView: nil, + Ptmx: nil, } gui := &Gui{ @@ -811,6 +815,15 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } + mainViewWidth, mainViewHeight := gui.getMainView().Size() + if mainViewWidth != gui.State.PrevMainWidth || mainViewHeight != gui.State.PrevMainHeight { + gui.State.PrevMainWidth = mainViewWidth + gui.State.PrevMainHeight = mainViewHeight + if err := gui.onResize(); err != nil { + return err + } + } + // here is a good place log some stuff // if you download humanlog and do tail -f development.log | humanlog // this will let you see these branches as prettified json @@ -942,7 +955,7 @@ func (gui *Gui) startBackgroundFetch() { // Run setup the gui with keybindings and start the mainloop func (gui *Gui) Run() error { - g, err := gocui.NewGui(gocui.OutputNormal, OverlappingEdges) + g, err := gocui.NewGui(gocui.Output256, OverlappingEdges) if err != nil { return err } diff --git a/pkg/gui/pty.go b/pkg/gui/pty.go new file mode 100644 index 000000000..18fb98fda --- /dev/null +++ b/pkg/gui/pty.go @@ -0,0 +1,21 @@ +package gui + +import ( + "github.com/jesseduffield/pty" +) + +func (gui *Gui) onResize() error { + if gui.State.Ptmx == nil { + return nil + } + mainView := gui.getMainView() + width, height := mainView.Size() + + if err := pty.Setsize(gui.State.Ptmx, &pty.Winsize{Cols: uint16(width), Rows: uint16(height)}); err != nil { + return err + } + + // TODO: handle resizing properly + + return nil +} diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index 37144d8c6..1837e2f7d 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -41,7 +41,7 @@ func (gui *Gui) handleReflogCommitSelect(g *gocui.Gui, v *gocui.View) error { cmd := gui.OSCommand.ExecutableFromString( gui.GitCommand.ShowCmdStr(commit.Sha), ) - if err := gui.newCmdTask("main", cmd); err != nil { + if err := gui.newPtyTask("main", cmd); err != nil { gui.Log.Error(err) } diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index db12767e8..92d84df9f 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -41,7 +41,7 @@ func (gui *Gui) handleStashEntrySelect(g *gocui.Gui, v *gocui.View) error { cmd := gui.OSCommand.ExecutableFromString( gui.GitCommand.ShowStashEntryCmdStr(stashEntry.Index), ) - if err := gui.newCmdTask("main", cmd); err != nil { + if err := gui.newPtyTask("main", cmd); err != nil { gui.Log.Error(err) } diff --git a/pkg/gui/tasks_adapter.go b/pkg/gui/tasks_adapter.go index 22ebb9da9..38d7ce36b 100644 --- a/pkg/gui/tasks_adapter.go +++ b/pkg/gui/tasks_adapter.go @@ -5,6 +5,7 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/tasks" + "github.com/jesseduffield/pty" ) func (gui *Gui) newCmdTask(viewName string, cmd *exec.Cmd) error { @@ -25,6 +26,49 @@ func (gui *Gui) newCmdTask(viewName string, cmd *exec.Cmd) error { return nil } +func (gui *Gui) newPtyTask(viewName string, cmd *exec.Cmd) error { + width, _ := gui.getMainView().Size() + pager, err := gui.GitCommand.GetPager(width) + if err != nil { + return err + } + + if pager == "" { + // if we're not using a custom pager we don't need to use a pty + return gui.newCmdTask(viewName, cmd) + } + + cmd.Env = append(cmd.Env, "GIT_PAGER="+pager) + + view, err := gui.g.View(viewName) + if err != nil { + return nil // swallowing for now + } + + _, height := view.Size() + _, oy := view.Origin() + + manager := gui.getManager(view) + + ptmx, err := pty.Start(cmd) + if err != nil { + return err + } + + gui.State.Ptmx = ptmx + onClose := func() { gui.State.Ptmx = nil } + + if err := gui.onResize(); err != nil { + return err + } + + if err := manager.NewTask(manager.NewPtyTask(ptmx, cmd, height+oy+10, onClose)); err != nil { + return err + } + + return nil +} + func (gui *Gui) newTask(viewName string, f func(chan struct{}) error) error { view, err := gui.g.View(viewName) if err != nil { @@ -69,7 +113,10 @@ func (gui *Gui) getManager(view *gocui.View) *tasks.ViewBufferManager { view.Clear() }, func() { - gui.g.Update(func(*gocui.Gui) error { return nil }) + gui.g.Update(func(*gocui.Gui) error { + gui.Log.Warn("updating view") + return nil + }) }) gui.viewBufferManagerMap[view.Name()] = manager } |