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