Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config/segment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func init() {
gob.Register(&segments.Todoist{})
gob.Register(&segments.UI5Tooling{})
gob.Register(&segments.Umbraco{})
gob.Register(&segments.Uno{})
gob.Register(&segments.Unity{})
gob.Register(&segments.Upgrade{})
gob.Register(&segments.UpgradeCache{})
Expand Down Expand Up @@ -349,6 +350,8 @@ const (
UI5TOOLING SegmentType = "ui5tooling"
// UMBRACO writes the Umbraco version if Umbraco is present
UMBRACO SegmentType = "umbraco"
// UNO writes the Uno.Sdk version from global.json
UNO SegmentType = "uno"
// UNITY writes which Unity version is currently active
UNITY SegmentType = "unity"
// UPGRADE lets you know if you can upgrade Oh My Posh
Expand Down Expand Up @@ -473,6 +476,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
TODOIST: func() SegmentWriter { return &segments.Todoist{} },
UI5TOOLING: func() SegmentWriter { return &segments.UI5Tooling{} },
UMBRACO: func() SegmentWriter { return &segments.Umbraco{} },
UNO: func() SegmentWriter { return &segments.Uno{} },
UNITY: func() SegmentWriter { return &segments.Unity{} },
UPGRADE: func() SegmentWriter { return &segments.Upgrade{} },
V: func() SegmentWriter { return &segments.V{} },
Expand Down
39 changes: 39 additions & 0 deletions src/segments/uno.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package segments

import (
"encoding/json"

"github.com/gookit/goutil/jsonutil"
)

type unoGlobalJSON struct {
MSBuildSDKs map[string]string `json:"msbuild-sdks"`
}

type Uno struct {
Base

Version string
}

func (u *Uno) Template() string {
return " {{ .Version }} "
}

func (u *Uno) Enabled() bool {
file, err := u.env.HasParentFilePath("global.json", false)
if err != nil {
return false
}

content := jsonutil.StripComments(u.env.FileContent(file.Path))

var globalJSON unoGlobalJSON
err = json.Unmarshal([]byte(content), &globalJSON)
if err != nil {
return false
}

u.Version = globalJSON.MSBuildSDKs["Uno.Sdk"]
return len(u.Version) > 0
}
85 changes: 85 additions & 0 deletions src/segments/uno_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package segments

import (
"errors"
"testing"

"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/runtime/mock"
"github.com/jandedobbeleer/oh-my-posh/src/segments/options"
"github.com/stretchr/testify/assert"
)

func TestUnoSegment(t *testing.T) {
cases := []struct {
Case string
GlobalJSON string
ExpectedVersion string
ExpectedEnabled bool
HasGlobalJSON bool
}{
{
Case: "no global.json found",
ExpectedEnabled: false,
},
{
Case: "invalid global.json",
HasGlobalJSON: true,
GlobalJSON: `invalid json`,
ExpectedEnabled: false,
},
{
Case: "global.json without Uno.Sdk",
HasGlobalJSON: true,
GlobalJSON: `{"msbuild-sdks":{"Another.Sdk":"1.0.0"}}`,
ExpectedEnabled: false,
},
{
Case: "valid Uno.Sdk in global.json",
HasGlobalJSON: true,
GlobalJSON: `{"msbuild-sdks":{"Uno.Sdk":"6.5.31"}}`,
ExpectedVersion: "6.5.31",
ExpectedEnabled: true,
},
{
Case: "valid dotnet sdk global.json without Uno.Sdk",
HasGlobalJSON: true,
GlobalJSON: `{"sdk":{ "version": "10.0.103" }}`,
ExpectedEnabled: false,
},
{
Case: "valid Uno.Sdk in commented global.json",
HasGlobalJSON: true,
GlobalJSON: `{
// Uno SDK version
"msbuild-sdks": {
"Uno.Sdk": "6.5.31"
}
}`,
ExpectedVersion: "6.5.31",
ExpectedEnabled: true,
},
}

for _, tc := range cases {
env := new(mock.Environment)

if tc.HasGlobalJSON {
file := &runtime.FileInfo{Path: "/test/global.json"}
env.On("HasParentFilePath", "global.json", false).Return(file, nil)
env.On("FileContent", "/test/global.json").Return(tc.GlobalJSON)
} else {
env.On("HasParentFilePath", "global.json", false).Return(&runtime.FileInfo{}, errors.New("file not found"))
}

uno := &Uno{}
uno.Init(options.Map{}, env)

assert.Equal(t, tc.ExpectedEnabled, uno.Enabled(), tc.Case)
assert.Equal(t, tc.ExpectedVersion, uno.Version, tc.Case)

if tc.ExpectedEnabled {
assert.Equal(t, tc.ExpectedVersion, renderTemplate(env, "{{ .Version }}", uno), tc.Case)
}
}
}
14 changes: 14 additions & 0 deletions themes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
"todoist",
"ui5tooling",
"umbraco",
"uno",
"unity",
"upgrade",
"v",
Expand Down Expand Up @@ -4547,6 +4548,19 @@
"description": "https://ohmyposh.dev/docs/segments/cli/umbraco"
}
},
{
"if": {
"properties": {
"type": {
"const": "uno"
}
}
},
"then": {
"title": "Uno Platform Segment",
"description": "https://ohmyposh.dev/docs/segments/cli/uno"
}
},
{
"if": {
"properties": {
Expand Down
43 changes: 43 additions & 0 deletions website/docs/segments/cli/uno.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
id: uno
title: Uno Platform
sidebar_label: Uno Platform
---

## What

Display the currently active [Uno Platform][uno] SDK version.

## Sample Configuration

import Config from "@site/src/components/Config.js";

<Config
data={{
type: "uno",
style: "powerline",
powerline_symbol: "\uE0B0",
foreground: "#ffffff",
background: "#7D4698",
template: " \ue799 {{ .Version }} ",
}}
/>

## Template ([info][templates])

:::note default template

```template
{{ .Version }}
```

:::

### Properties

| Name | Type | Description |
| ---------- | -------- | ------------------------- |
| `.Version` | `string` | the Uno Platform SDK version |

[uno]: https://platform.uno/
[templates]: /docs/configuration/templates
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default {
"segments/cli/terraform",
"segments/cli/ui5tooling",
"segments/cli/umbraco",
"segments/cli/uno",
"segments/cli/unity",
"segments/cli/xmake",
"segments/cli/yarn",
Expand Down