mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 20:23:50 -07:00
Add --ghost=TEXT
to display a ghost text when the input is empty
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.61.0
|
||||||
|
------
|
||||||
|
- Added `--ghost=TEXT` to display a ghost text when the input is empty
|
||||||
|
```sh
|
||||||
|
# Display "Type to search" when the input is empty
|
||||||
|
fzf --ghost "Type to search"
|
||||||
|
```
|
||||||
|
|
||||||
0.60.3
|
0.60.3
|
||||||
------
|
------
|
||||||
- Bug fixes and improvements
|
- Bug fixes and improvements
|
||||||
|
@@ -709,6 +709,10 @@ ANSI color codes are supported.
|
|||||||
Do not display horizontal separator on the info line. A synonym for
|
Do not display horizontal separator on the info line. A synonym for
|
||||||
\fB\-\-separator=''\fB
|
\fB\-\-separator=''\fB
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-ghost=" "TEXT"
|
||||||
|
Ghost text to display when the input is empty
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B "\-\-filepath\-word"
|
.B "\-\-filepath\-word"
|
||||||
Make word-wise movements and actions respect path separators. The following
|
Make word-wise movements and actions respect path separators. The following
|
||||||
|
@@ -136,6 +136,7 @@ Usage: fzf [options]
|
|||||||
--separator=STR Draw horizontal separator on info line using the string
|
--separator=STR Draw horizontal separator on info line using the string
|
||||||
(default: '─' or '-')
|
(default: '─' or '-')
|
||||||
--no-separator Hide info line separator
|
--no-separator Hide info line separator
|
||||||
|
--ghost=TEXT Ghost text to display when the input is empty
|
||||||
--filepath-word Make word-wise movements respect path separators
|
--filepath-word Make word-wise movements respect path separators
|
||||||
--input-border[=STYLE] Draw border around the input section
|
--input-border[=STYLE] Draw border around the input section
|
||||||
[rounded|sharp|bold|block|thinblock|double|horizontal|vertical|
|
[rounded|sharp|bold|block|thinblock|double|horizontal|vertical|
|
||||||
@@ -574,6 +575,7 @@ type Options struct {
|
|||||||
InfoStyle infoStyle
|
InfoStyle infoStyle
|
||||||
InfoPrefix string
|
InfoPrefix string
|
||||||
InfoCommand string
|
InfoCommand string
|
||||||
|
Ghost string
|
||||||
Separator *string
|
Separator *string
|
||||||
JumpLabels string
|
JumpLabels string
|
||||||
Prompt string
|
Prompt string
|
||||||
@@ -689,6 +691,7 @@ func defaultOptions() *Options {
|
|||||||
ScrollOff: 3,
|
ScrollOff: 3,
|
||||||
FileWord: false,
|
FileWord: false,
|
||||||
InfoStyle: infoDefault,
|
InfoStyle: infoDefault,
|
||||||
|
Ghost: "",
|
||||||
Separator: nil,
|
Separator: nil,
|
||||||
JumpLabels: defaultJumpLabels,
|
JumpLabels: defaultJumpLabels,
|
||||||
Prompt: "> ",
|
Prompt: "> ",
|
||||||
@@ -2597,6 +2600,10 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
|||||||
case "--no-separator":
|
case "--no-separator":
|
||||||
nosep := ""
|
nosep := ""
|
||||||
opts.Separator = &nosep
|
opts.Separator = &nosep
|
||||||
|
case "--ghost":
|
||||||
|
if opts.Ghost, err = nextString("ghost text required"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case "--scrollbar":
|
case "--scrollbar":
|
||||||
given, bar := optionalNextString()
|
given, bar := optionalNextString()
|
||||||
if given {
|
if given {
|
||||||
|
@@ -234,6 +234,7 @@ type Terminal struct {
|
|||||||
wrap bool
|
wrap bool
|
||||||
wrapSign string
|
wrapSign string
|
||||||
wrapSignWidth int
|
wrapSignWidth int
|
||||||
|
ghost string
|
||||||
separator labelPrinter
|
separator labelPrinter
|
||||||
separatorLen int
|
separatorLen int
|
||||||
spinner []string
|
spinner []string
|
||||||
@@ -847,6 +848,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
|||||||
infoCommand: opts.InfoCommand,
|
infoCommand: opts.InfoCommand,
|
||||||
infoStyle: opts.InfoStyle,
|
infoStyle: opts.InfoStyle,
|
||||||
infoPrefix: opts.InfoPrefix,
|
infoPrefix: opts.InfoPrefix,
|
||||||
|
ghost: opts.Ghost,
|
||||||
separator: nil,
|
separator: nil,
|
||||||
spinner: makeSpinner(opts.Unicode),
|
spinner: makeSpinner(opts.Unicode),
|
||||||
promptString: opts.Prompt,
|
promptString: opts.Prompt,
|
||||||
@@ -2359,6 +2361,11 @@ func (t *Terminal) printPrompt() {
|
|||||||
t.prompt()
|
t.prompt()
|
||||||
|
|
||||||
before, after := t.updatePromptOffset()
|
before, after := t.updatePromptOffset()
|
||||||
|
if len(before) == 0 && len(after) == 0 && len(t.ghost) > 0 {
|
||||||
|
w.CPrint(tui.ColInput.WithAttr(tui.Dim), t.ghost)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
color := tui.ColInput
|
color := tui.ColInput
|
||||||
if t.paused {
|
if t.paused {
|
||||||
color = tui.ColDisabled
|
color = tui.ColDisabled
|
||||||
|
@@ -1813,4 +1813,22 @@ class TestCore < TestInteractive
|
|||||||
assert_equal ['[0] 1st: foo, 3rd: baz, 2nd: bar'], File.readlines(tempname, chomp: true)
|
assert_equal ['[0] 1st: foo, 3rd: baz, 2nd: bar'], File.readlines(tempname, chomp: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ghost
|
||||||
|
tmux.send_keys %(seq 100 | #{FZF} --prompt 'X ' --ghost 'Type in query ...'), :Enter
|
||||||
|
tmux.until do |lines|
|
||||||
|
assert_equal 100, lines.match_count
|
||||||
|
assert_includes lines, 'X Type in query ...'
|
||||||
|
end
|
||||||
|
tmux.send_keys '100'
|
||||||
|
tmux.until do |lines|
|
||||||
|
assert_equal 1, lines.match_count
|
||||||
|
assert_includes lines, 'X 100'
|
||||||
|
end
|
||||||
|
tmux.send_keys 'C-u'
|
||||||
|
tmux.until do |lines|
|
||||||
|
assert_equal 100, lines.match_count
|
||||||
|
assert_includes lines, 'X Type in query ...'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user