Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ func (cfg *Config) getPalette() color.Palette {
return palette
}

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

func (cfg *Config) Features(env runtime.Environment) shell.Features {
Expand Down
14 changes: 3 additions & 11 deletions src/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ func TestFeaturesShellIntegration(t *testing.T) {

func TestFeaturesStreaming(t *testing.T) {
cases := []struct {
Case string
DisableStreaming string
Streaming int
ExpectedFeats shell.Features
Case string
Streaming int
ExpectedFeats shell.Features
}{
{
Case: "streaming enabled",
Expand All @@ -177,18 +176,11 @@ func TestFeaturesStreaming(t *testing.T) {
Case: "streaming not configured",
ExpectedFeats: 0,
},
{
Case: "POSH_DISABLE_STREAMING overrides the config",
Streaming: 100,
DisableStreaming: "1",
ExpectedFeats: 0,
},
}

for _, tc := range cases {
env := &mock.Environment{}
env.On("Shell").Return(shell.PWSH)
env.On("Getenv", "POSH_DISABLE_STREAMING").Return(tc.DisableStreaming)

cfg := &Config{
Streaming: tc.Streaming,
Expand Down
10 changes: 5 additions & 5 deletions src/prompt/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const regenerateFixtureCommand = "go run . config export data --sanitize --theme

// fixturePath is the single sanitized --data fixture every bundled theme
// renders against - see the package comment above for why one shared fixture
// replaces what used to be 124 per-theme files.
// replaces what used to be 125 per-theme files.
var fixturePath = filepath.Join("testdata", "fixtures", "prompt.data.json")

// sanitizedPWD is the PWD value cli/sanitize.go bakes into fixturePath (see
Expand All @@ -69,7 +69,7 @@ var update = flag.Bool("update", false, "regenerate the golden manifest and repr
// fixture. code.yml runs `go test ./...` on ubuntu, macOS and windows, so all
// three matter, not just this machine.
func TestMain(m *testing.M) {
// 65 of 124 themes render a time segment through dateInZone(fmt, date,
// 65 of 125 themes render a time segment through dateInZone(fmt, date,
// "Local") (template/date.go). The segment's own state is baked into the
// fixture at record time (restoreData never re-probes it), but formatting
// that recorded instant still happens at render time in the process's
Expand Down Expand Up @@ -216,7 +216,7 @@ func renderTheme(t *testing.T, themePath, fixturePath string) []byte {
// template.Init only rebuilds the package-level template.Cache singleton
// when it is nil (template/init.go) - by design, for the serve daemon,
// which stays alive across many renders and calls ResetCache itself
// between them (cli/serve.go). This harness renders 124 different themes
// between them (cli/serve.go). This harness renders 125 different themes
// (each with its own env identity) in one process, and other tests in
// this package also populate Cache directly, so without forcing a rebuild
// here every render after the first would silently reuse whichever env
Expand Down Expand Up @@ -314,13 +314,13 @@ func contextWindow(b []byte, offset int) []byte {
}

// TestGoldenThemes renders every bundled theme from its committed fixture and
// checks it two ways: a sha256 line in the manifest (all 124 themes) and,
// checks it two ways: a sha256 line in the manifest (all 125 themes) and,
// additionally for representativeThemes, a byte-for-byte comparison against a
// committed golden file. Run with -update to regenerate both instead of
// comparing.
func TestGoldenThemes(t *testing.T) {
themePaths := themeFiles(t)
require.Lenf(t, themePaths, 124, "expected 124 bundled themes (122 .omp.json + 2 .omp.yaml); "+
require.Lenf(t, themePaths, 125, "expected 125 bundled themes (123 .omp.json + 2 .omp.yaml); "+
"if this changed intentionally, update the fixture/golden set for the new/removed theme(s)")

type manifestEntry struct {
Expand Down
1 change: 1 addition & 0 deletions src/prompt/testdata/goldens/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if_tea 1485171bfd8dc7ed6c8741682d96b434075286345a7e493ece046180f276ba6d
illusi0n 136fcbf744b7423de9326452b336b9c85e7edc2888821a166939019f41d24c5f
iterm2 39e7436753c8cdae446cd25670bd3f33e11a807720d1f01047f3e724debb679d
jandedobbeleer 28dc389e8d6265370039f2c749559e181a659d35272aebfc8a1120dc1ed4443d
jandedobbeleer-accessible d6f8430dbe8df92601134d90ebd6a5838dfe0bb3d91e13def35d7d0e86a530b1
jblab_2021 72923b996d17e9502f0cc5d182eebc64948eac132fdbf767e6f520ea9a415556
jonnychipz 4a5ef8a7154c7c3c237e387d8d03858ff59b942b937c232fabd23ec419c9efc0
json f8a1ebf6f791cb08a142718cf2ad34e338f562584d59655c903064458244efa3
Expand Down
2 changes: 1 addition & 1 deletion src/shell/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
os.execute(string.format('"%s" notice', omp_executable))
end`
case Streaming:
return "serve_enabled = true"
return "if os.getenv(\"POSH_DISABLE_STREAMING\") == nil then\n serve_enabled = true\nend"
case PromptMark, PoshGit, Azure, LineError, Jobs, CursorPositioning, Async, KeyHandlers, VIMode:
fallthrough
default:
Expand Down
4 changes: 3 additions & 1 deletion src/shell/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ else
os.execute(string.format('"%s" notice', omp_executable))
end
rprompt_enabled = true
serve_enabled = true`
if os.getenv("POSH_DISABLE_STREAMING") == nil then
serve_enabled = true
end`

assert.Equal(t, want, got)
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (f Features) Fish() Code {
case Tooltips:
return "enable_poshtooltips"
case Streaming:
return "set --global _omp_enable_streaming 1"
return "if not set -q POSH_DISABLE_STREAMING; set --global _omp_enable_streaming 1; end"
case Upgrade:
return unixUpgrade
case Notice:
Expand Down
2 changes: 1 addition & 1 deletion src/shell/fish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set --global _omp_ftcs_marks 1
"$_omp_executable" notice
set --global _omp_prompt_mark 1
set --global _omp_cursor_positioning 1
set --global _omp_enable_streaming 1
if not set -q POSH_DISABLE_STREAMING; set --global _omp_enable_streaming 1; end
_omp_enable_vimode
set --global _omp_transient_rprompt 1`

Expand Down
4 changes: 4 additions & 0 deletions src/shell/scripts/omp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
}

function Enable-PoshStreaming {
if (Test-Path Env:POSH_DISABLE_STREAMING) {
return
}

$global:_ompStreaming = $true

if (-not $script:ServeSupported) {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (f Features) Zsh() Code {
case Notice:
return unixNotice
case Streaming:
return "_omp_enable_streaming=1"
return "if [[ ! -v POSH_DISABLE_STREAMING ]]; then _omp_enable_streaming=1; fi"
case VIMode:
return "_omp_enable_vimode"
case PromptMark, RPrompt, PoshGit, Azure, LineError, Jobs, Async, KeyHandlers:
Expand Down
2 changes: 1 addition & 1 deletion src/shell/zsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _omp_ftcs_marks=1
"$_omp_executable" upgrade --auto
"$_omp_executable" notice
_omp_cursor_positioning=1
_omp_enable_streaming=1
if [[ ! -v POSH_DISABLE_STREAMING ]]; then _omp_enable_streaming=1; fi
_omp_enable_vimode`

assert.Equal(t, want, got)
Expand Down
10 changes: 5 additions & 5 deletions website/docs/configuration/streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ We recommend starting with a timeout of around 100ms and adjusting based on your

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

```powershell
if ($Host.Name -eq 'SomeIncompatibleHost') {
$env:POSH_DISABLE_STREAMING = '1'
$env:POSH_DISABLE_STREAMING = ''
}

oh-my-posh init pwsh --config ~/.mytheme.omp.json | Invoke-Expression
Expand Down
Loading