mirror of
https://github.com/junegunn/fzf.git
synced 2026-01-16 16:17:32 +08:00
Style change: thinner gutter column (#4521)
This commit is contained in:
@@ -590,6 +590,7 @@ type Options struct {
|
||||
Separator *string
|
||||
JumpLabels string
|
||||
Prompt string
|
||||
Gutter *string
|
||||
Pointer *string
|
||||
Marker *string
|
||||
MarkerMulti *[3]string
|
||||
@@ -710,6 +711,7 @@ func defaultOptions() *Options {
|
||||
Separator: nil,
|
||||
JumpLabels: defaultJumpLabels,
|
||||
Prompt: "> ",
|
||||
Gutter: nil,
|
||||
Pointer: nil,
|
||||
Marker: nil,
|
||||
MarkerMulti: nil,
|
||||
@@ -2857,6 +2859,13 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "--gutter":
|
||||
str, err := nextString("gutter character required")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
str = firstLine(str)
|
||||
opts.Gutter = &str
|
||||
case "--pointer":
|
||||
str, err := nextString("pointer sign required")
|
||||
if err != nil {
|
||||
@@ -3355,22 +3364,28 @@ func applyPreset(opts *Options, preset string) error {
|
||||
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)
|
||||
func validateSign(sign string, signOptName string, maxWidth int) error {
|
||||
if uniseg.StringWidth(sign) > maxWidth {
|
||||
return fmt.Errorf("%v display width should be up to %d", signOptName, maxWidth)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateOptions(opts *Options) error {
|
||||
if opts.Pointer != nil {
|
||||
if err := validateSign(*opts.Pointer, "pointer"); err != nil {
|
||||
if err := validateSign(*opts.Pointer, "pointer", 2); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Marker != nil {
|
||||
if err := validateSign(*opts.Marker, "marker"); err != nil {
|
||||
if err := validateSign(*opts.Marker, "marker", 2); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Gutter != nil {
|
||||
if err := validateSign(*opts.Gutter, "gutter", 1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ func TestValidateSign(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
err := validateSign(testCase.inputSign, "")
|
||||
err := validateSign(testCase.inputSign, "", 2)
|
||||
if testCase.isValid && err != nil {
|
||||
t.Errorf("Input sign `%s` caused error", testCase.inputSign)
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ type Terminal struct {
|
||||
footerLabel labelPrinter
|
||||
footerLabelLen int
|
||||
footerLabelOpts labelOpts
|
||||
gutterReverse bool
|
||||
pointer string
|
||||
pointerLen int
|
||||
pointerEmpty string
|
||||
@@ -1094,10 +1095,27 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
|
||||
// This should be called before accessing tui.Color*
|
||||
tui.InitTheme(opts.Theme, renderer.DefaultTheme(), opts.Black, opts.InputBorderShape.Visible(), opts.HeaderBorderShape.Visible())
|
||||
|
||||
// Gutter character
|
||||
var gutterChar string
|
||||
if opts.Gutter != nil {
|
||||
gutterChar = *opts.Gutter
|
||||
} else if t.unicode && !t.theme.Gutter.Color.IsDefault() {
|
||||
gutterChar = "▌"
|
||||
} else {
|
||||
gutterChar = " "
|
||||
t.gutterReverse = true
|
||||
}
|
||||
|
||||
t.prompt, t.promptLen = t.parsePrompt(opts.Prompt)
|
||||
// Pre-calculated empty pointer and marker signs
|
||||
t.pointerEmpty = strings.Repeat(" ", t.pointerLen)
|
||||
if t.pointerLen == 0 {
|
||||
t.pointerEmpty = ""
|
||||
} else {
|
||||
t.pointerEmpty = gutterChar + strings.Repeat(" ", util.Max(0, t.pointerLen-1))
|
||||
}
|
||||
t.markerEmpty = strings.Repeat(" ", t.markerLen)
|
||||
|
||||
// Labels
|
||||
t.listLabel, t.listLabelLen = t.ansiLabelPrinter(opts.ListLabel.label, &tui.ColListLabel, false)
|
||||
t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(opts.BorderLabel.label, &tui.ColBorderLabel, false)
|
||||
t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(opts.PreviewLabel.label, &tui.ColPreviewLabel, false)
|
||||
@@ -3096,9 +3114,21 @@ func (t *Terminal) renderEmptyLine(line int, barRange [2]int) {
|
||||
t.renderBar(line, barRange)
|
||||
}
|
||||
|
||||
func (t *Terminal) gutter(current bool) {
|
||||
var color tui.ColorPair
|
||||
if current {
|
||||
color = tui.ColCurrentCursorEmpty
|
||||
} else if t.gutterReverse {
|
||||
color = tui.ColCursorEmpty
|
||||
} else {
|
||||
color = tui.ColCursorEmptyChar
|
||||
}
|
||||
t.window.CPrint(color, t.pointerEmpty)
|
||||
}
|
||||
|
||||
func (t *Terminal) renderGapLine(line int, barRange [2]int, drawLine bool) {
|
||||
t.move(line, 0, false)
|
||||
t.window.CPrint(tui.ColCursorEmpty, t.pointerEmpty)
|
||||
t.gutter(false)
|
||||
t.window.Print(t.markerEmpty)
|
||||
x := t.pointerLen + t.markerLen
|
||||
|
||||
@@ -3262,7 +3292,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
|
||||
return indentSize
|
||||
}
|
||||
if len(label) == 0 {
|
||||
t.window.CPrint(tui.ColCurrentCursorEmpty, t.pointerEmpty)
|
||||
t.gutter(true)
|
||||
} else {
|
||||
t.window.CPrint(tui.ColCurrentCursor, label)
|
||||
}
|
||||
@@ -3284,7 +3314,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
|
||||
return indentSize
|
||||
}
|
||||
if len(label) == 0 {
|
||||
t.window.CPrint(tui.ColCursorEmpty, t.pointerEmpty)
|
||||
t.gutter(false)
|
||||
} else {
|
||||
t.window.CPrint(tui.ColCursor, label)
|
||||
}
|
||||
|
||||
@@ -776,6 +776,7 @@ var (
|
||||
ColMatch ColorPair
|
||||
ColCursor ColorPair
|
||||
ColCursorEmpty ColorPair
|
||||
ColCursorEmptyChar ColorPair
|
||||
ColMarker ColorPair
|
||||
ColSelected ColorPair
|
||||
ColSelectedMatch ColorPair
|
||||
@@ -1168,10 +1169,11 @@ func initPalette(theme *ColorTheme) {
|
||||
ColSelectedMatch = pair(theme.SelectedMatch, theme.SelectedBg)
|
||||
ColCursor = pair(theme.Cursor, theme.Gutter)
|
||||
ColCursorEmpty = pair(blank, theme.Gutter)
|
||||
ColCursorEmptyChar = pair(theme.Gutter, theme.ListBg)
|
||||
if theme.SelectedBg.Color != theme.ListBg.Color {
|
||||
ColMarker = pair(theme.Marker, theme.SelectedBg)
|
||||
} else {
|
||||
ColMarker = pair(theme.Marker, theme.Gutter)
|
||||
ColMarker = pair(theme.Marker, theme.ListBg)
|
||||
}
|
||||
ColCurrent = pair(theme.Current, theme.DarkBg)
|
||||
ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)
|
||||
|
||||
Reference in New Issue
Block a user