mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(segment): add xmake
This commit is contained in:
parent
07acb9b0f6
commit
ae4f8133ca
|
@ -198,6 +198,8 @@ const (
|
||||||
WINREG SegmentType = "winreg"
|
WINREG SegmentType = "winreg"
|
||||||
// WITHINGS queries the Withings API.
|
// WITHINGS queries the Withings API.
|
||||||
WITHINGS SegmentType = "withings"
|
WITHINGS SegmentType = "withings"
|
||||||
|
// XMAKE write the xmake version if xmake.lua is present
|
||||||
|
XMAKE SegmentType = "xmake"
|
||||||
// YTM writes YouTube Music information and status
|
// YTM writes YouTube Music information and status
|
||||||
YTM SegmentType = "ytm"
|
YTM SegmentType = "ytm"
|
||||||
)
|
)
|
||||||
|
@ -329,6 +331,7 @@ func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error
|
||||||
WAKATIME: &segments.Wakatime{},
|
WAKATIME: &segments.Wakatime{},
|
||||||
WINREG: &segments.WindowsRegistry{},
|
WINREG: &segments.WindowsRegistry{},
|
||||||
WITHINGS: &segments.Withings{},
|
WITHINGS: &segments.Withings{},
|
||||||
|
XMAKE: &segments.XMake{},
|
||||||
YTM: &segments.Ytm{},
|
YTM: &segments.Ytm{},
|
||||||
}
|
}
|
||||||
if segment.Properties == nil {
|
if segment.Properties == nil {
|
||||||
|
|
33
src/segments/xmake.go
Normal file
33
src/segments/xmake.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"oh-my-posh/environment"
|
||||||
|
"oh-my-posh/properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
type XMake struct {
|
||||||
|
language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *XMake) Template() string {
|
||||||
|
return languageTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *XMake) Init(props properties.Properties, env environment.Environment) {
|
||||||
|
x.language = language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: []string{"xmake.lua"},
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "xmake",
|
||||||
|
args: []string{"--version"},
|
||||||
|
regex: `xmake v(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *XMake) Enabled() bool {
|
||||||
|
return x.language.Enabled()
|
||||||
|
}
|
31
src/segments/xmake_test.go
Normal file
31
src/segments/xmake_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestXMake(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "XMake 2.7.2-dev", ExpectedString: "2.7.2", Version: "xmake v2.7.2+dev.605b8e3e0"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "xmake",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "xmake.lua",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
x := &XMake{}
|
||||||
|
x.Init(props, env)
|
||||||
|
assert.True(t, x.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, renderTemplate(env, x.Template(), x), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
|
@ -277,6 +277,7 @@
|
||||||
"wakatime",
|
"wakatime",
|
||||||
"winreg",
|
"winreg",
|
||||||
"withings",
|
"withings",
|
||||||
|
"xmake",
|
||||||
"ytm"
|
"ytm"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1261,6 +1262,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"const": "xmake"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"title": "XMake Segment",
|
||||||
|
"description": "https://ohmyposh.dev/docs/segments/xmake",
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"home_enabled": {
|
||||||
|
"$ref": "#/definitions/home_enabled"
|
||||||
|
},
|
||||||
|
"fetch_version": {
|
||||||
|
"$ref": "#/definitions/fetch_version"
|
||||||
|
},
|
||||||
|
"display_mode": {
|
||||||
|
"$ref": "#/definitions/display_mode"
|
||||||
|
},
|
||||||
|
"missing_command_text": {
|
||||||
|
"$ref": "#/definitions/missing_command_text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"if": {
|
"if": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
53
website/docs/segments/xmake.mdx
Normal file
53
website/docs/segments/xmake.mdx
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
---
|
||||||
|
id: xmake
|
||||||
|
title: XMake
|
||||||
|
sidebar_label: XMake
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active xmake version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "xmake",
|
||||||
|
"style": "powerline",
|
||||||
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"foreground": "#e0f2f1",
|
||||||
|
"background": "#22a079",
|
||||||
|
"template": " xmake v{{ .Full }} "
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `home_enabled` | `boolean` | display the segment in the HOME folder or not - defaults to `false` |
|
||||||
|
| `fetch_version` | `boolean` | display the xmake version (`xmake --version`) - defaults to `true` |
|
||||||
|
| `missing_command_text` | `string` | text to display when the command is missing - defaults to empty |
|
||||||
|
| `display_mode` | `string` | <ul><li>`always`: the segment is always displayed</li><li>`files`: the segment is only displayed when a `xmake.lua` file is present (**default**)</li></ul> |
|
||||||
|
|
||||||
|
## Template ([into][templates])
|
||||||
|
|
||||||
|
:::note default template
|
||||||
|
|
||||||
|
```template
|
||||||
|
{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| -------- | -------- | -------------------------------------------------- |
|
||||||
|
| `.Full` | `string` | the full version |
|
||||||
|
| `.Major` | `string` | major number |
|
||||||
|
| `.Minor` | `string` | minor number |
|
||||||
|
| `.Patch` | `string` | patch number |
|
||||||
|
| `.Error` | `string` | error encountered when fetching the version string |
|
||||||
|
|
||||||
|
[templates]: /docs/configuration/templates
|
|
@ -113,6 +113,7 @@ module.exports = {
|
||||||
"segments/wakatime",
|
"segments/wakatime",
|
||||||
"segments/withings",
|
"segments/withings",
|
||||||
"segments/winreg",
|
"segments/winreg",
|
||||||
|
"segments/xmake",
|
||||||
"segments/ytm",
|
"segments/ytm",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue