diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2024-01-16 14:17:56 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-01-16 14:18:31 +0900 |
commit | cdfaf761df2e68503ca7c74c0aaa3e6fa4a46bda (patch) | |
tree | d12ef3ad5a0f20b0f8a462967afb026dd04615bc /src/terminal.go | |
parent | 1a9ea6f738cfafab83a5e0e828e60f0bf68bffee (diff) |
Expose state information via environment variables to child processes
Close #3582
Diffstat (limited to 'src/terminal.go')
-rw-r--r-- | src/terminal.go | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/terminal.go b/src/terminal.go index 77543e25..7832cbbc 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -291,6 +291,8 @@ type Terminal struct { termSize tui.TermSize lastAction actionType lastFocus int32 + areaLines int + areaColumns int } type selectedItem struct { @@ -451,6 +453,17 @@ const ( actHideHeader ) +func (a actionType) Name() string { + name := "" + for i, r := range a.String()[3:] { + if i > 0 && r >= 'A' && r <= 'Z' { + name += "-" + } + name += string(r) + } + return strings.ToLower(name) +} + func processExecution(action actionType) bool { switch action { case actTransform, @@ -825,6 +838,14 @@ func (t *Terminal) environ() []string { if t.listenPort != nil { env = append(env, fmt.Sprintf("FZF_PORT=%d", *t.listenPort)) } + env = append(env, "FZF_QUERY="+string(t.input)) + env = append(env, "FZF_ACTION="+t.lastAction.Name()) + env = append(env, "FZF_PROMPT="+string(t.promptString)) + env = append(env, fmt.Sprintf("FZF_TOTAL_COUNT=%d", t.count)) + env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.merger.Length())) + env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected))) + env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines)) + env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns)) return env } @@ -1291,6 +1312,9 @@ func (t *Terminal) resizeWindows(forcePreview bool) { width -= paddingInt[1] + paddingInt[3] height -= paddingInt[0] + paddingInt[2] + t.areaLines = height + t.areaColumns = width + // Set up preview window noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode) if forcePreview || t.needPreviewWindow() { @@ -2543,14 +2567,7 @@ func replacePlaceholder(params replacePlaceholderParams) string { } } case match == "{fzf:action}": - name := "" - for i, r := range params.lastAction.String()[3:] { - if i > 0 && r >= 'A' && r <= 'Z' { - name += "-" - } - name += string(r) - } - return strings.ToLower(name) + return params.lastAction.Name() case match == "{fzf:prompt}": return quoteEntry(params.prompt) default: |