feat(language): allow enabling or disabling HOME folder

closes #874
This commit is contained in:
Jan De Dobbeleer 2021-07-31 16:54:25 +02:00 committed by Jan De Dobbeleer
parent 1868e15137
commit c4db62c644
12 changed files with 19 additions and 6 deletions

View file

@ -25,6 +25,7 @@ Display the currently active crystal version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the julia version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active dart version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the dart version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active .NET SDK version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `dotnet`
is present - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`

View file

@ -25,6 +25,7 @@ Display the currently active golang version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the golang version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active java version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the java version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the java command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active julia version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the julia version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active node version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the node version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -26,6 +26,7 @@ Supports conda, virtualenv and pyenv.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_virtual_env: `boolean` - show the name of the virtualenv or not - defaults to `true`
- display_default: `boolean` - show the name of the virtualenv when it's default (`system`, `base`)
or not - defaults to `true`

View file

@ -25,6 +25,7 @@ Display the currently active ruby version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the ruby version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -25,6 +25,7 @@ Display the currently active rust version.
## Properties
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
- display_version: `boolean` - display the rust version (`rustc --version`) - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty

View file

@ -90,6 +90,8 @@ const (
VersionMismatchColor Property = "version_mismatch_color"
// EnableVersionMismatch displays empty string by default
EnableVersionMismatch Property = "enable_version_mismatch"
// HomeEnabled displays the segment in the HOME folder or not
HomeEnabled Property = "home_enabled"
)
func (l *language) string() string {
@ -119,10 +121,11 @@ func (l *language) enabled() bool {
inHomeDir := func() bool {
return l.env.getcwd() == l.env.homeDir()
}
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
if inHomeDir() && displayMode != DisplayModeAlways {
homeEnabled := l.props.getBool(HomeEnabled, false)
if inHomeDir() && !homeEnabled {
return false
}
displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
l.loadLanguageContext()
switch displayMode {
case DisplayModeAlways:

View file

@ -441,15 +441,15 @@ func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
func TestLanguageEnabledInHome(t *testing.T) {
cases := []struct {
Case string
DisplayMode string
HomeEnabled bool
ExpectedEnabled bool
}{
{Case: "Always enabled", DisplayMode: DisplayModeAlways, ExpectedEnabled: true},
{Case: "Context disabled", DisplayMode: DisplayModeContext, ExpectedEnabled: false},
{Case: "Always enabled", HomeEnabled: true, ExpectedEnabled: true},
{Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false},
}
for _, tc := range cases {
props := map[Property]interface{}{
DisplayMode: tc.DisplayMode,
HomeEnabled: tc.HomeEnabled,
}
args := &languageArgs{
commands: []*cmd{