Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support custom input position #34

Merged
merged 5 commits into from Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/gofzf/main.go
Expand Up @@ -34,7 +34,8 @@ var (
flagSelectedPrefix string
flagUnselectedPrefix string

flagCountView bool
flagInputPosition string
flagCountView bool

flagPromptFg string
flagPromptBg string
Expand Down Expand Up @@ -129,6 +130,8 @@ var rootCmd = &cobra.Command{
fzf.WithSelectedPrefix(flagSelectedPrefix),
fzf.WithUnselectedPrefix(flagUnselectedPrefix),

fzf.WithInputPosition(fzf.InputPosition(flagInputPosition)),

fzf.WithCountViewEnabled(flagCountView),

fzf.WithStyles(
Expand Down Expand Up @@ -340,6 +343,8 @@ func init() {
rootCmd.Flags().StringVar(&flagSelectedPrefix, "selected-prefix", "● ", "")
rootCmd.Flags().StringVar(&flagUnselectedPrefix, "unselected-prefix", "◯ ", "")

rootCmd.Flags().StringVar(&flagInputPosition, "input-position", string(fzf.InputPositionTop), "position of input (top|bottom)")

rootCmd.Flags().BoolVar(&flagCountView, "count-view", true, "")

rootCmd.Flags().StringVar(&flagPromptFg, "prompt-fg", "", "")
Expand Down
7 changes: 7 additions & 0 deletions docs/cli/README.ja.md
Expand Up @@ -54,6 +54,7 @@ $ go install github.com/koki-develop/go-fzf/cmd/gofzf@latest
`gofzf` CLI はフラグを使用して様々な見た目のカスタマイズができます。

- [プロンプト](#プロンプト)
- [インプットの位置](#インプットの位置)
- [インプットのプレースホルダ](#インプットのプレースホルダ)
- [インプットのテキスト](#インプットのテキスト)
- [カーソル](#カーソル)
Expand All @@ -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` が有効です。 |

#### インプットのプレースホルダ

| フラグ | デフォルト | 説明 |
Expand Down
7 changes: 7 additions & 0 deletions docs/cli/README.md
Expand Up @@ -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)
Expand All @@ -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 |
Expand Down
16 changes: 16 additions & 0 deletions docs/library/README.ja.md
Expand Up @@ -154,6 +154,7 @@ if err != nil {
- [プロンプト](#プロンプト)
- [カーソル](#カーソル)
- [選択中 / 未選択アイテムの接頭辞](#選択中--未選択アイテムの接頭辞)
- [インプットの位置](#インプットの位置)
- [インプットのプレースホルダ](#インプットのプレースホルダ)
- [カウントビュー](#カウントビュー)
- [スタイル](#スタイル)
Expand Down Expand Up @@ -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()` を使用するとインプットのプレースホルダを設定できます。
Expand Down
16 changes: 16 additions & 0 deletions docs/library/README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/input-position/README.md
@@ -0,0 +1 @@
![](./demo.gif)
Binary file added examples/input-position/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions 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])
}
}
4 changes: 4 additions & 0 deletions fzf.go
Expand Up @@ -29,6 +29,10 @@ func New(opts ...Option) (*FZF, error) {
return nil, errors.New("limit must be at least 1")
}

if err := o.inputPosition.Valid(); err != nil {
return nil, err
}

m := newModel(&o)

return &FZF{
Expand Down