Skip to content

Commit 6682034

Browse files
fix(shell): respect POSH_DISABLE_STREAMING at runtime
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 0976794 commit 6682034

10 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/config/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ func (cfg *Config) getPalette() color.Palette {
136136
return palette
137137
}
138138

139-
// streamingEnabled reports whether streaming should be enabled: it's configured, and not
140-
// force-disabled via POSH_DISABLE_STREAMING regardless of that configuration.
139+
// streamingEnabled reports whether streaming should be enabled: it's configured.
141140
func (cfg *Config) streamingEnabled(env runtime.Environment) bool {
142-
return cfg.Streaming > 0 && env.Getenv("POSH_DISABLE_STREAMING") != "1"
141+
return cfg.Streaming > 0
143142
}
144143

145144
func (cfg *Config) Features(env runtime.Environment) shell.Features {

src/config/config_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,6 @@ func TestFeaturesStreaming(t *testing.T) {
177177
Case: "streaming not configured",
178178
ExpectedFeats: 0,
179179
},
180-
{
181-
Case: "POSH_DISABLE_STREAMING overrides the config",
182-
Streaming: 100,
183-
DisableStreaming: "1",
184-
ExpectedFeats: 0,
185-
},
186180
}
187181

188182
for _, tc := range cases {

src/shell/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ else
3333
os.execute(string.format('"%s" notice', omp_executable))
3434
end`
3535
case Streaming:
36-
return "serve_enabled = true"
36+
return "if os.getenv(\"POSH_DISABLE_STREAMING\") ~= \"1\" then\n serve_enabled = true\nend"
3737
case PromptMark, PoshGit, Azure, LineError, Jobs, CursorPositioning, Async, KeyHandlers, VIMode:
3838
fallthrough
3939
default:

src/shell/cmd_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ else
2727
os.execute(string.format('"%s" notice', omp_executable))
2828
end
2929
rprompt_enabled = true
30-
serve_enabled = true`
30+
if os.getenv("POSH_DISABLE_STREAMING") ~= "1" then
31+
serve_enabled = true
32+
end`
3133

3234
assert.Equal(t, want, got)
3335
}

src/shell/fish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (f Features) Fish() Code {
2424
case Tooltips:
2525
return "enable_poshtooltips"
2626
case Streaming:
27-
return "set --global _omp_enable_streaming 1"
27+
return "if test \"$POSH_DISABLE_STREAMING\" != \"1\"; set --global _omp_enable_streaming 1; end"
2828
case Upgrade:
2929
return unixUpgrade
3030
case Notice:

src/shell/fish_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set --global _omp_ftcs_marks 1
1818
"$_omp_executable" notice
1919
set --global _omp_prompt_mark 1
2020
set --global _omp_cursor_positioning 1
21-
set --global _omp_enable_streaming 1
21+
if test "$POSH_DISABLE_STREAMING" != "1"; set --global _omp_enable_streaming 1; end
2222
_omp_enable_vimode
2323
set --global _omp_transient_rprompt 1`
2424

src/shell/pwsh_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Enable-PoshVIMode`
3333
assert.Equal(t, want, got)
3434
}
3535

36+
func TestPwshStreamingGuard(t *testing.T) {
37+
assert.Contains(t, pwshInit, "if ($env:POSH_DISABLE_STREAMING -eq '1') {")
38+
assert.Contains(t, pwshInit, "return")
39+
}
40+
3641
func TestSourceCommandAsyncPwsh(t *testing.T) {
3742
got := sourceCommandAsync(PWSH, "C:/cache/init.pwsh.ps1")
3843

src/shell/scripts/omp.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,10 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
993993
}
994994

995995
function Enable-PoshStreaming {
996+
if ($env:POSH_DISABLE_STREAMING -eq '1') {
997+
return
998+
}
999+
9961000
$global:_ompStreaming = $true
9971001

9981002
if (-not $script:ServeSupported) {

src/shell/zsh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (f Features) Zsh() Code {
2222
case Notice:
2323
return unixNotice
2424
case Streaming:
25-
return "_omp_enable_streaming=1"
25+
return "if [[ \"${POSH_DISABLE_STREAMING:-}\" != \"1\" ]]; then _omp_enable_streaming=1; fi"
2626
case VIMode:
2727
return "_omp_enable_vimode"
2828
case PromptMark, RPrompt, PoshGit, Azure, LineError, Jobs, Async, KeyHandlers:

src/shell/zsh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _omp_ftcs_marks=1
2020
"$_omp_executable" upgrade --auto
2121
"$_omp_executable" notice
2222
_omp_cursor_positioning=1
23-
_omp_enable_streaming=1
23+
if [[ "${POSH_DISABLE_STREAMING:-}" != "1" ]]; then _omp_enable_streaming=1; fi
2424
_omp_enable_vimode`
2525

2626
assert.Equal(t, want, got)

0 commit comments

Comments
 (0)