mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat: deprecate pre- and postfix
This commit is contained in:
parent
b4292e2e50
commit
83980a3dff
|
@ -36,7 +36,7 @@ func (n *new) Enabled() bool {
|
|||
}
|
||||
|
||||
func (n *new) Template() string {
|
||||
return "{{.Text}} world"
|
||||
return " {{.Text}} world "
|
||||
}
|
||||
|
||||
func (n *new) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package engine
|
|||
import (
|
||||
"oh-my-posh/color"
|
||||
"oh-my-posh/environment"
|
||||
"oh-my-posh/properties"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -111,23 +110,16 @@ func (b *Block) renderSegment(segment *Segment) {
|
|||
b.writePowerline(false)
|
||||
switch b.activeSegment.Style {
|
||||
case Plain, Powerline:
|
||||
b.renderText(segment.stringValue)
|
||||
b.writer.Write(b.activeBackground, b.activeForeground, segment.stringValue)
|
||||
case Diamond:
|
||||
b.writer.Write(color.Transparent, b.activeBackground, b.activeSegment.LeadingDiamond)
|
||||
b.renderText(segment.stringValue)
|
||||
b.writer.Write(b.activeBackground, b.activeForeground, segment.stringValue)
|
||||
b.writer.Write(color.Transparent, b.activeBackground, b.activeSegment.TrailingDiamond)
|
||||
}
|
||||
b.previousActiveSegment = b.activeSegment
|
||||
b.writer.SetParentColors(b.activeBackground, b.activeForeground)
|
||||
}
|
||||
|
||||
func (b *Block) renderText(text string) {
|
||||
defaultValue := " "
|
||||
b.writer.Write(b.activeBackground, b.activeForeground, b.activeSegment.getValue(properties.Prefix, defaultValue))
|
||||
b.writer.Write(b.activeBackground, b.activeForeground, text)
|
||||
b.writer.Write(b.activeBackground, b.activeForeground, b.activeSegment.getValue(properties.Postfix, defaultValue))
|
||||
}
|
||||
|
||||
func (b *Block) writePowerline(final bool) {
|
||||
resolvePowerlineSymbol := func() string {
|
||||
var symbol string
|
||||
|
|
|
@ -10,12 +10,18 @@ import (
|
|||
|
||||
const (
|
||||
colorBackground = properties.Property("color_background")
|
||||
|
||||
prefix = properties.Property("prefix")
|
||||
postfix = properties.Property("postfix")
|
||||
)
|
||||
|
||||
func (cfg *Config) Migrate(env environment.Environment) {
|
||||
for _, block := range cfg.Blocks {
|
||||
block.migrate(env)
|
||||
}
|
||||
for _, segment := range cfg.Tooltips {
|
||||
segment.migrate(env)
|
||||
}
|
||||
cfg.updated = true
|
||||
}
|
||||
|
||||
|
@ -66,9 +72,9 @@ func (segment *Segment) migrate(env environment.Environment) {
|
|||
stateList = append(stateList, `"Full"`)
|
||||
}
|
||||
if len(stateList) < 3 {
|
||||
enabledTemplate := "{{ $stateList := list %s }}{{ if has .State.String $stateList }}{{.Icon}}{{.Percentage}}{{ end }}"
|
||||
enabledTemplate := "{{ $stateList := list %s }}{{ if has .State.String $stateList }}{{ .Icon }}{{ .Percentage }}{{ end }}"
|
||||
template := segment.Properties.GetString(properties.SegmentTemplate, segment.writer.Template())
|
||||
template = strings.ReplaceAll(template, "{{.Icon}}{{.Percentage}}", fmt.Sprintf(enabledTemplate, strings.Join(stateList, " ")))
|
||||
template = strings.ReplaceAll(template, "{{ .Icon }}{{ .Percentage }}", fmt.Sprintf(enabledTemplate, strings.Join(stateList, " ")))
|
||||
segment.Properties[properties.SegmentTemplate] = template
|
||||
}
|
||||
case PYTHON:
|
||||
|
@ -98,7 +104,8 @@ func (segment *Segment) migrate(env environment.Environment) {
|
|||
segment.migrateColorOverride("version_mismatch_color", "{{ if .Mismatch }}%s{{ end }}")
|
||||
}
|
||||
case EXIT:
|
||||
template := segment.writer.Template()
|
||||
segment.migrateTemplate()
|
||||
template := segment.Properties.GetString(properties.SegmentTemplate, segment.writer.Template())
|
||||
displayExitCode := properties.Property("display_exit_code")
|
||||
if !segment.Properties.GetBool(displayExitCode, true) {
|
||||
delete(segment.Properties, displayExitCode)
|
||||
|
@ -144,7 +151,15 @@ func (segment *Segment) migratePropertyKey(oldProperty, newProperty properties.P
|
|||
}
|
||||
|
||||
func (segment *Segment) migrateTemplate() {
|
||||
defer segment.migratePreAndPostFix()
|
||||
if segment.hasProperty(properties.SegmentTemplate) {
|
||||
// existing template, ensure to add default pre/postfix values
|
||||
if !segment.hasProperty(prefix) {
|
||||
segment.Properties[prefix] = " "
|
||||
}
|
||||
if !segment.hasProperty(postfix) {
|
||||
segment.Properties[postfix] = " "
|
||||
}
|
||||
return
|
||||
}
|
||||
segment.Properties[properties.SegmentTemplate] = segment.writer.Template()
|
||||
|
@ -191,3 +206,21 @@ func (segment *Segment) migrateInlineColorOverride(property properties.Property,
|
|||
template = strings.ReplaceAll(template, old, colorTemplate)
|
||||
segment.Properties[properties.SegmentTemplate] = template
|
||||
}
|
||||
|
||||
func (segment *Segment) migratePreAndPostFix() {
|
||||
template := segment.Properties.GetString(properties.SegmentTemplate, segment.writer.Template())
|
||||
defaultValue := " "
|
||||
if segment.hasProperty(prefix) {
|
||||
prefix := segment.Properties.GetString(prefix, defaultValue)
|
||||
template = strings.TrimPrefix(template, defaultValue)
|
||||
template = prefix + template
|
||||
delete(segment.Properties, "prefix")
|
||||
}
|
||||
if segment.hasProperty(postfix) {
|
||||
postfix := segment.Properties.GetString(postfix, defaultValue)
|
||||
template = strings.TrimSuffix(template, defaultValue)
|
||||
template += postfix
|
||||
delete(segment.Properties, "postfix")
|
||||
}
|
||||
segment.Properties[properties.SegmentTemplate] = template
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
Case: "GIT",
|
||||
Expected: "{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} working {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} and{{ end }}{{ if .Staging.Changed }} staged {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} stash {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} worktree {{ .WorktreeCount }}{{ end }}", // nolint: lll
|
||||
Expected: " {{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} working {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} and{{ end }}{{ if .Staging.Changed }} staged {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} stash {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} worktree {{ .WorktreeCount }}{{ end }} ", // nolint: lll
|
||||
Type: GIT,
|
||||
Props: properties.Map{
|
||||
"local_working_icon": " working ",
|
||||
|
@ -207,7 +207,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "GIT - Staging and Working Color",
|
||||
Expected: "{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} working <#123456>{{ .Working.String }}</>{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} and{{ end }}{{ if .Staging.Changed }} staged <#123456>{{ .Staging.String }}</>{{ end }}{{ if gt .StashCount 0}} stash {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} worktree {{ .WorktreeCount }}{{ end }}", // nolint: lll
|
||||
Expected: " {{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} working <#123456>{{ .Working.String }}</>{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} and{{ end }}{{ if .Staging.Changed }} staged <#123456>{{ .Staging.String }}</>{{ end }}{{ if gt .StashCount 0}} stash {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} worktree {{ .WorktreeCount }}{{ end }} ", // nolint: lll
|
||||
Type: GIT,
|
||||
Props: properties.Map{
|
||||
"local_working_icon": " working ",
|
||||
|
@ -221,7 +221,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "EXIT - No exit Code with Icon overrides",
|
||||
Expected: "{{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }}",
|
||||
Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ",
|
||||
Type: EXIT,
|
||||
Props: properties.Map{
|
||||
"display_exit_code": false,
|
||||
|
@ -231,7 +231,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "EXIT - Always numeric",
|
||||
Expected: "{{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }}",
|
||||
Expected: " {{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }} ",
|
||||
Type: EXIT,
|
||||
Props: properties.Map{
|
||||
"always_numeric": true,
|
||||
|
@ -241,7 +241,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "BATTERY",
|
||||
Expected: `{{ if not .Error }}{{ $stateList := list "Discharging" "Full" }}{{ if has .State.String $stateList }}{{.Icon}}{{.Percentage}}{{ end }}{{ end }}{{.Error}}`,
|
||||
Expected: ` {{ if not .Error }}{{ $stateList := list "Discharging" "Full" }}{{ if has .State.String $stateList }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ end }}{{ .Error }} `,
|
||||
Type: BATTERY,
|
||||
Props: properties.Map{
|
||||
"display_charging": false,
|
||||
|
@ -249,7 +249,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "SESSION",
|
||||
Expected: "{{ if .SSHSession }}SSH {{ end }}{{ .UserName }}@{{ .HostName }}",
|
||||
Expected: " {{ if .SSHSession }}SSH {{ end }}{{ .UserName }}@{{ .HostName }} ",
|
||||
Type: SESSION,
|
||||
Props: properties.Map{
|
||||
"ssh_icon": "SSH ",
|
||||
|
@ -257,7 +257,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "SESSION no HOST",
|
||||
Expected: "{{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}",
|
||||
Expected: " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }} ",
|
||||
Type: SESSION,
|
||||
Props: properties.Map{
|
||||
"display_host": false,
|
||||
|
@ -265,7 +265,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "SESSION no USER",
|
||||
Expected: "{{ if .SSHSession }}\uf817 {{ end }}{{ .HostName }}",
|
||||
Expected: " {{ if .SSHSession }}\uf817 {{ end }}{{ .HostName }} ",
|
||||
Type: SESSION,
|
||||
Props: properties.Map{
|
||||
"display_user": false,
|
||||
|
@ -273,7 +273,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "SESSION no USER nor HOST",
|
||||
Expected: "{{ if .SSHSession }}\uf817 {{ end }}",
|
||||
Expected: " {{ if .SSHSession }}\uf817 {{ end }} ",
|
||||
Type: SESSION,
|
||||
Props: properties.Map{
|
||||
"display_user": false,
|
||||
|
@ -282,7 +282,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "SESSION - Color overrides",
|
||||
Expected: "{{ if .SSHSession }}\uf817 {{ end }}<#123456>{{ .UserName }}</>@<#789012>{{ .HostName }}</>",
|
||||
Expected: " {{ if .SSHSession }}\uf817 {{ end }}<#123456>{{ .UserName }}</>@<#789012>{{ .HostName }}</> ",
|
||||
Type: SESSION,
|
||||
Props: properties.Map{
|
||||
"user_color": "#123456",
|
||||
|
@ -337,3 +337,49 @@ func TestInlineColorOverride(t *testing.T) {
|
|||
assert.Equal(t, tc.Expected, segment.Properties[properties.SegmentTemplate], tc.Case)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigratePreAndPostfix(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected string
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "Pre and Postfix",
|
||||
Expected: "<background,transparent>\ue0b6</> \uf489 {{ .Name }} <transparent,background>\ue0b2</>",
|
||||
Props: properties.Map{
|
||||
"postfix": " <transparent,background>\ue0b2</>",
|
||||
"prefix": "<background,transparent>\ue0b6</> \uf489 ",
|
||||
"template": "{{ .Name }}",
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "Prefix",
|
||||
Expected: " {{ .Name }} ",
|
||||
Props: properties.Map{
|
||||
"prefix": " ",
|
||||
"template": "{{ .Name }}",
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "Postfix",
|
||||
Expected: " {{ .Name }} ",
|
||||
Props: properties.Map{
|
||||
"postfix": " ",
|
||||
"template": "{{ .Name }} ",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
segment := &Segment{
|
||||
Properties: tc.Props,
|
||||
writer: &MockedWriter{
|
||||
template: tc.Props.GetString(properties.SegmentTemplate, ""),
|
||||
},
|
||||
}
|
||||
segment.migrateTemplate()
|
||||
assert.Equal(t, tc.Expected, segment.Properties[properties.SegmentTemplate], tc.Case)
|
||||
assert.NotContains(t, segment.Properties, "prefix", tc.Case)
|
||||
assert.NotContains(t, segment.Properties, "postfix", tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,13 +169,6 @@ func (segment *Segment) enabled() bool {
|
|||
return segment.active
|
||||
}
|
||||
|
||||
func (segment *Segment) getValue(property properties.Property, defaultValue string) string {
|
||||
if value, ok := segment.Properties[property]; ok {
|
||||
return properties.ParseString(value, defaultValue)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func (segment *Segment) shouldIncludeFolder() bool {
|
||||
cwdIncluded := segment.cwdIncluded()
|
||||
cwdExcluded := segment.cwdExcluded()
|
||||
|
|
|
@ -23,10 +23,6 @@ type Property string
|
|||
const (
|
||||
// Style indicates with style to use
|
||||
Style Property = "style"
|
||||
// Prefix adds a text prefix to the segment
|
||||
Prefix Property = "prefix"
|
||||
// Postfix adds a text postfix to the segment
|
||||
Postfix Property = "postfix"
|
||||
// IncludeFolders folders to be included for the segment logic
|
||||
IncludeFolders Property = "include_folders"
|
||||
// ExcludeFolders folders to be excluded for the segment logic
|
||||
|
|
|
@ -20,7 +20,7 @@ const (
|
|||
)
|
||||
|
||||
func (a *Aws) Template() string {
|
||||
return "{{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }}"
|
||||
return " {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} "
|
||||
}
|
||||
|
||||
func (a *Aws) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -81,7 +81,7 @@ type AzurePowerShellSubscription struct {
|
|||
}
|
||||
|
||||
func (a *Az) Template() string {
|
||||
return "{{ .Name }}"
|
||||
return " {{ .Name }} "
|
||||
}
|
||||
|
||||
func (a *Az) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -28,7 +28,7 @@ const (
|
|||
)
|
||||
|
||||
func (b *Battery) Template() string {
|
||||
return "{{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}"
|
||||
return " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }} "
|
||||
}
|
||||
|
||||
func (b *Battery) Enabled() bool {
|
||||
|
|
|
@ -97,7 +97,7 @@ type Batch struct {
|
|||
}
|
||||
|
||||
func (bf *Brewfather) Template() string {
|
||||
return "{{ .StatusIcon }} {{ if .DaysBottledOrFermented }}{{ .DaysBottledOrFermented }}{{ .DayIcon }} {{ end }}{{ url .Recipe.Name .URL }} {{ printf \"%.1f\" .MeasuredAbv }}%{{ if and (.Reading) (eq .Status \"Fermenting\") }} {{ printf \"%.3f\" .Reading.Gravity }} {{ .Reading.Temperature }}\u00b0 {{ .TemperatureTrendIcon }}{{ end }}" // nolint:lll
|
||||
return " {{ .StatusIcon }} {{ if .DaysBottledOrFermented }}{{ .DaysBottledOrFermented }}{{ .DayIcon }} {{ end }}{{ url .Recipe.Name .URL }} {{ printf \"%.1f\" .MeasuredAbv }}%{{ if and (.Reading) (eq .Status \"Fermenting\") }} {{ printf \"%.3f\" .Reading.Gravity }} {{ .Reading.Temperature }}\u00b0 {{ .TemperatureTrendIcon }}{{ end }} " // nolint:lll
|
||||
}
|
||||
|
||||
func (bf *Brewfather) Enabled() bool {
|
||||
|
|
|
@ -21,7 +21,7 @@ const (
|
|||
)
|
||||
|
||||
func (c *Cmd) Template() string {
|
||||
return "{{ .Output }}"
|
||||
return " {{ .Output }} "
|
||||
}
|
||||
|
||||
func (c *Cmd) Enabled() bool {
|
||||
|
|
|
@ -13,7 +13,7 @@ type Dotnet struct {
|
|||
}
|
||||
|
||||
func (d *Dotnet) Template() string {
|
||||
return "{{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }}"
|
||||
return " {{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }} "
|
||||
}
|
||||
|
||||
func (d *Dotnet) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -62,7 +62,7 @@ func (t *Executiontime) Enabled() bool {
|
|||
}
|
||||
|
||||
func (t *Executiontime) Template() string {
|
||||
return "{{ .FormattedMs }}"
|
||||
return " {{ .FormattedMs }} "
|
||||
}
|
||||
|
||||
func (t *Executiontime) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -14,7 +14,7 @@ type Exit struct {
|
|||
}
|
||||
|
||||
func (e *Exit) Template() string {
|
||||
return "{{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }}"
|
||||
return " {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} "
|
||||
}
|
||||
|
||||
func (e *Exit) Enabled() bool {
|
||||
|
|
|
@ -108,7 +108,7 @@ const (
|
|||
)
|
||||
|
||||
func (g *Git) Template() string {
|
||||
return "{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uF692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }}" // nolint: lll
|
||||
return " {{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uF692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }} " // nolint: lll
|
||||
}
|
||||
|
||||
func (g *Git) Enabled() bool {
|
||||
|
|
|
@ -16,7 +16,7 @@ const (
|
|||
)
|
||||
|
||||
func (i *IPify) Template() string {
|
||||
return "{{ .IP }}"
|
||||
return " {{ .IP }} "
|
||||
}
|
||||
|
||||
func (i *IPify) Enabled() bool {
|
||||
|
|
|
@ -35,7 +35,7 @@ type KubeContext struct {
|
|||
}
|
||||
|
||||
func (k *Kubectl) Template() string {
|
||||
return "{{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }}"
|
||||
return " {{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }} "
|
||||
}
|
||||
|
||||
func (k *Kubectl) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestKubectlSegment(t *testing.T) {
|
|||
ParseKubeConfig: true,
|
||||
Kubeconfig: "currentcontextmarker" + lsep + "contextdefinitionincomplete",
|
||||
Files: testKubeConfigFiles,
|
||||
ExpectedString: "ctx :: :: :: ",
|
||||
ExpectedString: "ctx :: :: ::",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{Case: "disabled", Template: standardTemplate, KubectlExists: false, Context: "aaa", Namespace: "bbb", ExpectedEnabled: false},
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
languageTemplate = "{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}"
|
||||
languageTemplate = " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
|
||||
)
|
||||
|
||||
type loadContext func()
|
||||
|
|
|
@ -25,7 +25,7 @@ type VersionInfo struct {
|
|||
}
|
||||
|
||||
func (n *Nbgv) Template() string {
|
||||
return "{{ .Version }}"
|
||||
return " {{ .Version }} "
|
||||
}
|
||||
|
||||
func (n *Nbgv) Enabled() bool {
|
||||
|
|
|
@ -48,7 +48,7 @@ type NightscoutData struct {
|
|||
}
|
||||
|
||||
func (ns *Nightscout) Template() string {
|
||||
return "{{ .Sgv }}"
|
||||
return " {{ .Sgv }} "
|
||||
}
|
||||
|
||||
func (ns *Nightscout) Enabled() bool {
|
||||
|
|
|
@ -23,7 +23,7 @@ const (
|
|||
)
|
||||
|
||||
func (n *Node) Template() string {
|
||||
return "{{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }}"
|
||||
return " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} "
|
||||
}
|
||||
|
||||
func (n *Node) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -62,7 +62,7 @@ const (
|
|||
)
|
||||
|
||||
func (oi *Os) Template() string {
|
||||
return "{{ if .WSL }}WSL at {{ end }}{{.Icon}}"
|
||||
return " {{ if .WSL }}WSL at {{ end }}{{.Icon}} "
|
||||
}
|
||||
|
||||
func (oi *Os) Enabled() bool {
|
||||
|
|
|
@ -54,7 +54,7 @@ func (d *Owm) Enabled() bool {
|
|||
}
|
||||
|
||||
func (d *Owm) Template() string {
|
||||
return "{{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }})"
|
||||
return " {{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }}) "
|
||||
}
|
||||
|
||||
func (d *Owm) getResult() (*owmDataResponse, error) {
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestOWMSegmentSingle(t *testing.T) {
|
|||
{
|
||||
Case: "Sunny Display",
|
||||
JSONResponse: `{"weather":[{"icon":"01d"}],"main":{"temp":20}}`,
|
||||
ExpectedString: "\ufa98 ",
|
||||
ExpectedString: "\ufa98",
|
||||
ExpectedEnabled: true,
|
||||
Template: "{{.Weather}} ",
|
||||
},
|
||||
|
|
|
@ -57,7 +57,7 @@ const (
|
|||
)
|
||||
|
||||
func (pt *Path) Template() string {
|
||||
return "{{ .Path }}"
|
||||
return " {{ .Path }} "
|
||||
}
|
||||
|
||||
func (pt *Path) Enabled() bool {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"oh-my-posh/mock"
|
||||
"oh-my-posh/properties"
|
||||
"oh-my-posh/template"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -32,7 +33,7 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context
|
|||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return text
|
||||
return strings.TrimSpace(text)
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -312,7 +313,7 @@ func TestGetFullPath(t *testing.T) {
|
|||
|
||||
// StackCountEnabled=true and StackCount=2
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"},
|
||||
{Style: Full, Pwd: "", StackCount: 2, Expected: "2 "},
|
||||
{Style: Full, Pwd: "", StackCount: 2, Expected: "2"},
|
||||
{Style: Full, Pwd: "/", StackCount: 2, Expected: "2 /"},
|
||||
{Style: Full, Pwd: "/usr/home", StackCount: 2, Expected: "2 ~"},
|
||||
{Style: Full, Pwd: "/usr/home/abc", StackCount: 2, Expected: "2 ~/abc"},
|
||||
|
|
|
@ -43,7 +43,7 @@ func (p *Plastic) Init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
|
||||
func (p *Plastic) Template() string {
|
||||
return "{{ .Selector }}"
|
||||
return " {{ .Selector }} "
|
||||
}
|
||||
|
||||
func (p *Plastic) Enabled() bool {
|
||||
|
|
|
@ -18,7 +18,7 @@ const (
|
|||
)
|
||||
|
||||
func (p *PoshGit) Template() string {
|
||||
return "{{ .Status }}"
|
||||
return " {{ .Status }} "
|
||||
}
|
||||
|
||||
func (p *PoshGit) Enabled() bool {
|
||||
|
|
|
@ -17,7 +17,7 @@ const (
|
|||
)
|
||||
|
||||
func (p *Python) Template() string {
|
||||
return "{{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }}"
|
||||
return " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} "
|
||||
}
|
||||
|
||||
func (p *Python) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -11,7 +11,7 @@ type Root struct {
|
|||
}
|
||||
|
||||
func (rt *Root) Template() string {
|
||||
return "\uF0E7"
|
||||
return " \uF0E7 "
|
||||
}
|
||||
|
||||
func (rt *Root) Enabled() bool {
|
||||
|
|
|
@ -22,7 +22,7 @@ func (s *Session) Enabled() bool {
|
|||
}
|
||||
|
||||
func (s *Session) Template() string {
|
||||
return "{{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}@{{ .HostName }}"
|
||||
return " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}@{{ .HostName }} "
|
||||
}
|
||||
|
||||
func (s *Session) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -19,7 +19,7 @@ const (
|
|||
)
|
||||
|
||||
func (s *Shell) Template() string {
|
||||
return "{{ .Name }}"
|
||||
return " {{ .Name }} "
|
||||
}
|
||||
|
||||
func (s *Shell) Enabled() bool {
|
||||
|
|
|
@ -33,7 +33,7 @@ const (
|
|||
)
|
||||
|
||||
func (s *Spotify) Template() string {
|
||||
return "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }}"
|
||||
return " {{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} "
|
||||
}
|
||||
|
||||
func (s *Spotify) resolveIcon() {
|
||||
|
|
|
@ -25,7 +25,7 @@ func TestSpotifyStringPlayingSong(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSpotifyStringStoppedSong(t *testing.T) {
|
||||
expected := "\uf04d "
|
||||
expected := "\uf04d"
|
||||
env := new(mock.MockedEnvironment)
|
||||
s := &Spotify{
|
||||
MusicPlayer: MusicPlayer{
|
||||
|
|
|
@ -21,13 +21,13 @@ func TestSpotifyWsl(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
Case: "Spotify not running",
|
||||
ExpectedString: " - ",
|
||||
ExpectedString: "-",
|
||||
ExpectedEnabled: false,
|
||||
ExecOutput: "INFO: No tasks are running which match the specified criteria.\n",
|
||||
},
|
||||
{
|
||||
Case: "Spotify stopped/paused",
|
||||
ExpectedString: " - ",
|
||||
ExpectedString: "-",
|
||||
ExpectedEnabled: false,
|
||||
ExecOutput: `"Spotify.exe","21824","Console","1","124,928 K","Running","PC\user","0:09:44","Spotify Premium"
|
||||
"Spotify.exe","21876","Console","1","25,520 K","Running","PC\user","0:00:00","N/A"
|
||||
|
@ -49,7 +49,7 @@ func TestSpotifyWsl(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Case: "tasklist.exe not in path",
|
||||
ExpectedString: " - ",
|
||||
ExpectedString: "-",
|
||||
ExpectedEnabled: false,
|
||||
ExecOutput: ""},
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (a *AuthError) Error() string {
|
|||
}
|
||||
|
||||
func (s *Strava) Template() string {
|
||||
return "{{ if .Error }}{{ .Error }}{{ else }}{{ .Ago }}{{ end }}"
|
||||
return " {{ if .Error }}{{ .Error }}{{ else }}{{ .Ago }}{{ end }} "
|
||||
}
|
||||
|
||||
func (s *Strava) Enabled() bool {
|
||||
|
|
|
@ -36,7 +36,7 @@ const (
|
|||
)
|
||||
|
||||
func (s *SystemInfo) Template() string {
|
||||
return "{{ round .PhysicalPercentUsed .Precision }}"
|
||||
return " {{ round .PhysicalPercentUsed .Precision }} "
|
||||
}
|
||||
|
||||
func (s *SystemInfo) Enabled() bool {
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestSysInfo(t *testing.T) {
|
|||
{Case: "not enabled", ExpectDisabled: true, SysInfo: SystemInfo{PhysicalPercentUsed: 0, SwapPercentUsed: 0}},
|
||||
{
|
||||
Case: "2 physical cpus",
|
||||
ExpectedString: "1200 1200 ",
|
||||
ExpectedString: "1200 1200",
|
||||
Template: "{{range $cpu := .CPU}}{{round $cpu.Mhz 2 }} {{end}}",
|
||||
SysInfo: SystemInfo{CPU: []cpu.InfoStat{{Mhz: 1200}, {Mhz: 1200}}},
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ type Terraform struct {
|
|||
}
|
||||
|
||||
func (tf *Terraform) Template() string {
|
||||
return "{{ .WorkspaceName }}"
|
||||
return " {{ .WorkspaceName }} "
|
||||
}
|
||||
|
||||
func (tf *Terraform) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -13,7 +13,7 @@ type Text struct {
|
|||
}
|
||||
|
||||
func (t *Text) Template() string {
|
||||
return "{{ .Text }}"
|
||||
return " {{ .Text }} "
|
||||
}
|
||||
|
||||
func (t *Text) Enabled() bool {
|
||||
|
|
|
@ -20,7 +20,7 @@ const (
|
|||
)
|
||||
|
||||
func (t *Time) Template() string {
|
||||
return "{{ .CurrentDate | date .Format }}"
|
||||
return " {{ .CurrentDate | date .Format }} "
|
||||
}
|
||||
|
||||
func (t *Time) Enabled() bool {
|
||||
|
|
|
@ -25,7 +25,7 @@ type wtData struct {
|
|||
}
|
||||
|
||||
func (w *Wakatime) Template() string {
|
||||
return "{{ secondsRound .CummulativeTotal.Seconds }}"
|
||||
return " {{ secondsRound .CummulativeTotal.Seconds }} "
|
||||
}
|
||||
|
||||
func (w *Wakatime) Enabled() bool {
|
||||
|
|
|
@ -15,7 +15,7 @@ type Wifi struct {
|
|||
}
|
||||
|
||||
const (
|
||||
defaultTemplate = "{{ if .Error }}{{ .Error }}{{ else }}\uFAA8 {{ .SSID }} {{ .Signal }}% {{ .ReceiveRate }}Mbps{{ end }}"
|
||||
defaultTemplate = " {{ if .Error }}{{ .Error }}{{ else }}\uFAA8 {{ .SSID }} {{ .Signal }}% {{ .ReceiveRate }}Mbps{{ end }} "
|
||||
)
|
||||
|
||||
func (w *Wifi) Template() string {
|
||||
|
|
|
@ -22,7 +22,7 @@ const (
|
|||
)
|
||||
|
||||
func (wr *WindowsRegistry) Template() string {
|
||||
return "{{ .Value }}"
|
||||
return " {{ .Value }} "
|
||||
}
|
||||
|
||||
func (wr *WindowsRegistry) Init(props properties.Properties, env environment.Environment) {
|
||||
|
|
|
@ -19,7 +19,7 @@ const (
|
|||
)
|
||||
|
||||
func (y *Ytm) Template() string {
|
||||
return "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }}"
|
||||
return " {{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} "
|
||||
}
|
||||
|
||||
func (y *Ytm) Enabled() bool {
|
||||
|
|
Loading…
Reference in a new issue