mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
2751a243ef
commit
a2353d93e7
|
@ -216,6 +216,8 @@ const (
|
||||||
TIME SegmentType = "time"
|
TIME SegmentType = "time"
|
||||||
// UI5 Tooling segment
|
// UI5 Tooling segment
|
||||||
UI5TOOLING SegmentType = "ui5tooling"
|
UI5TOOLING SegmentType = "ui5tooling"
|
||||||
|
// VALA writes the active vala version
|
||||||
|
VALA SegmentType = "vala"
|
||||||
// WAKATIME writes tracked time spend in dev editors
|
// WAKATIME writes tracked time spend in dev editors
|
||||||
WAKATIME SegmentType = "wakatime"
|
WAKATIME SegmentType = "wakatime"
|
||||||
// WINREG queries the Windows registry.
|
// WINREG queries the Windows registry.
|
||||||
|
@ -292,6 +294,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
|
||||||
TEXT: func() SegmentWriter { return &segments.Text{} },
|
TEXT: func() SegmentWriter { return &segments.Text{} },
|
||||||
TIME: func() SegmentWriter { return &segments.Time{} },
|
TIME: func() SegmentWriter { return &segments.Time{} },
|
||||||
UI5TOOLING: func() SegmentWriter { return &segments.UI5Tooling{} },
|
UI5TOOLING: func() SegmentWriter { return &segments.UI5Tooling{} },
|
||||||
|
VALA: func() SegmentWriter { return &segments.Vala{} },
|
||||||
WAKATIME: func() SegmentWriter { return &segments.Wakatime{} },
|
WAKATIME: func() SegmentWriter { return &segments.Wakatime{} },
|
||||||
WINREG: func() SegmentWriter { return &segments.WindowsRegistry{} },
|
WINREG: func() SegmentWriter { return &segments.WindowsRegistry{} },
|
||||||
WITHINGS: func() SegmentWriter { return &segments.Withings{} },
|
WITHINGS: func() SegmentWriter { return &segments.Withings{} },
|
||||||
|
|
34
src/segments/vala.go
Normal file
34
src/segments/vala.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Vala struct {
|
||||||
|
language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Vala) Template() string {
|
||||||
|
return languageTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Vala) Init(props properties.Properties, env platform.Environment) {
|
||||||
|
v.language = language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: []string{"*.vala"},
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "vala",
|
||||||
|
args: []string{"--version"},
|
||||||
|
regex: `Vala (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
versionURLTemplate: "https://gitlab.gnome.org/GNOME/vala/raw/{{ .Major }}.{{ .Minor }}/NEWS",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Vala) Enabled() bool {
|
||||||
|
return v.language.Enabled()
|
||||||
|
}
|
35
src/segments/vala_test.go
Normal file
35
src/segments/vala_test.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestVala(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Case: "vala 0.48.17",
|
||||||
|
ExpectedString: "0.48.17",
|
||||||
|
Version: "Vala 0.48.17",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "vala",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.vala",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
v := &Vala{}
|
||||||
|
v.Init(props, env)
|
||||||
|
assert.True(t, v.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, renderTemplate(env, v.Template(), v), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
|
@ -2672,6 +2672,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"const": "vala"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"title": "Vala Segment",
|
||||||
|
"description": "https://ohmyposh.dev/docs/segments/vala",
|
||||||
|
"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": {
|
||||||
|
|
55
website/docs/segments/vala.mdx
Normal file
55
website/docs/segments/vala.mdx
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
---
|
||||||
|
id: vala
|
||||||
|
title: Vala
|
||||||
|
sidebar_label: Vala
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active vala version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "vala",
|
||||||
|
"style": "powerline",
|
||||||
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"foreground": "#ffffff",
|
||||||
|
"background": "#5E20A4",
|
||||||
|
"template": " \ue69e {{ .Full }} "
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `home_enabled` | `boolean` | display the segment in the HOME folder or not - defaults to `false` |
|
||||||
|
| `fetch_version` | `boolean` | fetch the flutter 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 `*.vala` files are present (**default**)</li></ul> |
|
||||||
|
| `version_url_template` | `string` | a go [text/template][go-text-template] [template][templates] that creates the URL of the version info / release notes |
|
||||||
|
|
||||||
|
## Template ([info][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 |
|
||||||
|
| `.URL` | `string` | URL of the version info / release notes |
|
||||||
|
| `.Error` | `string` | error encountered when fetching the version string |
|
||||||
|
|
||||||
|
[go-text-template]: https://golang.org/pkg/text/template/
|
||||||
|
[templates]: /docs/configuration/templates
|
|
@ -112,6 +112,7 @@ module.exports = {
|
||||||
"segments/text",
|
"segments/text",
|
||||||
"segments/time",
|
"segments/time",
|
||||||
"segments/ui5tooling",
|
"segments/ui5tooling",
|
||||||
|
"segments/vala",
|
||||||
"segments/wakatime",
|
"segments/wakatime",
|
||||||
"segments/withings",
|
"segments/withings",
|
||||||
"segments/winreg",
|
"segments/winreg",
|
||||||
|
|
Loading…
Reference in a new issue