mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
eca24bebcc
commit
7e5b9fa725
|
@ -71,6 +71,8 @@ type language struct {
|
||||||
loadContext loadContext
|
loadContext loadContext
|
||||||
inContext inContext
|
inContext inContext
|
||||||
matchesVersionFile matchesVersionFile
|
matchesVersionFile matchesVersionFile
|
||||||
|
homeEnabled bool
|
||||||
|
displayMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -121,13 +123,16 @@ func (l *language) enabled() bool {
|
||||||
inHomeDir := func() bool {
|
inHomeDir := func() bool {
|
||||||
return l.env.getcwd() == l.env.homeDir()
|
return l.env.getcwd() == l.env.homeDir()
|
||||||
}
|
}
|
||||||
homeEnabled := l.props.getBool(HomeEnabled, false)
|
homeEnabled := l.props.getBool(HomeEnabled, l.homeEnabled)
|
||||||
if inHomeDir() && !homeEnabled {
|
if inHomeDir() && !homeEnabled {
|
||||||
return false
|
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()
|
l.loadLanguageContext()
|
||||||
switch displayMode {
|
switch l.displayMode {
|
||||||
case DisplayModeAlways:
|
case DisplayModeAlways:
|
||||||
return true
|
return true
|
||||||
case DisplayModeEnvironment:
|
case DisplayModeEnvironment:
|
||||||
|
|
|
@ -43,6 +43,8 @@ func (p *python) init(props *properties, env environmentInfo) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
versionURLTemplate: "[%s](https://www.python.org/downloads/release/python-%s%s%s/)",
|
versionURLTemplate: "[%s](https://www.python.org/downloads/release/python-%s%s%s/)",
|
||||||
|
displayMode: props.getString(DisplayMode, DisplayModeEnvironment),
|
||||||
|
homeEnabled: props.getBool(HomeEnabled, true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ import (
|
||||||
|
|
||||||
func TestPythonVirtualEnv(t *testing.T) {
|
func TestPythonVirtualEnv(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
|
Case string
|
||||||
Expected string
|
Expected string
|
||||||
|
ExpectedDisabled bool
|
||||||
VirtualEnvName string
|
VirtualEnvName string
|
||||||
CondaEnvName string
|
CondaEnvName string
|
||||||
CondaDefaultEnvName string
|
CondaDefaultEnvName string
|
||||||
|
@ -16,13 +18,13 @@ func TestPythonVirtualEnv(t *testing.T) {
|
||||||
DisplayVersion bool
|
DisplayVersion bool
|
||||||
DisplayDefault bool
|
DisplayDefault bool
|
||||||
}{
|
}{
|
||||||
{Expected: "VENV", VirtualEnvName: "VENV"},
|
{Case: "VENV", Expected: "VENV", VirtualEnvName: "VENV"},
|
||||||
{Expected: "CONDA", CondaEnvName: "CONDA"},
|
{Case: "CONDA", Expected: "CONDA", CondaEnvName: "CONDA"},
|
||||||
{Expected: "CONDA", CondaDefaultEnvName: "CONDA"},
|
{Case: "CONDA default", Expected: "CONDA", CondaDefaultEnvName: "CONDA"},
|
||||||
{Expected: "", CondaDefaultEnvName: "base"},
|
{Case: "Display Base", Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true},
|
||||||
{Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true},
|
{Case: "Hide base", Expected: "", CondaDefaultEnvName: "base", ExpectedDisabled: true},
|
||||||
{Expected: "PYENV", PyEnvName: "PYENV"},
|
{Case: "PYENV", Expected: "PYENV", PyEnvName: "PYENV"},
|
||||||
{Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true},
|
{Case: "PYENV Version", Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
@ -46,8 +48,8 @@ func TestPythonVirtualEnv(t *testing.T) {
|
||||||
}
|
}
|
||||||
python := &python{}
|
python := &python{}
|
||||||
python.init(props, env)
|
python.init(props, env)
|
||||||
assert.True(t, python.enabled())
|
assert.Equal(t, !tc.ExpectedDisabled, python.enabled(), tc.Case)
|
||||||
assert.Equal(t, tc.Expected, python.string())
|
assert.Equal(t, tc.Expected, python.string(), tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue