Export FZF_PREVIEW_* variables to other processes as well
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #4098
authored by Junegunn Choi · committed by Junegunn Choi · parent e7e852b · Browse files · 2 files·+17 added−22 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−22 removed
- other:+17 added−22 removed
Provenance
- Commit
ac3e24c- Tree
363b832- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
e7e852b
2 files changed+17 added−22 removed
modified:man/man1/fzf.1+1 added-4 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE SOFTWARE.23 ..24-.TH fzf 1 "Nov 2024" "fzf 0.56.3" "fzf - a command-line fuzzy finder"24+.TH fzf 1 "Nov 2024" "fzf 0.57.0" "fzf - a command-line fuzzy finder"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 1092 unmodified lines1121 .BR FZF_KEY " The name of the last key pressed"1122 .br1123 .BR FZF_PORT " Port number when \-\-listen option is used"1124 .br1125-1126-The following variables are additionally exported to the preview commands.1127-1125 .BR FZF_PREVIEW_TOP " Top position of the preview window"1126 .br1127 .BR FZF_PREVIEW_LEFT " Left position of the preview window"1128 .br578 unmodified linesmodified:src/terminal.go+16 added-18 removed
559 unmodified lines560 }561 562 type previewRequest struct {563 template string564- pwindow tui.Window565- pwindowSize tui.TermSize564 scrollOffset int565 list []*Item566 env []string567 }399 unmodified lines967 env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))968 env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))969 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))970 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))971+972+ // Add preview environment variables if preview is enabled973+ pwindowSize := t.pwindowSize()974+ if pwindowSize.Lines > 0 {975+ lines := fmt.Sprintf("LINES=%d", pwindowSize.Lines)976+ columns := fmt.Sprintf("COLUMNS=%d", pwindowSize.Columns)977+ env = append(env, lines)978+ env = append(env, "FZF_PREVIEW_"+lines)979+ env = append(env, columns)980+ env = append(env, "FZF_PREVIEW_"+columns)981+ env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+t.pwindow.Top()))982+ env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", t.pwindow.Left()))983+ }984+985 return env986 }987 988 func borderLines(shape tui.BorderShape) int {2541 unmodified lines3530 t.previewBox.WaitFor(reqPreviewReady)3531 for {3532 var items []*Item3533 var commandTemplate string3522- var pwindow tui.Window3523- var pwindowSize tui.TermSize3534 var env []string3535 initialOffset := 03536 t.previewBox.Wait(func(events *util.Events) {3537 for req, value := range *events {5 unmodified lines3543 request := value.(previewRequest)3544 commandTemplate = request.template3545 initialOffset = request.scrollOffset3546 items = request.list3537- pwindow = request.pwindow3538- pwindowSize = request.pwindowSize3547 env = request.env3548 }3549 }3550 events.Clear()9 unmodified lines3560 if items[0] != nil {3561 _, query := t.Input()3562 command, tempFiles := t.replacePlaceholder(commandTemplate, false, string(query), items)3563 cmd := t.executor.ExecCommand(command, true)3556- if pwindowSize.Lines > 0 {3557- lines := fmt.Sprintf("LINES=%d", pwindowSize.Lines)3558- columns := fmt.Sprintf("COLUMNS=%d", pwindowSize.Columns)3559- env = append(env, lines)3560- env = append(env, "FZF_PREVIEW_"+lines)3561- env = append(env, columns)3562- env = append(env, "FZF_PREVIEW_"+columns)3563- env = append(env, fmt.Sprintf("FZF_PREVIEW_TOP=%d", t.tui.Top()+pwindow.Top()))3564- env = append(env, fmt.Sprintf("FZF_PREVIEW_LEFT=%d", pwindow.Left()))3565- }3564 cmd.Env = env3565 3566 out, _ := cmd.StdoutPipe()3567 cmd.Stderr = cmd.Stdout118 unmodified lines3686 refreshPreview := func(command string) {3687 if len(command) > 0 && t.canPreview() {3688 _, list := t.buildPlusList(command, false)3689 t.cancelPreview()3692- t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.pwindow, t.pwindowSize(), t.evaluateScrollOffset(), list, t.environ()})3690+ t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environ()})3691 }3692 }3693 3694 go func() { // Render loop376 unmodified lines4071 valid, list := t.buildPlusList(t.previewOpts.command, false)4072 if valid {4073 t.cancelPreview()4074 t.previewBox.Set(reqPreviewEnqueue,4077- previewRequest{t.previewOpts.command, t.pwindow, t.pwindowSize(), t.evaluateScrollOffset(), list, t.environ()})4075+ previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environ()})4076 }4077 } else {4078 // Discard the preview content so that it won't accidentally appear4079 // when preview window is re-enabled and previewDelay is triggered1070 unmodified lines