mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
parent
7e5f5246cc
commit
c729788676
|
@ -101,6 +101,8 @@ const (
|
||||||
EXECUTIONTIME SegmentType = "executiontime"
|
EXECUTIONTIME SegmentType = "executiontime"
|
||||||
// EXIT writes the last exit code
|
// EXIT writes the last exit code
|
||||||
EXIT SegmentType = "exit"
|
EXIT SegmentType = "exit"
|
||||||
|
// FLUTTER writes the flutter version
|
||||||
|
FLUTTER SegmentType = "flutter"
|
||||||
// GIT represents the git status and information
|
// GIT represents the git status and information
|
||||||
GIT SegmentType = "git"
|
GIT SegmentType = "git"
|
||||||
// GOLANG writes which go version is currently active
|
// GOLANG writes which go version is currently active
|
||||||
|
@ -261,6 +263,7 @@ func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error
|
||||||
DOTNET: &segments.Dotnet{},
|
DOTNET: &segments.Dotnet{},
|
||||||
EXECUTIONTIME: &segments.Executiontime{},
|
EXECUTIONTIME: &segments.Executiontime{},
|
||||||
EXIT: &segments.Exit{},
|
EXIT: &segments.Exit{},
|
||||||
|
FLUTTER: &segments.Flutter{},
|
||||||
GIT: &segments.Git{},
|
GIT: &segments.Git{},
|
||||||
GOLANG: &segments.Golang{},
|
GOLANG: &segments.Golang{},
|
||||||
HASKELL: &segments.Haskell{},
|
HASKELL: &segments.Haskell{},
|
||||||
|
|
|
@ -5,6 +5,11 @@ import (
|
||||||
"oh-my-posh/properties"
|
"oh-my-posh/properties"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
dartExtensions = []string{"*.dart", "pubspec.yaml", "pubspec.yml", "pubspec.lock"}
|
||||||
|
dartFolders = []string{".dart_tool"}
|
||||||
|
)
|
||||||
|
|
||||||
type Dart struct {
|
type Dart struct {
|
||||||
language
|
language
|
||||||
}
|
}
|
||||||
|
@ -17,8 +22,8 @@ func (d *Dart) Init(props properties.Properties, env environment.Environment) {
|
||||||
d.language = language{
|
d.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
extensions: []string{"*.dart", "pubspec.yaml", "pubspec.yml", "pubspec.lock"},
|
extensions: dartExtensions,
|
||||||
folders: []string{".dart_tool"},
|
folders: dartFolders,
|
||||||
commands: []*cmd{
|
commands: []*cmd{
|
||||||
{
|
{
|
||||||
executable: "dart",
|
executable: "dart",
|
||||||
|
|
35
src/segments/flutter.go
Normal file
35
src/segments/flutter.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"oh-my-posh/environment"
|
||||||
|
"oh-my-posh/properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Flutter struct {
|
||||||
|
language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Flutter) Template() string {
|
||||||
|
return languageTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Flutter) Init(props properties.Properties, env environment.Environment) {
|
||||||
|
f.language = language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: dartExtensions,
|
||||||
|
folders: dartFolders,
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "flutter",
|
||||||
|
args: []string{"--version"},
|
||||||
|
regex: `Flutter (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
versionURLTemplate: "https://github.com/flutter/flutter/releases/tag/{{ .Major }}.{{ .Minor }}.{{ .Patch }}",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Flutter) Enabled() bool {
|
||||||
|
return f.language.Enabled()
|
||||||
|
}
|
31
src/segments/flutter_test.go
Normal file
31
src/segments/flutter_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFlutter(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "Flutter 2.10.4", ExpectedString: "2.10.4", Version: "Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "flutter",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.dart",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
d := &Flutter{}
|
||||||
|
d.Init(props, env)
|
||||||
|
assert.True(t, d.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, renderTemplate(env, d.Template(), d), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
56
website/docs/segments/flutter.md
Normal file
56
website/docs/segments/flutter.md
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
---
|
||||||
|
id: flutter
|
||||||
|
title: Flutter
|
||||||
|
sidebar_label: Flutter
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active dart version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "flutter",
|
||||||
|
"style": "powerline",
|
||||||
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"foreground": "#ffffff",
|
||||||
|
"background": "#06A4CE",
|
||||||
|
"template": " \ue28e {{ .Full }} "
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
|
||||||
|
- fetch_version: `boolean` - fetch the dart version - defaults to `true`
|
||||||
|
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
|
||||||
|
- display_mode: `string` - determines when the segment is displayed
|
||||||
|
- `always`: the segment is always displayed
|
||||||
|
- `files`: the segment is only displayed when `*.dart`, `pubspec.yaml`, `pubspec.yml`, `pubspec.lock` files or the `.dart_tool`
|
||||||
|
folder are present (default)
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- `.Full`: `string` - the full version
|
||||||
|
- `.Major`: `string` - major number
|
||||||
|
- `.Minor`: `string` - minor number
|
||||||
|
- `.Patch`: `string` - patch 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
|
|
@ -66,6 +66,7 @@ module.exports = {
|
||||||
"segments/dotnet",
|
"segments/dotnet",
|
||||||
"segments/executiontime",
|
"segments/executiontime",
|
||||||
"segments/exit",
|
"segments/exit",
|
||||||
|
"segments/flutter",
|
||||||
"segments/git",
|
"segments/git",
|
||||||
"segments/poshgit",
|
"segments/poshgit",
|
||||||
"segments/golang",
|
"segments/golang",
|
||||||
|
|
Loading…
Reference in a new issue