diff --git a/src/segment_language.go b/src/segment_language.go index b48f9e43..41c96876 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -71,6 +71,8 @@ type language struct { loadContext loadContext inContext inContext matchesVersionFile matchesVersionFile + homeEnabled bool + displayMode string } const ( @@ -121,13 +123,16 @@ func (l *language) enabled() bool { inHomeDir := func() bool { return l.env.getcwd() == l.env.homeDir() } - homeEnabled := l.props.getBool(HomeEnabled, false) + homeEnabled := l.props.getBool(HomeEnabled, l.homeEnabled) if inHomeDir() && !homeEnabled { return false } - displayMode := l.props.getString(DisplayMode, DisplayModeFiles) + // set default mode when not set + if len(l.displayMode) == 0 { + l.displayMode = l.props.getString(DisplayMode, DisplayModeFiles) + } l.loadLanguageContext() - switch displayMode { + switch l.displayMode { case DisplayModeAlways: return true case DisplayModeEnvironment: diff --git a/src/segment_python.go b/src/segment_python.go index 895564e0..23bbf24b 100644 --- a/src/segment_python.go +++ b/src/segment_python.go @@ -43,6 +43,8 @@ func (p *python) init(props *properties, env environmentInfo) { }, }, versionURLTemplate: "[%s](https://www.python.org/downloads/release/python-%s%s%s/)", + displayMode: props.getString(DisplayMode, DisplayModeEnvironment), + homeEnabled: props.getBool(HomeEnabled, true), } } diff --git a/src/segment_python_test.go b/src/segment_python_test.go index a2d197dc..6b28f2c2 100644 --- a/src/segment_python_test.go +++ b/src/segment_python_test.go @@ -8,7 +8,9 @@ import ( func TestPythonVirtualEnv(t *testing.T) { cases := []struct { + Case string Expected string + ExpectedDisabled bool VirtualEnvName string CondaEnvName string CondaDefaultEnvName string @@ -16,13 +18,13 @@ func TestPythonVirtualEnv(t *testing.T) { DisplayVersion bool DisplayDefault bool }{ - {Expected: "VENV", VirtualEnvName: "VENV"}, - {Expected: "CONDA", CondaEnvName: "CONDA"}, - {Expected: "CONDA", CondaDefaultEnvName: "CONDA"}, - {Expected: "", CondaDefaultEnvName: "base"}, - {Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true}, - {Expected: "PYENV", PyEnvName: "PYENV"}, - {Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true}, + {Case: "VENV", Expected: "VENV", VirtualEnvName: "VENV"}, + {Case: "CONDA", Expected: "CONDA", CondaEnvName: "CONDA"}, + {Case: "CONDA default", Expected: "CONDA", CondaDefaultEnvName: "CONDA"}, + {Case: "Display Base", Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true}, + {Case: "Hide base", Expected: "", CondaDefaultEnvName: "base", ExpectedDisabled: true}, + {Case: "PYENV", Expected: "PYENV", PyEnvName: "PYENV"}, + {Case: "PYENV Version", Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true}, } for _, tc := range cases { @@ -46,8 +48,8 @@ func TestPythonVirtualEnv(t *testing.T) { } python := &python{} python.init(props, env) - assert.True(t, python.enabled()) - assert.Equal(t, tc.Expected, python.string()) + assert.Equal(t, !tc.ExpectedDisabled, python.enabled(), tc.Case) + assert.Equal(t, tc.Expected, python.string(), tc.Case) } }