Skip to content

Commit

Permalink
feat: add dart support
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed May 14, 2021
1 parent d96cb79 commit 4030c32
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 2 deletions.
34 changes: 34 additions & 0 deletions docs/docs/segment-dart.md
@@ -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)
1 change: 1 addition & 0 deletions docs/sidebars.js
Expand Up @@ -33,6 +33,7 @@ module.exports = {
"battery",
"command",
"crystal",
"dart",
"dotnet",
"environment",
"executiontime",
Expand Down
2 changes: 1 addition & 1 deletion src/environment.go
Expand Up @@ -204,7 +204,7 @@ func (env *environment) runCommand(command string, args ...string) (string, erro
if cmd, ok := env.cmdCache.get(command); ok {
command = cmd
}
out, err := exec.Command(command, args...).Output()
out, err := exec.Command(command, args...).CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return "", &commandError{
Expand Down
3 changes: 3 additions & 0 deletions src/segment.go
Expand Up @@ -113,6 +113,8 @@ const (
AZFunc SegmentType = "azfunc"
// Crystal writes the active crystal version
Crystal SegmentType = "crystal"
// Dart writes the active dart version
Dart SegmentType = "dart"
)

func (segment *Segment) string() string {
Expand Down Expand Up @@ -239,6 +241,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
PoshGit: &poshgit{},
AZFunc: &azfunc{},
Crystal: &crystal{},
Dart: &dart{},
}
if writer, ok := functions[segment.Type]; ok {
props := &properties{
Expand Down
29 changes: 29 additions & 0 deletions src/segment_dart.go
@@ -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 changes: 31 additions & 0 deletions src/segment_dart_test.go
@@ -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))
}
}
29 changes: 28 additions & 1 deletion themes/schema.json
Expand Up @@ -153,7 +153,8 @@
"java",
"poshgit",
"azfunc",
"crystal"
"crystal",
"dart"
]
},
"style": {
Expand Down Expand Up @@ -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": {
"properties": {
Expand Down

0 comments on commit 4030c32

Please sign in to comment.