Add more --border options; default changed to "rounded"

--border option now takes an optional argument that defines the style

  - rounded (new default)
  - sharp
  - horizontal (previous default)
This commit is contained in:
Junegunn Choi
2020-03-05 20:15:15 +09:00
parent 99f1e02766
commit d9b1211191
6 changed files with 150 additions and 90 deletions

View File

@@ -57,7 +57,8 @@ const usage = `usage: fzf [options]
--min-height=HEIGHT Minimum height when --height is given in percent
(default: 10)
--layout=LAYOUT Choose layout: [default|reverse|reverse-list]
--border Draw border above and below the finder
--border[=STYLE] Draw border around the finder
[rounded|sharp|horizontal] (default: rounded)
--margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)
--info=STYLE Finder info style [default|inline|hidden]
--prompt=STR Input prompt (default: '> ')
@@ -212,7 +213,7 @@ type Options struct {
Header []string
HeaderLines int
Margin [4]sizeSpec
Bordered bool
BorderShape tui.BorderShape
Unicode bool
Tabstop int
ClearOnExit bool
@@ -301,12 +302,12 @@ func nextString(args []string, i *int, message string) string {
return args[*i]
}
func optionalNextString(args []string, i *int) string {
if len(args) > *i+1 && !strings.HasPrefix(args[*i+1], "-") {
func optionalNextString(args []string, i *int) (bool, string) {
if len(args) > *i+1 && !strings.HasPrefix(args[*i+1], "-") && !strings.HasPrefix(args[*i+1], "+") {
*i++
return args[*i]
return true, args[*i]
}
return ""
return false, ""
}
func atoi(str string) int {
@@ -400,6 +401,23 @@ func parseAlgo(str string) algo.Algo {
return algo.FuzzyMatchV2
}
func parseBorder(str string, optional bool) tui.BorderShape {
switch str {
case "rounded":
return tui.BorderRounded
case "sharp":
return tui.BorderSharp
case "horizontal":
return tui.BorderHorizontal
default:
if optional && str == "" {
return tui.BorderRounded
}
errorExit("invalid border style (expected: rounded|sharp|horizontal)")
}
return tui.BorderNone
}
func parseKeyChords(str string, message string) map[int]string {
if len(str) == 0 {
errorExit(message)
@@ -1098,7 +1116,7 @@ func parseOptions(opts *Options, allArgs []string) {
case "--bind":
parseKeymap(opts.Keymap, nextString(allArgs, &i, "bind expression required"))
case "--color":
spec := optionalNextString(allArgs, &i)
_, spec := optionalNextString(allArgs, &i)
if len(spec) == 0 {
opts.Theme = tui.EmptyTheme()
} else {
@@ -1246,9 +1264,10 @@ func parseOptions(opts *Options, allArgs []string) {
case "--no-margin":
opts.Margin = defaultMargin()
case "--no-border":
opts.Bordered = false
opts.BorderShape = tui.BorderNone
case "--border":
opts.Bordered = true
hasArg, arg := optionalNextString(allArgs, &i)
opts.BorderShape = parseBorder(arg, !hasArg)
case "--no-unicode":
opts.Unicode = false
case "--unicode":
@@ -1273,6 +1292,8 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Filter = &value
} else if match, value := optString(arg, "-d", "--delimiter="); match {
opts.Delimiter = delimiterRegexp(value)
} else if match, value := optString(arg, "--border="); match {
opts.BorderShape = parseBorder(value, false)
} else if match, value := optString(arg, "--prompt="); match {
opts.Prompt = value
} else if match, value := optString(arg, "--pointer="); match {