Add 'bell' action to ring the terminal bell

This commit is contained in:
Junegunn Choi 2025-01-25 11:22:32 +09:00
parent 02199cd609
commit 04017c25bb
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
8 changed files with 22 additions and 0 deletions

View File

@ -9,10 +9,16 @@ CHANGELOG
- fzf will automatically choose `path` scheme when the input is a TTY device, where fzf would start its built-in walker or run `$FZF_DEFAULT_COMMAND` which is usually a command for listing files.
- Added `--header-lines-border` to display header from `--header-lines` with a separate border
```sh
# Use --header-lines-border to separate two headers
ps -ef | fzf --style full --layout reverse --header-lines 1 \
--bind 'ctrl-r:reload(ps -ef)' --header 'Press CTRL-R to reload' \
--header-lines-border bottom --no-list-border
```
- Added `bell` action to ring the terminal bell
```sh
# Press CTRL-Y to copy the current line to the clipboard and ring the bell
fzf --bind 'ctrl-y:execute-silent(echo -n {} | pbcopy)+bell'
```
- Bug fixes and improvements
- Fixed fish script to support fish 3.1.2 or later (@bitraid)

View File

@ -1541,6 +1541,7 @@ A key or an event can be bound to one or more of the following actions.
\fBbackward\-word\fR \fIalt\-b shift\-left\fR
\fBbecome(...)\fR (replace fzf process with the specified command; see below for the details)
\fBbeginning\-of\-line\fR \fIctrl\-a home\fR
\fBbell\fR (ring the terminal bell)
\fBcancel\fR (clear query string if not empty, abort fzf otherwise)
\fBchange\-border\-label(...)\fR (change \fB\-\-border\-label\fR to the given string)
\fBchange\-header(...)\fR (change header to the given string; doesn't affect \fB\-\-header\-lines\fR)

View File

@ -1586,6 +1586,8 @@ func parseActionList(masked string, original string, prevActions []*action, putA
} else {
return nil, errors.New("unable to put non-printable character")
}
case "bell":
appendAction(actBell)
default:
t := isExecuteAction(specLower)
if t == actIgnore {

View File

@ -567,6 +567,7 @@ const (
actBecome
actShowHeader
actHideHeader
actBell
)
func (a actionType) Name() string {
@ -4704,6 +4705,8 @@ func (t *Terminal) Loop() error {
t.executor.Become(t.ttyin, t.environ(), command)
}
}
case actBell:
t.tui.Bell()
case actExecute, actExecuteSilent:
t.executeCommand(a.a, false, a.t == actExecuteSilent, false, false, "")
case actExecuteMulti:

View File

@ -44,6 +44,7 @@ func (r *FullscreenRenderer) PassThrough(string) {}
func (r *FullscreenRenderer) Clear() {}
func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }
func (r *FullscreenRenderer) ShouldEmitResizeEvent() bool { return false }
func (r *FullscreenRenderer) Bell() {}
func (r *FullscreenRenderer) Refresh() {}
func (r *FullscreenRenderer) Close() {}
func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }

View File

@ -32,6 +32,10 @@ const consoleDevice string = "/dev/tty"
var offsetRegexp = regexp.MustCompile("(.*)\x1b\\[([0-9]+);([0-9]+)R")
var offsetRegexpBegin = regexp.MustCompile("^\x1b\\[[0-9]+;[0-9]+R")
func (r *LightRenderer) Bell() {
r.flushRaw("\a")
}
func (r *LightRenderer) PassThrough(str string) {
r.queued.WriteString("\x1b7" + str + "\x1b8")
}

View File

@ -100,6 +100,10 @@ const (
BoldForce = Attr(1 << 10)
)
func (r *FullscreenRenderer) Bell() {
_screen.Beep()
}
func (r *FullscreenRenderer) PassThrough(str string) {
// No-op
// https://github.com/gdamore/tcell/pull/650#issuecomment-1806442846

View File

@ -580,6 +580,7 @@ type Renderer interface {
PassThrough(string)
NeedScrollbarRedraw() bool
ShouldEmitResizeEvent() bool
Bell()
GetChar() Event