mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 03:19:01 +00:00
parent
3e1e75fe08
commit
48ab87294b
@ -89,6 +89,9 @@ Use black background
|
||||
.B "--reverse"
|
||||
Reverse orientation
|
||||
.TP
|
||||
.B "--no-hscroll"
|
||||
Disable horizontal scroll
|
||||
.TP
|
||||
.BI "--prompt=" "STR"
|
||||
Input prompt (default: '> ')
|
||||
.SS Scripting
|
||||
|
@ -38,6 +38,7 @@ const usage = `usage: fzf [options]
|
||||
+2, --no-256 Disable 256-color
|
||||
--black Use black background
|
||||
--reverse Reverse orientation
|
||||
--no-hscroll Disable horizontal scroll
|
||||
--prompt=STR Input prompt (default: '> ')
|
||||
|
||||
Scripting
|
||||
@ -93,6 +94,7 @@ type Options struct {
|
||||
Color256 bool
|
||||
Black bool
|
||||
Reverse bool
|
||||
Hscroll bool
|
||||
Prompt string
|
||||
Query string
|
||||
Select1 bool
|
||||
@ -121,6 +123,7 @@ func defaultOptions() *Options {
|
||||
Color256: strings.Contains(os.Getenv("TERM"), "256"),
|
||||
Black: false,
|
||||
Reverse: false,
|
||||
Hscroll: true,
|
||||
Prompt: "> ",
|
||||
Query: "",
|
||||
Select1: false,
|
||||
@ -304,6 +307,10 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
opts.Reverse = true
|
||||
case "--no-reverse":
|
||||
opts.Reverse = false
|
||||
case "--hscroll":
|
||||
opts.Hscroll = true
|
||||
case "--no-hscroll":
|
||||
opts.Hscroll = false
|
||||
case "-1", "--select-1":
|
||||
opts.Select1 = true
|
||||
case "+1", "--no-select-1":
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
type Terminal struct {
|
||||
prompt string
|
||||
reverse bool
|
||||
hscroll bool
|
||||
cx int
|
||||
cy int
|
||||
offset int
|
||||
@ -88,6 +89,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
return &Terminal{
|
||||
prompt: opts.Prompt,
|
||||
reverse: opts.Reverse,
|
||||
hscroll: opts.Hscroll,
|
||||
cx: len(input),
|
||||
cy: 0,
|
||||
offset: 0,
|
||||
@ -318,7 +320,7 @@ func trimLeft(runes []rune, width int) ([]rune, int32) {
|
||||
return runes, trimmed
|
||||
}
|
||||
|
||||
func (*Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
|
||||
func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
|
||||
var maxe int32
|
||||
for _, offset := range item.offsets {
|
||||
if offset[1] > maxe {
|
||||
@ -332,30 +334,40 @@ func (*Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, cur
|
||||
maxWidth := C.MaxX() - 3
|
||||
fullWidth := displayWidth(text)
|
||||
if fullWidth > maxWidth {
|
||||
// Stri..
|
||||
matchEndWidth := displayWidth(text[:maxe])
|
||||
if matchEndWidth <= maxWidth-2 {
|
||||
if t.hscroll {
|
||||
// Stri..
|
||||
matchEndWidth := displayWidth(text[:maxe])
|
||||
if matchEndWidth <= maxWidth-2 {
|
||||
text, _ = trimRight(text, maxWidth-2)
|
||||
text = append(text, []rune("..")...)
|
||||
} else {
|
||||
// Stri..
|
||||
if matchEndWidth < fullWidth-2 {
|
||||
text = append(text[:maxe], []rune("..")...)
|
||||
}
|
||||
// ..ri..
|
||||
var diff int32
|
||||
text, diff = trimLeft(text, maxWidth-2)
|
||||
|
||||
// Transform offsets
|
||||
for idx, offset := range offsets {
|
||||
b, e := offset.offset[0], offset.offset[1]
|
||||
b += 2 - diff
|
||||
e += 2 - diff
|
||||
b = util.Max32(b, 2)
|
||||
offsets[idx].offset[0] = b
|
||||
offsets[idx].offset[1] = util.Max32(b, e)
|
||||
}
|
||||
text = append([]rune(".."), text...)
|
||||
}
|
||||
} else {
|
||||
text, _ = trimRight(text, maxWidth-2)
|
||||
text = append(text, []rune("..")...)
|
||||
} else {
|
||||
// Stri..
|
||||
if matchEndWidth < fullWidth-2 {
|
||||
text = append(text[:maxe], []rune("..")...)
|
||||
}
|
||||
// ..ri..
|
||||
var diff int32
|
||||
text, diff = trimLeft(text, maxWidth-2)
|
||||
|
||||
// Transform offsets
|
||||
for idx, offset := range offsets {
|
||||
b, e := offset.offset[0], offset.offset[1]
|
||||
b += 2 - diff
|
||||
e += 2 - diff
|
||||
b = util.Max32(b, 2)
|
||||
offsets[idx].offset[0] = b
|
||||
offsets[idx].offset[1] = util.Max32(b, e)
|
||||
offsets[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-2))
|
||||
offsets[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))
|
||||
}
|
||||
text = append([]rune(".."), text...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,14 @@ func Max(first int, items ...int) int {
|
||||
return max
|
||||
}
|
||||
|
||||
// Max32 returns the smallest 32-bit integer
|
||||
func Min32(first int32, second int32) int32 {
|
||||
if first <= second {
|
||||
return first
|
||||
}
|
||||
return second
|
||||
}
|
||||
|
||||
// Max32 returns the largest 32-bit integer
|
||||
func Max32(first int32, second int32) int32 {
|
||||
if first > second {
|
||||
|
Loading…
Reference in New Issue
Block a user