Add --inline-info option

Close #202
pull/165/merge
Junegunn Choi 9 years ago
parent 9f64a00549
commit 651a8f8cc2

@ -116,6 +116,9 @@ Reverse orientation
.B "--no-hscroll" .B "--no-hscroll"
Disable horizontal scroll Disable horizontal scroll
.TP .TP
.B "--inline-info"
Display finder info inline with the query
.TP
.BI "--prompt=" "STR" .BI "--prompt=" "STR"
Input prompt (default: '> ') Input prompt (default: '> ')
.SS Scripting .SS Scripting

@ -40,6 +40,7 @@ const usage = `usage: fzf [options]
--black Use black background --black Use black background
--reverse Reverse orientation --reverse Reverse orientation
--no-hscroll Disable horizontal scroll --no-hscroll Disable horizontal scroll
--inline-info Display finder info inline with the query
--prompt=STR Input prompt (default: '> ') --prompt=STR Input prompt (default: '> ')
Scripting Scripting
@ -105,6 +106,7 @@ type Options struct {
Black bool Black bool
Reverse bool Reverse bool
Hscroll bool Hscroll bool
InlineInfo bool
Prompt string Prompt string
Query string Query string
Select1 bool Select1 bool
@ -141,6 +143,7 @@ func defaultOptions() *Options {
Black: false, Black: false,
Reverse: false, Reverse: false,
Hscroll: true, Hscroll: true,
InlineInfo: false,
Prompt: "> ", Prompt: "> ",
Query: "", Query: "",
Select1: false, Select1: false,
@ -364,6 +367,10 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Hscroll = true opts.Hscroll = true
case "--no-hscroll": case "--no-hscroll":
opts.Hscroll = false opts.Hscroll = false
case "--inline-info":
opts.InlineInfo = true
case "--no-inline-info":
opts.InlineInfo = 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":

@ -20,6 +20,7 @@ import (
// Terminal represents terminal input/output // Terminal represents terminal input/output
type Terminal struct { type Terminal struct {
inlineInfo bool
prompt string prompt string
reverse bool reverse bool
hscroll bool hscroll bool
@ -83,6 +84,7 @@ const (
func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
input := []rune(opts.Query) input := []rune(opts.Query)
return &Terminal{ return &Terminal{
inlineInfo: opts.InlineInfo,
prompt: opts.Prompt, prompt: opts.Prompt,
reverse: opts.Reverse, reverse: opts.Reverse,
hscroll: opts.Hscroll, hscroll: opts.Hscroll,
@ -229,14 +231,23 @@ func (t *Terminal) printPrompt() {
} }
func (t *Terminal) printInfo() { func (t *Terminal) printInfo() {
t.move(1, 0, true) if t.inlineInfo {
if t.reading { t.move(0, len(t.prompt)+displayWidth(t.input)+1, true)
duration := int64(spinnerDuration) if t.reading {
idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration C.CPrint(C.ColSpinner, true, " < ")
C.CPrint(C.ColSpinner, true, _spinner[idx]) } else {
C.CPrint(C.ColPrompt, true, " < ")
}
} else {
t.move(1, 0, true)
if t.reading {
duration := int64(spinnerDuration)
idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration
C.CPrint(C.ColSpinner, true, _spinner[idx])
}
t.move(1, 2, false)
} }
t.move(1, 2, false)
output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count) output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count)
if t.toggleSort > 0 { if t.toggleSort > 0 {
if t.sort { if t.sort {
@ -257,10 +268,16 @@ func (t *Terminal) printInfo() {
func (t *Terminal) printList() { func (t *Terminal) printList() {
t.constrain() t.constrain()
maxy := maxItems() maxy := t.maxItems()
count := t.merger.Length() - t.offset count := t.merger.Length() - t.offset
for i := 0; i < maxy; i++ { for i := 0; i < maxy; i++ {
t.move(i+2, 0, true) var line int
if t.inlineInfo {
line = i + 1
} else {
line = i + 2
}
t.move(line, 0, true)
if i < count { if i < count {
t.printItem(t.merger.Get(i+t.offset), i == t.cy-t.offset) t.printItem(t.merger.Get(i+t.offset), i == t.cy-t.offset)
} }
@ -515,6 +532,9 @@ func (t *Terminal) Loop() {
switch req { switch req {
case reqPrompt: case reqPrompt:
t.printPrompt() t.printPrompt()
if t.inlineInfo {
t.printInfo()
}
case reqInfo: case reqInfo:
t.printInfo() t.printInfo()
case reqList: case reqList:
@ -659,10 +679,10 @@ func (t *Terminal) Loop() {
case C.Del: case C.Del:
t.delChar() t.delChar()
case C.PgUp: case C.PgUp:
t.vmove(maxItems() - 1) t.vmove(t.maxItems() - 1)
req(reqList) req(reqList)
case C.PgDn: case C.PgDn:
t.vmove(-(maxItems() - 1)) t.vmove(-(t.maxItems() - 1))
req(reqList) req(reqList)
case C.AltB: case C.AltB:
t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1 t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
@ -685,6 +705,10 @@ func (t *Terminal) Loop() {
if !t.reverse { if !t.reverse {
my = C.MaxY() - my - 1 my = C.MaxY() - my - 1
} }
min := 2
if t.inlineInfo {
min = 1
}
if me.S != 0 { if me.S != 0 {
// Scroll // Scroll
if t.merger.Length() > 0 { if t.merger.Length() > 0 {
@ -696,8 +720,8 @@ func (t *Terminal) Loop() {
} }
} else if me.Double { } else if me.Double {
// Double-click // Double-click
if my >= 2 { if my >= min {
if t.vset(t.offset+my-2) && t.cy < t.merger.Length() { if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
req(reqClose) req(reqClose)
} }
} }
@ -705,9 +729,9 @@ func (t *Terminal) Loop() {
if my == 0 && mx >= 0 { if my == 0 && mx >= 0 {
// Prompt // Prompt
t.cx = mx t.cx = mx
} else if my >= 2 { } else if my >= min {
// List // List
if t.vset(t.offset+my-2) && t.multi && me.Mod { if t.vset(t.offset+my-min) && t.multi && me.Mod {
toggle() toggle()
} }
req(reqList) req(reqList)
@ -728,7 +752,7 @@ func (t *Terminal) Loop() {
func (t *Terminal) constrain() { func (t *Terminal) constrain() {
count := t.merger.Length() count := t.merger.Length()
height := C.MaxY() - 2 height := t.maxItems()
diffpos := t.cy - t.offset diffpos := t.cy - t.offset
t.cy = util.Constrain(t.cy, 0, count-1) t.cy = util.Constrain(t.cy, 0, count-1)
@ -761,6 +785,10 @@ func (t *Terminal) vset(o int) bool {
return t.cy == o return t.cy == o
} }
func maxItems() int { func (t *Terminal) maxItems() int {
return C.MaxY() - 2 if t.inlineInfo {
return C.MaxY() - 1
} else {
return C.MaxY() - 2
}
} }

Loading…
Cancel
Save