parent
c071e37316
commit
2c3cd35a5d
18
app.go
18
app.go
@ -366,20 +366,6 @@ func (app *app) exportFiles() {
|
||||
exportFiles(currFile, currSelections)
|
||||
}
|
||||
|
||||
func waitKey() error {
|
||||
cmd := pauseCommand()
|
||||
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("waiting key: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// This function is used to run a shell command. Modes are as follows:
|
||||
//
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
@ -430,9 +416,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
|
||||
switch prefix {
|
||||
case "!":
|
||||
if err := waitKey(); err != nil {
|
||||
app.ui.echoerrf("waiting key: %s", err)
|
||||
}
|
||||
anyKey()
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav, true)
|
||||
|
1
go.mod
1
go.mod
@ -5,5 +5,6 @@ go 1.12
|
||||
require (
|
||||
github.com/gdamore/tcell/v2 v2.2.0
|
||||
github.com/mattn/go-runewidth v0.0.10
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
|
||||
gopkg.in/djherbis/times.v1 v1.2.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -12,6 +12,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuF
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
|
||||
|
12
os.go
12
os.go
@ -94,18 +94,6 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
cmd := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
old=$(stty -g)
|
||||
stty raw -echo
|
||||
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
|
||||
stty $old
|
||||
echo`
|
||||
|
||||
return exec.Command(gOpts.shell, "-c", cmd)
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
if len(gOpts.ifs) != 0 {
|
||||
s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s)
|
||||
|
@ -76,10 +76,6 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
return exec.Command("cmd", "/c", "pause")
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
args = append([]string{"/c", s}, args...)
|
||||
|
||||
|
13
ui.go
13
ui.go
@ -17,6 +17,7 @@ import (
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/mattn/go-runewidth"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const gEscapeCode = 27
|
||||
@ -1151,6 +1152,18 @@ func (ui *ui) resume() {
|
||||
ui.screen.Resume()
|
||||
}
|
||||
|
||||
func anyKey() {
|
||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
||||
|
||||
fmt.Print("Press any key to continue")
|
||||
b := make([]byte, 1)
|
||||
os.Stdin.Read(b)
|
||||
}
|
||||
|
||||
func listMatches(screen tcell.Screen, matches []string) (*bytes.Buffer, error) {
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user