Skip to content

Commit

Permalink
suspend the application instead of stopping
Browse files Browse the repository at this point in the history
fixes dundee#90
  • Loading branch information
dundee committed Sep 5, 2021
1 parent fb01cc1 commit 3286bfc
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.16

require (
github.com/fatih/color v1.12.0
github.com/gdamore/tcell/v2 v2.4.0
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/mattn/go-isatty v0.0.13
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c // indirect
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
)
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.3.3/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM=
github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -410,8 +410,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c h1:Lyn7+CqXIiC+LOR9aHD6jDK+hPcmAuCfuXztd1v4w1Q=
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg=
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -424,6 +424,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
1 change: 1 addition & 0 deletions internal/common/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type TermApplication interface {
Run() error
Stop()
Suspend(f func()) bool
SetRoot(root tview.Primitive, fullscreen bool) *tview.Application
SetFocus(p tview.Primitive) *tview.Application
SetInputCapture(capture func(event *tcell.EventKey) *tcell.EventKey) *tview.Application
Expand Down
6 changes: 6 additions & 0 deletions internal/testapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func (app *MockedApp) Run() error {
// Stop does nothing
func (app *MockedApp) Stop() {}

// Suspend runs given function
func (app *MockedApp) Suspend(f func()) bool {
f()
return true
}

// SetRoot does nothing
func (app *MockedApp) SetRoot(root tview.Primitive, fullscreen bool) *tview.Application {
return nil
Expand Down
18 changes: 18 additions & 0 deletions tui/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tui

import (
"os"
"os/exec"
)

// Execute runs given bin path via exec.Command call
func Execute(argv0 string, argv []string, envv []string) error {
cmd := exec.Command(argv0, argv...)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = envv

return cmd.Run()
}
7 changes: 0 additions & 7 deletions tui/exec_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ package tui

import (
"os"
"syscall"
)

// Execute runs given bin path via the Exec syscall
func Execute(argv0 string, argv []string, envv []string) error {
// append argv0 to argv, as execve will make first argument the "binary name".
return syscall.Exec(argv0, append([]string{argv0}, argv...), envv)
}

func getShellBin() string {
shellbin, ok := os.LookupEnv("SHELL")
if !ok {
Expand Down
15 changes: 0 additions & 15 deletions tui/exec_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ import (
"os/exec"
)

// Execute runs given bin path via exec.Command call
func Execute(argv0 string, argv []string, envv []string) error {
// Windows does not support exec syscall.
cmd := exec.Command(argv0, argv...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = envv
err := cmd.Run()
if err == nil {
os.Exit(0)
}
return err
}

func getShellBin() string {
shellbin, ok := os.LookupEnv("COMSPEC")
if !ok {
Expand Down
18 changes: 10 additions & 8 deletions tui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ func (ui *UI) spawnShell() {
return
}

ui.app.Stop()
if err := os.Chdir(ui.currentDirPath); err != nil {
ui.showErr("Error changing directory", err)
return
}
if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
ui.showErr("Error executing shell", err)
}
ui.app.Suspend(func() {
if err := os.Chdir(ui.currentDirPath); err != nil {
ui.showErr("Error changing directory", err)
return
}

if err := ui.exec(getShellBin(), nil, os.Environ()); err != nil {
ui.showErr("Error executing shell", err)
}
})
}

0 comments on commit 3286bfc

Please sign in to comment.