Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 10, 2020
1 parent b47ea7b commit 10ef521
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
10 changes: 9 additions & 1 deletion pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ func (gui *Gui) Run() error {

gui.waitForIntro.Add(1)

gui.goEvery(time.Second, gui.stopChan, gui.refreshPackages)
gui.goEvery(time.Millisecond*250, gui.stopChan, gui.refreshPackages)
gui.goEvery(time.Millisecond*50, gui.stopChan, gui.refreshScreen)

g.SetManager(gocui.ManagerFunc(gui.layout), gocui.ManagerFunc(gui.getFocusLayout()))

Expand All @@ -231,6 +232,13 @@ func (gui *Gui) Run() error {
return err
}

func (gui *Gui) refreshScreen() error {
gui.g.Update(func(*gocui.Gui) error {
return nil
})
return nil
}

// RunWithSubprocesses loops, instantiating a new gocui.Gui with each iteration
// if the error returned from a run is a ErrSubProcess, it runs the subprocess
// otherwise it handles the error, possibly by quitting the application
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
v.Wrap = true
v.FgColor = textColor
v.IgnoreCarriageReturns = true
v.Autoscroll = true
}

hiddenViewOffset := 9999
Expand Down
58 changes: 36 additions & 22 deletions pkg/gui/pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package gui

import (
"io"
"os/exec"

"github.com/creack/pty"
Expand Down Expand Up @@ -31,34 +32,47 @@ func (gui *Gui) onResize() error {
// pseudo-terminal meaning we'll get the behaviour we want from the underlying
// command.
func (gui *Gui) newPtyTask(viewName string, cmd *exec.Cmd) error {
view, err := gui.g.View(viewName)
if err != nil {
return nil // swallowing for now
}
go func() {
view, err := gui.g.View(viewName)
if err != nil {
return // swallowing for now
}

_, height := view.Size()
_, oy := view.Origin()
view.Clear()

manager := gui.getManager(view)
// _, height := view.Size()
// _, oy := view.Origin()

ptmx, err := pty.Start(cmd)
if err != nil {
return err
}
// manager := gui.getManager(view)

gui.State.Ptmx = ptmx
onClose := func() {
ptmx.Close()
gui.State.Ptmx = nil
}
ptmx, err := pty.Start(cmd)
if err != nil {
// swallowing for now (actually continue to swallow this)
return
}
view.StdinWriter = ptmx
view.Pty = true

if err := gui.onResize(); err != nil {
return err
}
gui.State.Ptmx = ptmx
onClose := func() {
ptmx.Close()
gui.State.Ptmx = nil
view.Pty = false
view.StdinWriter = nil
}

if err := manager.NewTask(manager.NewCmdTask(ptmx, cmd, height+oy+10, onClose)); err != nil {
return err
}
if err := gui.onResize(); err != nil {
// swallowing for now
return
}

_, _ = io.Copy(view, ptmx)

onClose()

// if err := manager.NewTask(manager.NewCmdTask(ptmx, cmd, height+oy+10, onClose)); err != nil {
// return err
// }
}()
return nil
}

0 comments on commit 10ef521

Please sign in to comment.