diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-17 12:51:51 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-17 13:12:51 +0900 |
| commit | 0d5aebb806f3efef317bf49349100509eb1de67b (patch) | |
| tree | 1320a53a67ac41667acf94802c938213295b63f2 /src/options.go | |
| parent | 13135108906fce00dab5a403bf308e19382e630e (diff) | |
| download | fzf-0d5aebb806f3efef317bf49349100509eb1de67b.tar.gz | |
Allow setting border styles at once with --style full:STYLE
Diffstat (limited to 'src/options.go')
| -rw-r--r-- | src/options.go | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/options.go b/src/options.go index 3dc5d2a6..9042b6d7 100644 --- a/src/options.go +++ b/src/options.go @@ -56,7 +56,7 @@ Usage: fzf [options] --sync Synchronous search for multi-staged filtering GLOBAL STYLE - --style=PRESET Apply a style preset [default|minimal|full] + --style=PRESET Apply a style preset [default|minimal|full[:BORDER_STYLE] --color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors --no-color Disable colors --no-bold Do not use bold text @@ -214,6 +214,9 @@ Usage: fzf [options] ` +// Can be changed by --style +var defaultBorderShape tui.BorderShape = tui.DefaultBorderShape + const defaultInfoPrefix = " < " // Case denotes case-sensitivity of search @@ -628,7 +631,7 @@ func filterNonEmpty(input []string) []string { } func defaultPreviewOpts(command string) previewOpts { - return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, true, tui.DefaultBorderShape, 0, 0, nil} + return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, true, defaultBorderShape, 0, 0, nil} } func defaultOptions() *Options { @@ -842,7 +845,7 @@ func parseBorder(str string, optional bool, allowLine bool) (tui.BorderShape, er return tui.BorderNone, nil } if optional && str == "" { - return tui.DefaultBorderShape, nil + return defaultBorderShape, nil } return tui.BorderNone, errors.New("invalid border style (expected: rounded|sharp|bold|block|thinblock|double|horizontal|vertical|top|bottom|left|right|none)") } @@ -2729,7 +2732,7 @@ func parseOptions(index *int, opts *Options, allArgs []string) error { return err } case "--style": - preset, err := nextString("preset name required: [default|minimal|full]") + preset, err := nextString("preset name required: [default|minimal|full[:BORDER_STYLE]]") if err != nil { return err } @@ -2882,12 +2885,15 @@ func parseOptions(index *int, opts *Options, allArgs []string) error { } func applyPreset(opts *Options, preset string) error { + // Reset to the platform default + defaultBorderShape = tui.DefaultBorderShape + 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.border = defaultBorderShape opts.Preview.info = true opts.InfoStyle = infoDefault opts.Theme.Gutter = tui.NewColorAttr() @@ -2906,19 +2912,29 @@ func applyPreset(opts *Options, preset string) error { 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 + default: + tokens := strings.SplitN(preset, ":", 2) + if tokens[0] != "full" { + return errors.New("unsupported style preset: " + preset) + } + if len(tokens) == 2 && len(tokens[1]) > 0 { + var err error + defaultBorderShape, err = parseBorder(tokens[1], false, false) + if err != nil { + return err + } + } + + opts.ListBorderShape = defaultBorderShape + opts.InputBorderShape = defaultBorderShape + opts.HeaderBorderShape = defaultBorderShape + opts.Preview.border = 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 } |
