Skip to content

Commit

Permalink
Add style presets: --style=[default|minimal|full]
Browse files Browse the repository at this point in the history
Close #4160
  • Loading branch information
junegunn committed Jan 5, 2025
1 parent 0e0b868 commit 5ae60e2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ CHANGELOG

0.58.0
------
- Border and label for the list section

This version introduces three new border types, `--list-border`, `--input-border`, and `--header-border`, offering much greater flexibility for customizing the user interface.

Also, fzf now offers three "style presets" for easier customization, which can be activated using the `--style=[default|minimal|full]` option.

- Style presets (#4160)
- `--style=full`
- `--style=default`
- `--style=minimal`
- Border and label for the list section (#4148)
- Options
- `--list-border[=STYLE]`
- `--list-label=LABEL`
Expand All @@ -16,7 +25,7 @@ CHANGELOG
- Actions
- `change-list-label`
- `transform-list-label`
- Border and label for the input section (prompt line and info line)
- Border and label for the input section (prompt line and info line) (#4154)
- Options
- `--input-border[=STYLE]`
- `--input-label=LABEL`
Expand All @@ -29,7 +38,7 @@ CHANGELOG
- Actions
- `change-input-label`
- `transform-input-label`
- Border and label for the header section
- Border and label for the header section (#4159)
- Options
- `--header-border[=STYLE]`
- `--header-label=LABEL`
Expand Down
55 changes: 55 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Usage: fzf [options]
--jump-labels=CHARS Label characters for jump mode
Layout
--style=PRESET Apply a style preset [default|minimal|full]
--height=[~]HEIGHT[%] Display fzf window below the cursor with the given
height instead of using fullscreen.
A negative value is calculated as the terminal height
Expand Down Expand Up @@ -2646,6 +2647,14 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
if err := parseLabelPosition(&opts.PreviewLabel, pos); err != nil {
return err
}
case "--style":
preset, err := nextString(allArgs, &i, "preset name required: [default|minimal|full]")
if err != nil {
return err
}
if err := applyPreset(opts, preset); err != nil {
return err
}
case "--no-unicode":
opts.Unicode = false
case "--unicode":
Expand Down Expand Up @@ -2742,6 +2751,10 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
if opts.Tmux, err = parseTmuxOptions(value, index); err != nil {
return err
}
} else if match, value := optString(arg, "--style="); match {
if err := applyPreset(opts, value); err != nil {
return err
}
} else if match, value := optString(arg, "--scheme="); match {
opts.Scheme = strings.ToLower(value)
} else if match, value := optString(arg, "-q", "--query="); match {
Expand Down Expand Up @@ -2990,6 +3003,48 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
return err
}

func applyPreset(opts *Options, preset string) error {
switch strings.ToLower(preset) {
case "default":
opts.ListBorderShape = tui.BorderUndefined
opts.InputBorderShape = tui.BorderUndefined
opts.HeaderBorderShape = tui.BorderUndefined
opts.Preview.border = tui.DefaultBorderShape
opts.Preview.info = true
opts.InfoStyle = infoDefault
opts.Theme.Gutter = tui.NewColorAttr()
opts.Separator = nil
opts.Scrollbar = nil
opts.CursorLine = false
case "minimal":
opts.ListBorderShape = tui.BorderUndefined
opts.InputBorderShape = tui.BorderUndefined
opts.HeaderBorderShape = tui.BorderUndefined
opts.Preview.border = tui.BorderLine
opts.Preview.info = false
opts.InfoStyle = infoDefault
opts.Theme.Gutter = tui.ColorAttr{Color: -1, Attr: 0}
empty := ""
opts.Separator = &empty
opts.Scrollbar = &empty
opts.CursorLine = false
case "full":
opts.ListBorderShape = tui.DefaultBorderShape
opts.InputBorderShape = tui.DefaultBorderShape
opts.HeaderBorderShape = tui.DefaultBorderShape
opts.Preview.border = tui.DefaultBorderShape
opts.Preview.info = true
opts.InfoStyle = infoInlineRight
opts.Theme.Gutter = tui.NewColorAttr()
opts.Separator = nil
opts.Scrollbar = nil
opts.CursorLine = true
default:
return errors.New("unsupported style preset: " + preset)
}
return nil
}

func validateSign(sign string, signOptName string) error {
if uniseg.StringWidth(sign) > 2 {
return fmt.Errorf("%v display width should be up to 2", signOptName)
Expand Down

0 comments on commit 5ae60e2

Please sign in to comment.