Repository: JanDeDobbeleer/oh-my-posh
Pull request #608 (2021-04-01 18:32:48)

various fixes
### Prerequisites

- [ ] I have read and understand the `CONTRIBUTING` guide
- [ ] The commit message follows the [conventional commits][cc] guidelines
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)

### Description

[Description of the change]

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/docs/docs/segment-time.md b/docs/docs/segment-time.md
index 8e060927..82517f4a 100644
--- a/docs/docs/segment-time.md
+++ b/docs/docs/segment-time.md
@@ -25,13 +25,49 @@ Show the current timestamp.
 
 - time_format: `string` - format to use, follows the [golang standard][format] - defaults to `15:04:05`
 
-[format]: https://gobyexample.com/time-formatting-parsing
+[format]: https://yourbasic.org/golang/format-parse-string-time-date-example/
 
 - template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
-properties below. Only used when a value is set, making the above properties obsolete.
+  properties below. Only used when a value is set, making the above properties obsolete.
 
   example: `{{ now | date \"January 02, 2006 15:04:05 PM\" | lower }}`
 
 ## Template Properties
 
 - `.CurrentDate`: `time` - The time to display(testing purpose)
+
+### Standard time and date formats
+
+- January 2, 2006 **Date**
+- 01/02/06
+- Jan-02-06
+- 15:04:05 **Time**
+- 3:04:05 PM
+- Jan _2 15:04:05 **Timestamp**
+- Jan _2 15:04:05.000000 **with microseconds**
+- 2006-01-02T15:04:05-0700 **ISO 8601 (RFC 3339)**
+- 2006-01-02
+- 15:04:05
+- 02 Jan 06 15:04 MST **RFC 822**
+- 02 Jan 06 15:04 -0700 **with numeric zone**
+- Mon, 02 Jan 2006 15:04:05 MST 27e95cb
+- Mon, 02 Jan 2006 15:04:05 -0700 **with numeric zone**
+
+#### The following predefined date and timestamp format constants are also available
+
+- ANSIC       = "Mon Jan _2 15:04:05 2006"
+- UnixDate    = "Mon Jan _2 15:04:05 MST 2006"
+- RubyDate    = "Mon Jan 02 15:04:05 -0700 2006"
+- RFC822      = "02 Jan 06 15:04 MST"
+- RFC822Z     = "02 Jan 06 15:04 -0700"
+- RFC850      = "Monday, 02-Jan-06 15:04:05 MST"
+- RFC1123     = "Mon, 02 Jan 2006 15:04:05 MST"
+- RFC1123Z    = "Mon, 02 Jan 2006 15:04:05 -0700"
+- RFC3339     = "2006-01-02T15:04:05Z07:00"
+- RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
+- Kitchen     = "3:04PM"
+// Useful time stamps.
+- Stamp      = "Jan _2 15:04:05"
+- StampMilli = "Jan _2 15:04:05.000"
+- StampMicro = "Jan _2 15:04:05.000000"
+- StampNano  = "Jan _2 15:04:05.000000000"
diff --git a/src/settings.go b/src/config.go
similarity index 100%
rename from src/settings.go
rename to src/config.go
diff --git a/src/settings_test.go b/src/config_test.go
similarity index 100%
rename from src/settings_test.go
rename to src/config_test.go
diff --git a/src/console_title.go b/src/console_title.go
index ec621b57..bb9d918f 100644
--- a/src/console_title.go
+++ b/src/console_title.go
@@ -21,6 +21,8 @@ const (
 	FullPath ConsoleTitleStyle = "path"
 	// Template allows a more powerful custom string
 	Template ConsoleTitleStyle = "template"
+
+	templateEnvRegex = `\.Env\.(?P<ENV>[^ \.}]*)`
 )
 
 func (t *consoleTitle) getConsoleTitle() string {
@@ -53,7 +55,7 @@ func (t *consoleTitle) getTemplateText() string {
 
 	// load environment variables into the map
 	envVars := map[string]string{}
-	matches := findAllNamedRegexMatch(`\.Env\.(?P<ENV>[^ \.}]*)`, t.config.ConsoleTitleTemplate)
+	matches := findAllNamedRegexMatch(templateEnvRegex, t.config.ConsoleTitleTemplate)
 	for _, match := range matches {
 		envVars[match["ENV"]] = t.env.getenv(match["ENV"])
 	}
diff --git a/src/engine.go b/src/engine.go
index f30cd3f0..2eddbc20 100644
--- a/src/engine.go
+++ b/src/engine.go
@@ -79,13 +79,8 @@ func (e *engine) renderDiamondSegment(text string) {
 }
 
 func (e *engine) renderText(text string) {
-	defaultValue := " "
-	if e.activeSegment.background() != "" {
-		defaultValue = fmt.Sprintf("<%s>\u2588</>", e.activeSegment.background())
-	}
-
 	text = e.color.formats.generateHyperlink(text)
-
+	defaultValue := " "
 	prefix := e.activeSegment.getValue(Prefix, defaultValue)
 	postfix := e.activeSegment.getValue(Postfix, defaultValue)
 	e.color.write(e.activeSegment.background(), e.activeSegment.foreground(), fmt.Sprintf("%s%s%s", prefix, text, postfix))
diff --git a/src/main.go b/src/main.go
index dfe51926..9872e0f0 100644
--- a/src/main.go
+++ b/src/main.go
@@ -154,7 +154,7 @@ func main() {
 	}
 	colorer := &AnsiColor{
 		formats:            formats,
-		terminalBackground: cfg.TerminalBackground,
+		terminalBackground: getConsoleBackgroundColor(env, cfg.TerminalBackground),
 	}
 	title := &consoleTitle{
 		env:     env,
@@ -219,3 +219,23 @@ func getShellInitScript(executable, configFile, script string) string {
 	script = strings.ReplaceAll(script, "::CONFIG::", configFile)
 	return script
 }
+
+func getConsoleBackgroundColor(env environmentInfo, backgroundColorTemplate string) string {
+	if len(backgroundColorTemplate) == 0 {
+		return backgroundColorTemplate
+	}
+	context := struct {
+		Env map[string]string
+	}{
+		Env: map[string]string{},
+	}
+	matches := findAllNamedRegexMatch(templateEnvRegex, backgroundColorTemplate)
+	for _, match := range matches {
+		context.Env[match["ENV"]] = env.getenv(match["ENV"])
+	}
+	template := &textTemplate{
+		Template: backgroundColorTemplate,
+		Context:  context,
+	}
+	return template.render()
+}


Test patch:
diff --git a/src/main_test.go b/src/main_test.go
new file mode 100644
index 00000000..16b72b83
--- /dev/null
+++ b/src/main_test.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestConsoleBackgroundColorTemplate(t *testing.T) {
+	cases := []struct {
+		Case     string
+		Expected string
+		Term     string
+	}{
+		{Case: "Inside vscode", Expected: "#123456", Term: "vscode"},
+		{Case: "Outside vscode", Expected: "", Term: "windowsterminal"},
+	}
+
+	for _, tc := range cases {
+		env := new(MockedEnvironment)
+		env.On("getenv", "TERM_PROGRAM").Return(tc.Term)
+		color := getConsoleBackgroundColor(env, "{{ if eq \"vscode\" .Env.TERM_PROGRAM }}#123456{{end}}")
+		assert.Equal(t, tc.Expected, color, tc.Case)
+	}
+}