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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.quitChan:
|
case <-app.quitChan:
|
||||||
@@ -322,6 +324,7 @@ func (app *app) loop() {
|
|||||||
cmd.eval(app, nil)
|
cmd.eval(app, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUiExit(app)
|
||||||
app.quit()
|
app.quit()
|
||||||
|
|
||||||
app.nav.previewChan <- ""
|
app.nav.previewChan <- ""
|
||||||
@@ -461,12 +464,14 @@ func (app *app) loop() {
|
|||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||||
app.nav.previewChan <- ""
|
app.nav.previewChan <- ""
|
||||||
app.nav.dirPreviewChan <- nil
|
app.nav.dirPreviewChan <- nil
|
||||||
|
|
||||||
|
onUiExit(app)
|
||||||
if err := app.ui.suspend(); err != nil {
|
if err := app.ui.suspend(); err != nil {
|
||||||
log.Printf("suspend: %s", err)
|
log.Printf("suspend: %s", err)
|
||||||
}
|
}
|
||||||
@@ -475,6 +480,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
|||||||
app.quit()
|
app.quit()
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
|
onUiEnter(app)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
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
|
// % No No Yes Yes Yes Statline for input/output
|
||||||
// ! Yes No Yes Yes Yes Pause and then resume
|
// ! Yes No Yes Yes Yes Pause and then resume
|
||||||
// & No Yes No No No Do nothing
|
// & 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) {
|
func (app *app) runShell(s string, args []string, prefix string) {
|
||||||
app.nav.exportFiles()
|
app.nav.exportFiles()
|
||||||
app.ui.exportSizes()
|
app.ui.exportSizes()
|
||||||
@@ -513,12 +520,17 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
var out io.Reader
|
var out io.Reader
|
||||||
var err error
|
var err error
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "$", "!":
|
case "$", "!", "^":
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stderr
|
cmd.Stdout = os.Stderr
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
if prefix != "^" {
|
||||||
app.runCmdSync(cmd, prefix == "!")
|
app.runCmdSync(cmd, prefix == "!")
|
||||||
|
} else {
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
app.ui.echoerrf("running ^shell: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ The following special shell commands are used to customize the behavior of lf wh
|
|||||||
pre-cd
|
pre-cd
|
||||||
on-cd
|
on-cd
|
||||||
on-select
|
on-select
|
||||||
|
on-ui-enter
|
||||||
|
on-ui-exit
|
||||||
on-quit
|
on-quit
|
||||||
|
|
||||||
The following commands/keybindings are provided by default:
|
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.
|
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
|
on-quit
|
||||||
|
|
||||||
This shell command can be defined to be executed before quit.
|
This shell command can be defined to be executed before quit.
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ when defined:
|
|||||||
pre-cd
|
pre-cd
|
||||||
on-cd
|
on-cd
|
||||||
on-select
|
on-select
|
||||||
|
on-ui-enter
|
||||||
|
on-ui-exit
|
||||||
on-quit
|
on-quit
|
||||||
|
|
||||||
The following commands/keybindings are provided by default:
|
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.
|
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
|
on-quit
|
||||||
|
|
||||||
This shell command can be defined to be executed before 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) {
|
func splitKeys(s string) (keys []string) {
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
r, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
@@ -2764,6 +2780,9 @@ func (e *execExpr) eval(app *app, args []string) {
|
|||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s -- %s", e, args)
|
log.Printf("shell-async: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, e.prefix)
|
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:
|
default:
|
||||||
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
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
|
pre-cd
|
||||||
on-cd
|
on-cd
|
||||||
on-select
|
on-select
|
||||||
|
on-ui-enter
|
||||||
|
on-ui-exit
|
||||||
on-quit
|
on-quit
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
@@ -1332,6 +1334,18 @@ This shell command can be defined to be executed after changing a directory.
|
|||||||
.PP
|
.PP
|
||||||
This shell command can be defined to be executed after the selection changes.
|
This shell command can be defined to be executed after the selection changes.
|
||||||
.PP
|
.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
|
.EX
|
||||||
on-quit
|
on-quit
|
||||||
.EE
|
.EE
|
||||||
|
|||||||
@@ -1449,17 +1449,32 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readCmdEvent(ev tcell.Event) expr {
|
func (ui *ui) readCmdEvent(ev tcell.Event) expr {
|
||||||
switch tev := ev.(type) {
|
switch tev := ev.(type) {
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
if tev.Key() == tcell.KeyRune {
|
if tev.Key() == tcell.KeyRune {
|
||||||
if tev.Modifiers() == tcell.ModMask(tcell.ModAlt) {
|
if tev.Modifiers() == tcell.ModMask(tcell.ModAlt) {
|
||||||
val := string([]rune{'<', 'a', '-', tev.Rune(), '>'})
|
// support multi-key bindings but only for ESC[ at the moment
|
||||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
if tev.Rune() == '[' {
|
||||||
return expr
|
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 {
|
} 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 {
|
} else {
|
||||||
val := gKeyVal[tev.Key()]
|
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 != "" {
|
if _, ok := ev.(*tcell.EventKey); ok && ui.cmdPrefix != "" {
|
||||||
return readCmdEvent(ev)
|
return ui.readCmdEvent(ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ui.readNormalEvent(ev, nav)
|
return ui.readNormalEvent(ev, nav)
|
||||||
|
|||||||
Reference in new issue
Block a user