Skip to content

Commit 2e785f7

Browse files
fix(shell): disable streaming when override var is present
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 6682034 commit 2e785f7

10 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/config/config_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ func TestFeaturesShellIntegration(t *testing.T) {
163163

164164
func TestFeaturesStreaming(t *testing.T) {
165165
cases := []struct {
166-
Case string
167-
DisableStreaming string
168-
Streaming int
169-
ExpectedFeats shell.Features
166+
Case string
167+
Streaming int
168+
ExpectedFeats shell.Features
170169
}{
171170
{
172171
Case: "streaming enabled",
@@ -182,7 +181,6 @@ func TestFeaturesStreaming(t *testing.T) {
182181
for _, tc := range cases {
183182
env := &mock.Environment{}
184183
env.On("Shell").Return(shell.PWSH)
185-
env.On("Getenv", "POSH_DISABLE_STREAMING").Return(tc.DisableStreaming)
186184

187185
cfg := &Config{
188186
Streaming: tc.Streaming,

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 "if os.getenv(\"POSH_DISABLE_STREAMING\") ~= \"1\" then\n serve_enabled = true\nend"
36+
return "if os.getenv(\"POSH_DISABLE_STREAMING\") == nil 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else
2727
os.execute(string.format('"%s" notice', omp_executable))
2828
end
2929
rprompt_enabled = true
30-
if os.getenv("POSH_DISABLE_STREAMING") ~= "1" then
30+
if os.getenv("POSH_DISABLE_STREAMING") == nil then
3131
serve_enabled = true
3232
end`
3333

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 "if test \"$POSH_DISABLE_STREAMING\" != \"1\"; set --global _omp_enable_streaming 1; end"
27+
return "if not set -q POSH_DISABLE_STREAMING; 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-
if test "$POSH_DISABLE_STREAMING" != "1"; set --global _omp_enable_streaming 1; end
21+
if not set -q POSH_DISABLE_STREAMING; 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Enable-PoshVIMode`
3434
}
3535

3636
func TestPwshStreamingGuard(t *testing.T) {
37-
assert.Contains(t, pwshInit, "if ($env:POSH_DISABLE_STREAMING -eq '1') {")
37+
assert.Contains(t, pwshInit, "if (Test-Path Env:POSH_DISABLE_STREAMING) {")
3838
assert.Contains(t, pwshInit, "return")
3939
}
4040

src/shell/scripts/omp.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
993993
}
994994

995995
function Enable-PoshStreaming {
996-
if ($env:POSH_DISABLE_STREAMING -eq '1') {
996+
if (Test-Path Env:POSH_DISABLE_STREAMING) {
997997
return
998998
}
999999

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 "if [[ \"${POSH_DISABLE_STREAMING:-}\" != \"1\" ]]; then _omp_enable_streaming=1; fi"
25+
return "if [[ ! -v POSH_DISABLE_STREAMING ]]; 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-
if [[ "${POSH_DISABLE_STREAMING:-}" != "1" ]]; then _omp_enable_streaming=1; fi
23+
if [[ ! -v POSH_DISABLE_STREAMING ]]; then _omp_enable_streaming=1; fi
2424
_omp_enable_vimode`
2525

2626
assert.Equal(t, want, got)

website/docs/configuration/streaming.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ We recommend starting with a timeout of around 100ms and adjusting based on your
4747

4848
:::info
4949
If you're running inside a host or tool that doesn't get along with streaming's background
50-
repaint, set the `POSH_DISABLE_STREAMING` environment variable to `1` before initializing
51-
Oh My Posh to force it off entirely, regardless of what `streaming` is set to in your
52-
configuration. This lets you decide when to disable it using whatever check makes sense for
53-
your setup:
50+
repaint, set the `POSH_DISABLE_STREAMING` environment variable before initializing Oh My
51+
Posh to force it off entirely, regardless of what `streaming` is set to in your
52+
configuration. The variable can be present with any value, so you can decide when to disable
53+
it using whatever check makes sense for your setup:
5454

5555
```powershell
5656
if ($Host.Name -eq 'SomeIncompatibleHost') {
57-
$env:POSH_DISABLE_STREAMING = '1'
57+
$env:POSH_DISABLE_STREAMING = ''
5858
}
5959
6060
oh-my-posh init pwsh --config ~/.mytheme.omp.json | Invoke-Expression

0 commit comments

Comments
 (0)