Enable focus events through configuration by using focus (option) and on-ui-enter/on-ui-exit events.
This commit is contained in:
6 files changed
+93
-9
No files matched your search
@@ -300,6 +300,8 @@ func (app *app) loop() {
|
||||
}()
|
||||
}
|
||||
|
||||
onUiEnter(app)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-app.quitChan:
|
||||
@@ -322,6 +324,7 @@ func (app *app) loop() {
|
||||
cmd.eval(app, nil)
|
||||
}
|
||||
|
||||
onUiExit(app)
|
||||
app.quit()
|
||||
|
||||
app.nav.previewChan <- ""
|
||||
@@ -461,12 +464,14 @@ func (app *app) loop() {
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||
app.nav.previewChan <- ""
|
||||
app.nav.dirPreviewChan <- nil
|
||||
|
||||
onUiExit(app)
|
||||
if err := app.ui.suspend(); err != nil {
|
||||
log.Printf("suspend: %s", err)
|
||||
}
|
||||
@@ -475,6 +480,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||
app.quit()
|
||||
os.Exit(3)
|
||||
}
|
||||
onUiEnter(app)
|
||||
}()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
@@ -495,6 +501,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||
// % No No Yes Yes Yes Statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
// ^ No No Yes Yes Yes (internal for events)
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.nav.exportFiles()
|
||||
app.ui.exportSizes()
|
||||
@@ -513,12 +520,17 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
var out io.Reader
|
||||
var err error
|
||||
switch prefix {
|
||||
case "$", "!":
|
||||
case "$", "!", "^":
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
app.runCmdSync(cmd, prefix == "!")
|
||||
if prefix != "^" {
|
||||
app.runCmdSync(cmd, prefix == "!")
|
||||
} else {
|
||||
if err := cmd.Run(); err != nil {
|
||||
app.ui.echoerrf("running ^shell: %s", err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -208,6 +208,8 @@ The following special shell commands are used to customize the behavior of lf wh
|
||||
pre-cd
|
||||
on-cd
|
||||
on-select
|
||||
on-ui-enter
|
||||
on-ui-exit
|
||||
on-quit
|
||||
|
||||
The following commands/keybindings are provided by default:
|
||||
@@ -1110,6 +1112,14 @@ This shell command can be defined to be executed after changing a directory.
|
||||
|
||||
This shell command can be defined to be executed after the selection changes.
|
||||
|
||||
on-ui-enter
|
||||
|
||||
This shell command can be defined to be executed when the UI of lf becomes active. This will be triggered after lf starts and when foreground shell commands finish.
|
||||
|
||||
on-ui-exit
|
||||
|
||||
This shell command can be defined to be executed when the UI of lf becomes inactive. This will be triggered before lf exits and before starting foreground shell commands.
|
||||
|
||||
on-quit
|
||||
|
||||
This shell command can be defined to be executed before quit.
|
||||
|
||||
@@ -212,6 +212,8 @@ when defined:
|
||||
pre-cd
|
||||
on-cd
|
||||
on-select
|
||||
on-ui-enter
|
||||
on-ui-exit
|
||||
on-quit
|
||||
|
||||
The following commands/keybindings are provided by default:
|
||||
@@ -1202,6 +1204,18 @@ This shell command can be defined to be executed after changing a directory.
|
||||
|
||||
This shell command can be defined to be executed after the selection changes.
|
||||
|
||||
on-ui-enter
|
||||
|
||||
This shell command can be defined to be executed when the UI of lf becomes
|
||||
active. This will be triggered after lf starts and when foreground shell
|
||||
commands finish.
|
||||
|
||||
on-ui-exit
|
||||
|
||||
This shell command can be defined to be executed when the UI of lf becomes
|
||||
inactive. This will be triggered before lf exits and before starting foreground
|
||||
shell commands.
|
||||
|
||||
on-quit
|
||||
|
||||
This shell command can be defined to be executed before quit.
|
||||
|
||||
@@ -1157,6 +1157,22 @@ func onSelect(app *app) {
|
||||
}
|
||||
}
|
||||
|
||||
func onUiEnter(app *app) {
|
||||
if cmd, ok := gOpts.cmds["on-ui-enter"]; ok {
|
||||
ecmd := cmd.(*execExpr)
|
||||
ecmd.prefix = "^"
|
||||
ecmd.eval(app, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func onUiExit(app *app) {
|
||||
if cmd, ok := gOpts.cmds["on-ui-exit"]; ok {
|
||||
ecmd := cmd.(*execExpr)
|
||||
ecmd.prefix = "^"
|
||||
ecmd.eval(app, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func splitKeys(s string) (keys []string) {
|
||||
for i := 0; i < len(s); {
|
||||
r, w := utf8.DecodeRuneInString(s[i:])
|
||||
@@ -2764,6 +2780,9 @@ func (e *execExpr) eval(app *app, args []string) {
|
||||
case "&":
|
||||
log.Printf("shell-async: %s -- %s", e, args)
|
||||
app.runShell(e.value, args, e.prefix)
|
||||
case "^":
|
||||
log.Printf("shell-sync-evt: %s -- %s", e, args)
|
||||
app.runShell(e.value, args, e.prefix)
|
||||
default:
|
||||
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
||||
}
|
||||
|
||||
@@ -231,6 +231,8 @@ The following special shell commands are used to customize the behavior of lf wh
|
||||
pre-cd
|
||||
on-cd
|
||||
on-select
|
||||
on-ui-enter
|
||||
on-ui-exit
|
||||
on-quit
|
||||
.EE
|
||||
.PP
|
||||
@@ -1332,6 +1334,18 @@ This shell command can be defined to be executed after changing a directory.
|
||||
.PP
|
||||
This shell command can be defined to be executed after the selection changes.
|
||||
.PP
|
||||
.EX
|
||||
on-ui-enter
|
||||
.EE
|
||||
.PP
|
||||
This shell command can be defined to be executed when the UI of lf becomes active. This will be triggered after lf starts and when foreground shell commands finish.
|
||||
.PP
|
||||
.EX
|
||||
on-ui-exit
|
||||
.EE
|
||||
.PP
|
||||
This shell command can be defined to be executed when the UI of lf becomes inactive. This will be triggered before lf exits and before starting foreground shell commands.
|
||||
.PP
|
||||
.EX
|
||||
on-quit
|
||||
.EE
|
||||
|
||||
@@ -1449,17 +1449,32 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func readCmdEvent(ev tcell.Event) expr {
|
||||
func (ui *ui) readCmdEvent(ev tcell.Event) expr {
|
||||
switch tev := ev.(type) {
|
||||
case *tcell.EventKey:
|
||||
if tev.Key() == tcell.KeyRune {
|
||||
if tev.Modifiers() == tcell.ModMask(tcell.ModAlt) {
|
||||
val := string([]rune{'<', 'a', '-', tev.Rune(), '>'})
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
return expr
|
||||
// support multi-key bindings but only for ESC[ at the moment
|
||||
if tev.Rune() == '[' {
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'a', '-', tev.Rune(), '>')
|
||||
} else {
|
||||
val := string([]rune{'<', 'a', '-', tev.Rune(), '>'})
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
return expr
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return &callExpr{"cmd-insert", []string{string(tev.Rune())}, 1}
|
||||
// multi-key bindings
|
||||
if ui.keyAcc != nil {
|
||||
ui.keyAcc = append(ui.keyAcc, tev.Rune())
|
||||
val := string(ui.keyAcc)
|
||||
ui.keyAcc = nil
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
return expr
|
||||
}
|
||||
} else {
|
||||
return &callExpr{"cmd-insert", []string{string(tev.Rune())}, 1}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[tev.Key()]
|
||||
@@ -1478,7 +1493,7 @@ func (ui *ui) readEvent(ev tcell.Event, nav *nav) expr {
|
||||
}
|
||||
|
||||
if _, ok := ev.(*tcell.EventKey); ok && ui.cmdPrefix != "" {
|
||||
return readCmdEvent(ev)
|
||||
return ui.readCmdEvent(ev)
|
||||
}
|
||||
|
||||
return ui.readNormalEvent(ev, nav)
|
||||
|
||||
Reference in new issue
Block a user