add 'cmd-interrupt' command to kill current shell

This commit is contained in:
Gokcehan 2018-04-03 22:56:38 +03:00
parent c63c8f63ac
commit e55c490bf5
5 changed files with 15 additions and 0 deletions

4
app.go
View File

@ -6,6 +6,7 @@ import (
"io" "io"
"log" "log"
"os" "os"
"os/exec"
"strconv" "strconv"
"strings" "strings"
) )
@ -19,6 +20,7 @@ type app struct {
ui *ui ui *ui
nav *nav nav *nav
quitChan chan bool quitChan chan bool
cmd *exec.Cmd
cmdIn io.WriteCloser cmdIn io.WriteCloser
cmdHist []cmdItem cmdHist []cmdItem
cmdHistInd int cmdHistInd int
@ -230,6 +232,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix { switch prefix {
case "%": case "%":
go func() { go func() {
app.cmd = cmd
app.ui.msg = "" app.ui.msg = ""
app.ui.cmdPrefix = ">" app.ui.cmdPrefix = ">"
@ -252,6 +255,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
log.Printf("running shell: %s", err) log.Printf("running shell: %s", err)
} }
app.nav.renew(app.ui.wins[0].h) app.nav.renew(app.ui.wins[0].h)
app.cmd = nil
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
app.ui.draw(app.nav) app.ui.draw(app.nav)
}() }()

1
doc.go
View File

@ -69,6 +69,7 @@ keybindings:
cmd-delete-word (default '<c-w>') cmd-delete-word (default '<c-w>')
cmd-put (default '<c-y>') cmd-put (default '<c-y>')
cmd-transpose (default '<c-t>') cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>')
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:

View File

@ -73,6 +73,7 @@ keybindings:
cmd-delete-word (default '<c-w>') cmd-delete-word (default '<c-w>')
cmd-put (default '<c-y>') cmd-put (default '<c-y>')
cmd-transpose (default '<c-t>') cmd-transpose (default '<c-t>')
cmd-interrupt (default '<c-c>')
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:

View File

@ -559,6 +559,14 @@ func (e *callExpr) eval(app *app, args []string) {
if len(app.ui.cmdAccLeft) > 1 { if len(app.ui.cmdAccLeft) > 1 {
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1] app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
} }
case "cmd-interrupt":
if app.cmd != nil {
app.cmd.Process.Kill()
}
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
default: default:
cmd, ok := gOpts.cmds[e.name] cmd, ok := gOpts.cmds[e.name]
if !ok { if !ok {

View File

@ -124,6 +124,7 @@ func init() {
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil} gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil} gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil} gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil}
gOpts.cmds = make(map[string]expr) gOpts.cmds = make(map[string]expr)