Skip to content

Commit

Permalink
Merge pull request #32 from koki-develop/custom-input-text-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed Mar 31, 2023
2 parents f825e71 + 31d6235 commit eed084e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 1 deletion.
28 changes: 28 additions & 0 deletions cmd/gofzf/main.go
Expand Up @@ -54,6 +54,15 @@ var (
flagInputPlaceholderUnderline bool
flagInputPlaceholderFaint bool

flagInputTextFg string
flagInputTextBg string
flagInputTextBold bool
flagInputTextBlink bool
flagInputTextItalic bool
flagInputTextStrikethrough bool
flagInputTextUnderline bool
flagInputTextFaint bool

flagCursorFg string
flagCursorBg string
flagCursorBold bool
Expand Down Expand Up @@ -143,6 +152,16 @@ var rootCmd = &cobra.Command{
Underline: flagInputPlaceholderUnderline,
Faint: flagInputPlaceholderFaint,
}),
fzf.WithStyleInputText(fzf.Style{
ForegroundColor: flagInputTextFg,
BackgroundColor: flagInputTextBg,
Bold: flagInputTextBold,
Blink: flagInputTextBlink,
Italic: flagInputTextItalic,
Strikethrough: flagInputTextStrikethrough,
Underline: flagInputTextUnderline,
Faint: flagInputTextFaint,
}),
fzf.WithStyleCursor(fzf.Style{
ForegroundColor: flagCursorFg,
BackgroundColor: flagCursorBg,
Expand Down Expand Up @@ -341,6 +360,15 @@ func init() {
rootCmd.Flags().BoolVar(&flagInputPlaceholderUnderline, "input-placeholder-underline", false, "")
rootCmd.Flags().BoolVar(&flagInputPlaceholderFaint, "input-placeholder-faint", true, "")

rootCmd.Flags().StringVar(&flagInputTextFg, "input-text-fg", "", "")
rootCmd.Flags().StringVar(&flagInputTextBg, "input-text-bg", "", "")
rootCmd.Flags().BoolVar(&flagInputTextBold, "input-text-bold", false, "")
rootCmd.Flags().BoolVar(&flagInputTextBlink, "input-text-blink", false, "")
rootCmd.Flags().BoolVar(&flagInputTextItalic, "input-text-italic", false, "")
rootCmd.Flags().BoolVar(&flagInputTextStrikethrough, "input-text-strike", false, "")
rootCmd.Flags().BoolVar(&flagInputTextUnderline, "input-text-underline", false, "")
rootCmd.Flags().BoolVar(&flagInputTextFaint, "input-text-faint", false, "")

rootCmd.Flags().StringVar(&flagCursorFg, "cursor-fg", mainColor, "")
rootCmd.Flags().StringVar(&flagCursorBg, "cursor-bg", "", "")
rootCmd.Flags().BoolVar(&flagCursorBold, "cursor-bold", false, "")
Expand Down
14 changes: 14 additions & 0 deletions docs/cli/README.ja.md
Expand Up @@ -55,6 +55,7 @@ $ go install github.com/koki-develop/go-fzf/cmd/gofzf@latest

- [プロンプト](#プロンプト)
- [インプットのプレースホルダ](#インプットのプレースホルダ)
- [インプットのテキスト](#インプットのテキスト)
- [カーソル](#カーソル)
- [カーソル行](#カーソル行)
- [選択中 / 未選択アイテムの接頭辞](#選択中--未選択アイテムの接頭辞)
Expand Down Expand Up @@ -88,6 +89,19 @@ $ go install github.com/koki-develop/go-fzf/cmd/gofzf@latest
| `--input-placeholder-underline` | `false` | インプットのプレースホルダに下線を引く。 |
| `--input-placeholder-faint` | `true` | インプットのプレースホルダを薄く表示する。 |

#### インプットのテキスト

| フラグ | デフォルト | 説明 |
| ------------------------------- | ---------- | ------------------------------------------ |
| `--input-placeholder-fg` | N/A | インプットのテキストの文字色。 |
| `--input-placeholder-bg` | N/A | インプットのテキストの背景色。 |
| `--input-placeholder-bold` | `false` | インプットのテキストを太字にする。 |
| `--input-placeholder-blink` | `false` | インプットのテキストを点滅させる。 |
| `--input-placeholder-italic` | `false` | インプットのテキストをイタリック体にする。 |
| `--input-placeholder-strike` | `false` | インプットのテキストに取り消し線を引く。 |
| `--input-placeholder-underline` | `false` | インプットのテキストに下線を引く。 |
| `--input-placeholder-faint` | `false` | インプットのテキストを薄く表示する。 |

#### カーソル

| フラグ | デフォルト | 説明 |
Expand Down
14 changes: 14 additions & 0 deletions docs/cli/README.md
Expand Up @@ -55,6 +55,7 @@ The `gofzf` CLI allows for various visual customizations using flags.

- [Prompt](#prompt)
- [Placeholder for input](#placeholder-for-input)
- [Input text](#input-text)
- [Cursor](#cursor)
- [Cursor Line](#cursor-line)
- [Prefix of selected/unselected items](#prefix-of-selectedunselected-items)
Expand Down Expand Up @@ -88,6 +89,19 @@ The `gofzf` CLI allows for various visual customizations using flags.
| `--input-placeholder-underline` | `false` | Underline placeholder for input. |
| `--input-placeholder-faint` | `true` | Faint placeholder for input. |

#### Input text

| Flag | Default | Description |
| ------------------------ | ------- | ------------------------------- |
| `--input-text-fg` | N/A | Foreground color of input text. |
| `--input-text-bg` | N/A | Background color of input text. |
| `--input-text-bold` | `false` | Bold input text. |
| `--input-text-blink` | `false` | Blink input text. |
| `--input-text-italic` | `false` | Italicize input text. |
| `--input-text-strike` | `false` | Strkethrough input text. |
| `--input-text-underline` | `false` | Underline input text. |
| `--input-text-faint` | `false` | Faint input text. |

#### Cursor

| Flag | Default | Description |
Expand Down
1 change: 1 addition & 0 deletions docs/library/README.ja.md
Expand Up @@ -246,6 +246,7 @@ f, err := fzf.New(
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: true}), // プロンプト
fzf.WithStyleInputPlaceholder(fzf.Style{Faint: true, ForegroundColor: "#ff0000"}), // インプットのプレースホルダ
fzf.WithStyleInputText(fzf.Style{Italic: true}), // インプットのテキスト
fzf.WithStyleCursor(fzf.Style{Bold: true}), // カーソル
fzf.WithStyleCursorLine(fzf.Style{Bold: true}), // カーソル行
fzf.WithStyleMatches(fzf.Style{ForegroundColor: "#ff0000"}), // 一致文字
Expand Down
1 change: 1 addition & 0 deletions docs/library/README.md
Expand Up @@ -248,6 +248,7 @@ f, err := fzf.New(
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: true}), // Prompt
fzf.WithStyleInputPlaceholder(fzf.Style{Faint: true, ForegroundColor: "#ff0000"}), // Placeholder for input
fzf.WithStyleInputText(fzf.Style{Italic: true}), // Input text
fzf.WithStyleCursor(fzf.Style{Bold: true}), // Cursor
fzf.WithStyleCursorLine(fzf.Style{Bold: true}), // Cursor line
fzf.WithStyleMatches(fzf.Style{ForegroundColor: "#ff0000"}), // Matched characters
Expand Down
1 change: 1 addition & 0 deletions examples/styles/main.go
Expand Up @@ -15,6 +15,7 @@ func main() {
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: true}), // Prompt
fzf.WithStyleInputPlaceholder(fzf.Style{Faint: true, ForegroundColor: "#ff0000"}), // Placeholder for input
fzf.WithStyleInputText(fzf.Style{Italic: true}), // Input text
fzf.WithStyleCursor(fzf.Style{Bold: true}), // Cursor
fzf.WithStyleCursorLine(fzf.Style{Bold: true}), // Cursor line
fzf.WithStyleMatches(fzf.Style{ForegroundColor: "#ff0000"}), // Matched characters
Expand Down
1 change: 1 addition & 0 deletions model.go
Expand Up @@ -54,6 +54,7 @@ func newModel(opt *option) *model {
input.PromptStyle = opt.styles.option.prompt
input.Placeholder = opt.inputPlaceholder
input.PlaceholderStyle = opt.styles.option.inputPlaceholder
input.TextStyle = opt.styles.option.inputText
input.Focus()

if !opt.multiple() {
Expand Down
11 changes: 10 additions & 1 deletion styles.go
Expand Up @@ -7,6 +7,7 @@ var (
defaultStylesOption = stylesOption{
prompt: lipgloss.NewStyle(),
inputPlaceholder: lipgloss.NewStyle().Faint(true),
inputText: lipgloss.NewStyle(),
cursor: lipgloss.NewStyle().Foreground(lipgloss.Color(defaultColor)),
cursorLine: lipgloss.NewStyle().Bold(true),
matches: lipgloss.NewStyle().Foreground(lipgloss.Color(defaultColor)),
Expand Down Expand Up @@ -69,6 +70,7 @@ type StylesOption func(o *stylesOption)
type stylesOption struct {
prompt lipgloss.Style
inputPlaceholder lipgloss.Style
inputText lipgloss.Style
cursor lipgloss.Style
cursorLine lipgloss.Style
selectedPrefix lipgloss.Style
Expand All @@ -92,13 +94,20 @@ func WithStylePrompt(s Style) StylesOption {
}
}

// WithInputPlaceholder sets the placeholder for input.
// WithInputPlaceholder sets the style of placeholder for input.
func WithStyleInputPlaceholder(s Style) StylesOption {
return func(o *stylesOption) {
o.inputPlaceholder = s.lipgloss()
}
}

// WithStyleInputText sets the style of input text.
func WithStyleInputText(s Style) StylesOption {
return func(o *stylesOption) {
o.inputText = s.lipgloss()
}
}

// WithStyleCursor sets the style of cursor.
func WithStyleCursor(s Style) StylesOption {
return func(o *stylesOption) {
Expand Down

0 comments on commit eed084e

Please sign in to comment.