diff --git a/docs/cli/README.ja.md b/docs/cli/README.ja.md index 66c5967..59e09f7 100644 --- a/docs/cli/README.ja.md +++ b/docs/cli/README.ja.md @@ -54,6 +54,7 @@ $ go install github.com/koki-develop/go-fzf/cmd/gofzf@latest `gofzf` CLI はフラグを使用して様々な見た目のカスタマイズができます。 - [プロンプト](#プロンプト) +- [インプットの位置](#インプットの位置) - [インプットのプレースホルダ](#インプットのプレースホルダ) - [インプットのテキスト](#インプットのテキスト) - [カーソル](#カーソル) @@ -75,6 +76,12 @@ $ go install github.com/koki-develop/go-fzf/cmd/gofzf@latest | `--prompt-underline` | `false` | プロンプトに下線を引く。 | | `--prompt-faint` | `false` | プロンプトを薄く表示する。 | +#### インプットの位置 + +| フラグ | デフォルト | 説明 | +| ------------------ | ---------- | ------------------------------------------------------- | +| `--input-position` | `"top"` | インプットの位置。 `top` もしくは `bottom` が有効です。 | + #### インプットのプレースホルダ | フラグ | デフォルト | 説明 | diff --git a/docs/cli/README.md b/docs/cli/README.md index c5c97c7..41757a6 100644 --- a/docs/cli/README.md +++ b/docs/cli/README.md @@ -54,6 +54,7 @@ Setting the `--no-limit` flag allows unlimited item selection. The `gofzf` CLI allows for various visual customizations using flags. - [Prompt](#prompt) +- [Position of input](#position-of-input) - [Placeholder for input](#placeholder-for-input) - [Input text](#input-text) - [Cursor](#cursor) @@ -75,6 +76,12 @@ The `gofzf` CLI allows for various visual customizations using flags. | `--prompt-underline` | `false` | Underline prompt. | | `--prompt-faint` | `false` | Faint prompt. | +#### Position of input + +| Flag | Default | Description | +| ------------------ | ------- | ----------------------------------------------------- | +| `--input-position` | `"top"` | Position of input. Either `top` or `bottom` is valid. | + #### Placeholder for input | Flag | Default | Description | diff --git a/docs/library/README.ja.md b/docs/library/README.ja.md index d83a955..fb9a020 100644 --- a/docs/library/README.ja.md +++ b/docs/library/README.ja.md @@ -154,6 +154,7 @@ if err != nil { - [プロンプト](#プロンプト) - [カーソル](#カーソル) - [選択中 / 未選択アイテムの接頭辞](#選択中--未選択アイテムの接頭辞) +- [インプットの位置](#インプットの位置) - [インプットのプレースホルダ](#インプットのプレースホルダ) - [カウントビュー](#カウントビュー) - [スタイル](#スタイル) @@ -201,6 +202,21 @@ if err != nil { [Example](/examples/prefix/) +#### インプットの位置 + +`fzf.WithInputPosition()` を使用するとインプットの位置を設定できます。 + +```go +f, err := fzf.New( + fzf.WithInputPosition(fzf.InputPositionBottom), +) +if err != nil { + // ... +} +``` + +[Example](/examples/input-position/) + #### インプットのプレースホルダ `fzf.WithInputPlaceholder()` を使用するとインプットのプレースホルダを設定できます。 diff --git a/docs/library/README.md b/docs/library/README.md index 1a05500..211780f 100644 --- a/docs/library/README.md +++ b/docs/library/README.md @@ -155,6 +155,7 @@ if err != nil { - [Prompt](#prompt) - [Cursor](#cursor) - [Prefix of selected/unselected items](#prefix-of-selectedunselected-items) +- [Position of input](#position-of-input) - [Placeholder for input](#placeholder-for-input) - [Count View](#count-view) - [Styles](#styles) @@ -203,6 +204,21 @@ if err != nil { [Example](/examples/prefix/) +#### Position of input + +`fzf.WithInputPosition()` can be used to set the position of input. + +```go +f, err := fzf.New( + fzf.WithInputPosition(fzf.InputPositionBottom), +) +if err != nil { + // ... +} +``` + +[Example](/examples/input-position/) + #### Placeholder for input `fzf.WithCursor()` can be used to set the placeholder for input. diff --git a/examples/input-position/README.md b/examples/input-position/README.md new file mode 100644 index 0000000..b6cb717 --- /dev/null +++ b/examples/input-position/README.md @@ -0,0 +1 @@ +![](./demo.gif) diff --git a/examples/input-position/demo.gif b/examples/input-position/demo.gif new file mode 100644 index 0000000..b26f950 Binary files /dev/null and b/examples/input-position/demo.gif differ diff --git a/examples/input-position/main.go b/examples/input-position/main.go new file mode 100644 index 0000000..2306f71 --- /dev/null +++ b/examples/input-position/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "log" + + "github.com/koki-develop/go-fzf" +) + +func main() { + items := []string{"hello", "world", "foo", "bar"} + + f, err := fzf.New( + fzf.WithInputPosition(fzf.InputPositionBottom), + ) + if err != nil { + log.Fatal(err) + } + + idxs, err := f.Find(items, func(i int) string { return items[i] }) + if err != nil { + log.Fatal(err) + } + + for _, i := range idxs { + fmt.Println(items[i]) + } +} diff --git a/option.go b/option.go index e07a4c0..ef64d78 100644 --- a/option.go +++ b/option.go @@ -221,7 +221,7 @@ func WithCaseSensitive(s bool) Option { } } -// WithInputPosition sets the position of the input. +// WithInputPosition sets the position of input. func WithInputPosition(p InputPosition) Option { return func(o *option) { o.inputPosition = p diff --git a/tapes/library/input-position.tape b/tapes/library/input-position.tape new file mode 100644 index 0000000..b378122 --- /dev/null +++ b/tapes/library/input-position.tape @@ -0,0 +1,39 @@ +# configuration +Output ./examples/input-position/demo.gif +Set Shell "bash" +Set FontSize 32 +Set Width 1200 +Set Height 600 + +# setup +Hide +Type "mkdir ./tmp" Enter +Type "cp ./examples/input-position/main.go ./tmp/main.go" Enter +Type "cd ./tmp" Enter +Ctrl+l +Show + +# --- + +Type "go run ./main.go" Sleep 750ms Enter +Sleep 2s + +Up 2 +Sleep 1s + +Down 2 +Sleep 1s + +Type "world" +Sleep 750ms + +Enter + +Sleep 3s + +# --- + +# cleanup +Hide +Type "cd ../" Enter +Type "\rm -rf ./tmp" Enter