Skip to content

Commit

Permalink
Merge pull request #30 from koki-develop/custom-prompt-style
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed Mar 31, 2023
2 parents 5b9f21b + 53a8d9b commit 0660066
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
28 changes: 28 additions & 0 deletions cmd/gofzf/main.go
Expand Up @@ -36,6 +36,15 @@ var (

flagCountView bool

flagPromptFg string
flagPromptBg string
flagPromptBold bool
flagPromptBlink bool
flagPromptItalic bool
flagPromptStrikethrough bool
flagPromptUnderline bool
flagPromptFaint bool

flagCursorFg string
flagCursorBg string
flagCursorBold bool
Expand Down Expand Up @@ -105,6 +114,16 @@ var rootCmd = &cobra.Command{
fzf.WithCountViewEnabled(flagCountView),

fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{
ForegroundColor: flagPromptFg,
BackgroundColor: flagPromptBg,
Bold: flagPromptBold,
Blink: flagPromptBlink,
Italic: flagPromptItalic,
Strikethrough: flagPromptStrikethrough,
Underline: flagPromptUnderline,
Faint: flagPromptFaint,
}),
fzf.WithStyleCursor(fzf.Style{
ForegroundColor: flagCursorFg,
BackgroundColor: flagCursorBg,
Expand Down Expand Up @@ -285,6 +304,15 @@ func init() {

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

rootCmd.Flags().StringVar(&flagPromptFg, "prompt-fg", "", "")
rootCmd.Flags().StringVar(&flagPromptBg, "prompt-bg", "", "")
rootCmd.Flags().BoolVar(&flagPromptBold, "prompt-bold", false, "")
rootCmd.Flags().BoolVar(&flagPromptBlink, "prompt-blink", false, "")
rootCmd.Flags().BoolVar(&flagPromptItalic, "prompt-italic", false, "")
rootCmd.Flags().BoolVar(&flagPromptStrikethrough, "prompt-strike", false, "")
rootCmd.Flags().BoolVar(&flagPromptUnderline, "prompt-underline", false, "")
rootCmd.Flags().BoolVar(&flagPromptFaint, "prompt-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: 11 additions & 3 deletions docs/cli/README.md
Expand Up @@ -62,9 +62,17 @@ The `gofzf` CLI allows for various visual customizations using flags.

#### Prompt

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

#### Cursor

Expand Down
1 change: 1 addition & 0 deletions docs/library/README.ja.md
Expand Up @@ -244,6 +244,7 @@ if err != nil {
f, err := fzf.New(
fzf.WithNoLimit(true),
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: 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 @@ -246,6 +246,7 @@ See [reference](https://pkg.go.dev/github.com/koki-develop/go-fzf#Style) for ava
f, err := fzf.New(
fzf.WithNoLimit(true),
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: true}), // Prompt
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 @@ -13,6 +13,7 @@ func main() {
f, err := fzf.New(
fzf.WithNoLimit(true),
fzf.WithStyles(
fzf.WithStylePrompt(fzf.Style{Faint: true}), // Prompt
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 @@ -51,6 +51,7 @@ type model struct {
func newModel(opt *option) *model {
input := textinput.New()
input.Prompt = opt.prompt
input.PromptStyle = opt.styles.option.prompt
input.Placeholder = opt.inputPlaceholder
input.Focus()

Expand Down
9 changes: 9 additions & 0 deletions styles.go
Expand Up @@ -5,6 +5,7 @@ import "github.com/charmbracelet/lipgloss"
var (
defaultColor = "#00ADD8"
defaultStylesOption = stylesOption{
prompt: 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 @@ -65,6 +66,7 @@ func (s *Style) lipgloss() lipgloss.Style {
type StylesOption func(o *stylesOption)

type stylesOption struct {
prompt lipgloss.Style
cursor lipgloss.Style
cursorLine lipgloss.Style
selectedPrefix lipgloss.Style
Expand All @@ -81,6 +83,13 @@ func NewStyles(opts ...StylesOption) *Styles {
return &Styles{option: &o}
}

// WithStylePrompt sets the style of prompt.
func WithStylePrompt(s Style) StylesOption {
return func(o *stylesOption) {
o.prompt = s.lipgloss()
}
}

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

0 comments on commit 0660066

Please sign in to comment.