Skip to content
Myr

Support ANSI colors in --prompt string

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #2086

authored by Junegunn Choi · committed by Junegunn Choi · parent dda3e3c · Browse files · 2 files+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−3 removed

  • other:+17 added−3 removed

2 files+17 added−3 removed

modified:src/terminal.go+16 added-3 removed
62 unmodified lines
63type Terminal struct {64 initDelay time.Duration65 infoStyle infoStyle66 spinner []string67 prompt string67 prompt func()68 promptLen int69 pointer string70 pointerLen int71 pointerEmpty string
396 unmodified lines
468 startChan: make(chan bool, 1),469 killChan: make(chan int),470 tui: renderer,471 initFunc: func() { renderer.Init() }}472 t.prompt, t.promptLen = t.processTabs([]rune(opts.Prompt), 0)472 t.prompt, t.promptLen = t.parsePrompt(opts.Prompt)473 t.pointer, t.pointerLen = t.processTabs([]rune(opts.Pointer), 0)474 t.marker, t.markerLen = t.processTabs([]rune(opts.Marker), 0)475 // Pre-calculated empty pointer and marker signs476 t.pointerEmpty = strings.Repeat(" ", t.pointerLen)
1 unmodified line
478479 return &t480}481482func (t *Terminal) parsePrompt(prompt string) (func(), int) {483 var state *ansiState484 trimmed, colors, _ := extractColor(prompt, state, nil)485 item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}486 output := func() {487 t.printHighlighted(488 Result{item: item}, t.strong, tui.ColPrompt, tui.ColPrompt, false, false)489 }490 _, promptLen := t.processTabs([]rune(trimmed), 0)491492 return output, promptLen493}494495func (t *Terminal) noInfoLine() bool {496 return t.infoStyle != infoDefault497}498
293 unmodified lines
792}793794func (t *Terminal) printPrompt() {795 t.move(0, 0, true)783 t.window.CPrint(tui.ColPrompt, t.strong, t.prompt)796 t.prompt()797798 before, after := t.updatePromptOffset()799 t.window.CPrint(tui.ColNormal, t.strong, string(before))800 t.window.CPrint(tui.ColNormal, t.strong, string(after))
1490 unmodified lines
modified:CHANGELOG.md+1 added
24 unmodified lines
2526 # Preview window hidden by default, it appears when you first hit '?'27 fzf --bind '?:preview:cat {}' --preview-window hidden28 ```29- Added support for ANSI colors in `--prompt` string30- Vim plugin31 - `tmux` layout option for using fzf-tmux32 ```vim33 let g:fzf_layout = { 'tmux': '-p90%,60%' }
869 unmodified lines