From 890f9cde1b1b6e04c0d4681a4bf45f116b4ffa39 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 12 Jan 2021 20:37:14 +0100 Subject: [PATCH] refactor(language): remap context to files --- docs/docs/segment-golang.md | 2 +- docs/docs/segment-julia.md | 2 +- docs/docs/segment-node.md | 2 +- docs/docs/segment-python.md | 2 +- src/segment_language.go | 18 +++++++++--------- src/segment_language_test.go | 4 ++-- themes/schema.json | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/docs/segment-golang.md b/docs/docs/segment-golang.md index 42e83485d945..989a4eabcb24 100644 --- a/docs/docs/segment-golang.md +++ b/docs/docs/segment-golang.md @@ -29,4 +29,4 @@ Display the currently active golang version when a folder contains `.go` files. - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: The segment is always displayed - - `context`: The segment is only displayed when *.go or go.mod files are present (default) + - `files`: The segment is only displayed when `*.go` or `go.mod` files are present (default) diff --git a/docs/docs/segment-julia.md b/docs/docs/segment-julia.md index 2865fb6e98d4..ebabdc9a7a8d 100644 --- a/docs/docs/segment-julia.md +++ b/docs/docs/segment-julia.md @@ -29,4 +29,4 @@ Display the currently active julia version when a folder contains `.jl` files. - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: The segment is always displayed - - `context`: The segment is only displayed when *.jl files are present (default) + - `files`: The segment is only displayed when `*.jl` files are present (default) diff --git a/docs/docs/segment-node.md b/docs/docs/segment-node.md index 44244201b262..ae386936c7b1 100644 --- a/docs/docs/segment-node.md +++ b/docs/docs/segment-node.md @@ -29,4 +29,4 @@ Display the currently active node version when a folder contains `.js` or `.ts` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: The segment is always displayed - - `context`: The segment is only displayed when *.js, *.ts or package.json files are present (default) + - `files`: The segment is only displayed when `*.js`, `*.ts` or package.json files are present (default) diff --git a/docs/docs/segment-python.md b/docs/docs/segment-python.md index 37286c8b0886..3bec21410d4a 100644 --- a/docs/docs/segment-python.md +++ b/docs/docs/segment-python.md @@ -31,4 +31,4 @@ Supports conda, virtualenv and pyenv. - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: The segment is always displayed - - `context`: The segment is only displayed when *.py or *.ipynb files are present (default) + - `files`: The segment is only displayed when `*.py` or `*.ipynb` files are present (default) diff --git a/src/segment_language.go b/src/segment_language.go index cac739c20fd2..7762592c1f8f 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -15,12 +15,12 @@ type language struct { } const ( - // DisplayModeProperty sets the display mode (always, when_in_context, never) - DisplayModeProperty Property = "display_mode" + // DisplayMode sets the display mode (always, when_in_context, never) + DisplayMode Property = "display_mode" // DisplayModeAlways displays the segment always DisplayModeAlways string = "always" - // DisplayModeContext displays the segment when the current folder contains certain extensions - DisplayModeContext string = "context" + // DisplayModeFiles displays the segment when the current folder contains certain extensions + DisplayModeFiles string = "files" // MissingCommandTextProperty sets the text to display when the command is not present in the system MissingCommandTextProperty Property = "missing_command_text" // MissingCommandText displays empty string by default @@ -41,21 +41,21 @@ func (l *language) string() string { } func (l *language) enabled() bool { - displayMode := l.props.getString(DisplayModeProperty, DisplayModeContext) + displayMode := l.props.getString(DisplayMode, DisplayModeFiles) displayVersion := l.props.getBool(DisplayVersion, true) switch displayMode { case DisplayModeAlways: return (!displayVersion || l.hasCommand()) - case DisplayModeContext: + case DisplayModeFiles: fallthrough default: - return l.isInContext() && (!displayVersion || l.hasCommand()) + return l.hasLanguageFiles() && (!displayVersion || l.hasCommand()) } } -// isInContext will return true at least one file matching the extensions is found -func (l *language) isInContext() bool { +// hasLanguageFiles will return true at least one file matching the extensions is found +func (l *language) hasLanguageFiles() bool { for i, extension := range l.extensions { if l.env.hasFiles(extension) { break diff --git a/src/segment_language_test.go b/src/segment_language_test.go index 33b9afb603ca..5aa036f15872 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -45,8 +45,8 @@ func bootStrapLanguageTest(args *languageArgs) *language { } props := &properties{ values: map[Property]interface{}{ - DisplayVersion: args.displayVersion, - DisplayModeProperty: args.displayMode, + DisplayVersion: args.displayVersion, + DisplayMode: args.displayMode, }, } if args.missingCommandText != "" { diff --git a/themes/schema.json b/themes/schema.json index 2676fce64e2f..5052637c93d8 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -21,7 +21,7 @@ "type": "string", "title": "Display Mode", "description": "Determines whether the segment is displayed always or only if a file matching the extensions are present in the current folder", - "enum": ["always", "context", "never"], + "enum": ["always", "files"], "default": "context" }, "missing_command_text": {