summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-06 02:10:44 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-06 02:10:44 +0900
commit5ae60e2e806adba1652bec64a62caa473004d7ed (patch)
tree5aa2c889a85d656ccc5a0f77d149534a7637a76e
parent0e0b86834294e1befb9e1ce16239230aa40d1add (diff)
downloadfzf-5ae60e2e806adba1652bec64a62caa473004d7ed.tar.gz
Add style presets: --style=[default|minimal|full]
Close #4160
-rw-r--r--CHANGELOG.md15
-rw-r--r--src/options.go55
2 files changed, 67 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e0b8e66e..e6cf9ef8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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`
@@ -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`
@@ -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`
diff --git a/src/options.go b/src/options.go
index 7db7418b..2b1425fc 100644
--- a/src/options.go
+++ b/src/options.go
@@ -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
@@ -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":
@@ -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 {
@@ -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)