Add tty-write command (#1961)
This command offers a synchronized way to write to /dev/tty.
This commit is contained in:
1 parent
0df0c0f5ff
commit
1cb9e9d14a
5 files changed
+50
-10
No files matched your search
@@ -80,6 +80,7 @@ var (
|
||||
"mark-remove",
|
||||
"tag",
|
||||
"tag-toggle",
|
||||
"tty-write",
|
||||
"cmd-escape",
|
||||
"cmd-complete",
|
||||
"cmd-menu-complete",
|
||||
|
||||
@@ -102,6 +102,7 @@ The following commands are provided by lf:
|
||||
mark-remove (modal) (default '"')
|
||||
tag
|
||||
tag-toggle (default 't')
|
||||
tty-write
|
||||
|
||||
The following command line commands are provided by lf:
|
||||
|
||||
@@ -569,6 +570,12 @@ You can define a new tag-clearing command by combining `tag` with `tag-toggle` (
|
||||
|
||||
Tag a file with `*` or a single width character given in the argument if the file is untagged, otherwise remove the tag.
|
||||
|
||||
## tty-write
|
||||
|
||||
Write the given string to the tty.
|
||||
This is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).
|
||||
Using `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.
|
||||
|
||||
# COMMAND LINE COMMANDS
|
||||
|
||||
The prompt character specifies which of the several command-line modes you are in.
|
||||
@@ -1681,11 +1688,11 @@ You can define it just as you would define any other command:
|
||||
'
|
||||
}}
|
||||
|
||||
If you want to print escape sequences, you may redirect `printf` output to `/dev/tty`.
|
||||
If you want to send escape sequences to the terminal, you can use the `tty-write` command to do so.
|
||||
The following xterm-specific escape sequence sets the terminal title to the working directory:
|
||||
|
||||
cmd on-cd &{{
|
||||
printf "\033]0; $PWD\007" > /dev/tty
|
||||
lf -remote "send $id tty-write \"\033]0;$PWD\007\""
|
||||
}}
|
||||
|
||||
This command runs whenever you change the directory but not on startup.
|
||||
|
||||
@@ -92,6 +92,7 @@ The following commands are provided by lf:
|
||||
mark-remove (modal) (default '"')
|
||||
tag
|
||||
tag-toggle (default 't')
|
||||
tty-write
|
||||
|
||||
The following command line commands are provided by lf:
|
||||
|
||||
@@ -588,6 +589,14 @@ tag-toggle (default t)
|
||||
Tag a file with * or a single width character given in the argument if
|
||||
the file is untagged, otherwise remove the tag.
|
||||
|
||||
tty-write
|
||||
|
||||
Write the given string to the tty. This is useful for sending escape
|
||||
sequences to the terminal to control its behavior (e.g. OSC 0 to set the
|
||||
window title). Using tty-write is preferred over directly writing to
|
||||
/dev/tty because the latter is not synchronized and can interfere with
|
||||
drawing the UI.
|
||||
|
||||
COMMAND LINE COMMANDS
|
||||
|
||||
The prompt character specifies which of the several command-line modes
|
||||
@@ -1893,12 +1902,12 @@ would define any other command:
|
||||
'
|
||||
}}
|
||||
|
||||
If you want to print escape sequences, you may redirect printf output to
|
||||
/dev/tty. The following xterm-specific escape sequence sets the terminal
|
||||
title to the working directory:
|
||||
If you want to send escape sequences to the terminal, you can use the
|
||||
tty-write command to do so. The following xterm-specific escape sequence
|
||||
sets the terminal title to the working directory:
|
||||
|
||||
cmd on-cd &{{
|
||||
printf "\033]0; $PWD\007" > /dev/tty
|
||||
lf -remote "send $id tty-write \"\033]0;$PWD\007\""
|
||||
}}
|
||||
|
||||
This command runs whenever you change the directory but not on startup.
|
||||
|
||||
@@ -1061,6 +1061,19 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app, true)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case "tty-write":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("tty-write: requires an argument")
|
||||
return
|
||||
}
|
||||
|
||||
tty, ok := app.ui.screen.Tty()
|
||||
if !ok {
|
||||
log.Printf("tty-write: failed to get tty")
|
||||
return
|
||||
}
|
||||
|
||||
tty.Write([]byte(e.args[0]))
|
||||
case "scroll-down":
|
||||
if !app.nav.init {
|
||||
return
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 2.11.4
|
||||
.\"
|
||||
.TH "LF" "1" "2025-04-08" "r34-21-g3fdd991" "DOCUMENTATION"
|
||||
.TH "LF" "1" "2025-04-13" "" "DOCUMENTATION"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
@@ -102,6 +102,7 @@ mark-load (modal) (default \[dq]\[aq]\[dq])
|
||||
mark-remove (modal) (default \[aq]\[dq]\[aq])
|
||||
tag
|
||||
tag-toggle (default \[aq]t\[aq])
|
||||
tty-write
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -627,6 +628,15 @@ with \f[C]tag-toggle\f[R] (i.e.
|
||||
.PP
|
||||
Tag a file with \f[C]*\f[R] or a single width character given in the
|
||||
argument if the file is untagged, otherwise remove the tag.
|
||||
.SS tty-write
|
||||
.PP
|
||||
Write the given string to the tty.
|
||||
This is useful for sending escape sequences to the terminal to control
|
||||
its behavior (e.g.
|
||||
OSC 0 to set the window title).
|
||||
Using \f[C]tty-write\f[R] is preferred over directly writing to
|
||||
\f[C]/dev/tty\f[R] because the latter is not synchronized and can
|
||||
interfere with drawing the UI.
|
||||
.SH COMMAND LINE COMMANDS
|
||||
.PP
|
||||
The prompt character specifies which of the several command-line modes
|
||||
@@ -2154,15 +2164,15 @@ cmd on-cd &{{
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
If you want to print escape sequences, you may redirect \f[C]printf\f[R]
|
||||
output to \f[C]/dev/tty\f[R].
|
||||
If you want to send escape sequences to the terminal, you can use the
|
||||
\f[C]tty-write\f[R] command to do so.
|
||||
The following xterm-specific escape sequence sets the terminal title to
|
||||
the working directory:
|
||||
.IP
|
||||
.nf
|
||||
\f[C]
|
||||
cmd on-cd &{{
|
||||
printf \[dq]\[rs]033]0; $PWD\[rs]007\[dq] > /dev/tty
|
||||
lf -remote \[dq]send $id tty-write \[rs]\[dq]\[rs]033]0;$PWD\[rs]007\[rs]\[dq]\[dq]
|
||||
}}
|
||||
\f[R]
|
||||
.fi
|
||||
|
||||
Reference in new issue
Block a user