mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat: add dart support
This commit is contained in:
parent
d96cb7989a
commit
4030c32279
34
docs/docs/segment-dart.md
Normal file
34
docs/docs/segment-dart.md
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
id: dart
|
||||||
|
title: Dart
|
||||||
|
sidebar_label: Dart
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active dart version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "dart",
|
||||||
|
"style": "powerline",
|
||||||
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"foreground": "#ffffff",
|
||||||
|
"background": "#06A4CE",
|
||||||
|
"properties": {
|
||||||
|
"prefix": " \uE798 "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
- display_version: `boolean` - display the julia version - defaults to `true`
|
||||||
|
- display_error: `boolean` - show the error context when failing to retrieve the version information - 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)
|
|
@ -33,6 +33,7 @@ module.exports = {
|
||||||
"battery",
|
"battery",
|
||||||
"command",
|
"command",
|
||||||
"crystal",
|
"crystal",
|
||||||
|
"dart",
|
||||||
"dotnet",
|
"dotnet",
|
||||||
"environment",
|
"environment",
|
||||||
"executiontime",
|
"executiontime",
|
||||||
|
|
|
@ -204,7 +204,7 @@ func (env *environment) runCommand(command string, args ...string) (string, erro
|
||||||
if cmd, ok := env.cmdCache.get(command); ok {
|
if cmd, ok := env.cmdCache.get(command); ok {
|
||||||
command = cmd
|
command = cmd
|
||||||
}
|
}
|
||||||
out, err := exec.Command(command, args...).Output()
|
out, err := exec.Command(command, args...).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||||
return "", &commandError{
|
return "", &commandError{
|
||||||
|
|
|
@ -113,6 +113,8 @@ const (
|
||||||
AZFunc SegmentType = "azfunc"
|
AZFunc SegmentType = "azfunc"
|
||||||
// Crystal writes the active crystal version
|
// Crystal writes the active crystal version
|
||||||
Crystal SegmentType = "crystal"
|
Crystal SegmentType = "crystal"
|
||||||
|
// Dart writes the active dart version
|
||||||
|
Dart SegmentType = "dart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (segment *Segment) string() string {
|
func (segment *Segment) string() string {
|
||||||
|
@ -239,6 +241,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
|
||||||
PoshGit: &poshgit{},
|
PoshGit: &poshgit{},
|
||||||
AZFunc: &azfunc{},
|
AZFunc: &azfunc{},
|
||||||
Crystal: &crystal{},
|
Crystal: &crystal{},
|
||||||
|
Dart: &dart{},
|
||||||
}
|
}
|
||||||
if writer, ok := functions[segment.Type]; ok {
|
if writer, ok := functions[segment.Type]; ok {
|
||||||
props := &properties{
|
props := &properties{
|
||||||
|
|
29
src/segment_dart.go
Normal file
29
src/segment_dart.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
type dart struct {
|
||||||
|
language *language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dart) string() string {
|
||||||
|
return d.language.string()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dart) init(props *properties, env environmentInfo) {
|
||||||
|
d.language = &language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: []string{"*.dart", "pubspec.yaml", "pubspec.yml", "pubspec.lock", ".dart_tool"},
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "dart",
|
||||||
|
args: []string{"--version"},
|
||||||
|
regex: `Dart SDK version: (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
versionURLTemplate: "[%s](https://dart.dev/guides/language/evolution#dart-%s%s)",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dart) enabled() bool {
|
||||||
|
return d.language.enabled()
|
||||||
|
}
|
31
src/segment_dart_test.go
Normal file
31
src/segment_dart_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDart(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "Dart 2.12.4", ExpectedString: "2.12.4", Version: "Dart SDK version: 2.12.4 (stable) (Thu Apr 15 12:26:53 2021 +0200) on \"macos_x64\""},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "dart",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.dart",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
d := &dart{}
|
||||||
|
d.init(props, env)
|
||||||
|
assert.True(t, d.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, d.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
|
@ -153,7 +153,8 @@
|
||||||
"java",
|
"java",
|
||||||
"poshgit",
|
"poshgit",
|
||||||
"azfunc",
|
"azfunc",
|
||||||
"crystal"
|
"crystal",
|
||||||
|
"dart"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"style": {
|
"style": {
|
||||||
|
@ -691,6 +692,32 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"type": { "const": "dart" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"title": "Dart Segment",
|
||||||
|
"description": "https://ohmyposh.dev/docs/dart",
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"display_version": {
|
||||||
|
"$ref": "#/definitions/display_version"
|
||||||
|
},
|
||||||
|
"display_mode": {
|
||||||
|
"$ref": "#/definitions/display_mode"
|
||||||
|
},
|
||||||
|
"missing_command_text": {
|
||||||
|
"$ref": "#/definitions/missing_command_text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"if": {
|
"if": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
Loading…
Reference in a new issue