mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-13 14:34:06 -08:00
parent
971f4dfd87
commit
c3c72b17b3
|
@ -99,6 +99,8 @@ const (
|
||||||
CRYSTAL SegmentType = "crystal"
|
CRYSTAL SegmentType = "crystal"
|
||||||
// DART writes the active dart version
|
// DART writes the active dart version
|
||||||
DART SegmentType = "dart"
|
DART SegmentType = "dart"
|
||||||
|
// DENO writes the active deno version
|
||||||
|
DENO SegmentType = "deno"
|
||||||
// DOTNET writes which dotnet version is currently active
|
// DOTNET writes which dotnet version is currently active
|
||||||
DOTNET SegmentType = "dotnet"
|
DOTNET SegmentType = "dotnet"
|
||||||
// EXECUTIONTIME writes the execution time of the last run command
|
// EXECUTIONTIME writes the execution time of the last run command
|
||||||
|
@ -279,6 +281,7 @@ func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error
|
||||||
CRYSTAL: &segments.Crystal{},
|
CRYSTAL: &segments.Crystal{},
|
||||||
CMAKE: &segments.Cmake{},
|
CMAKE: &segments.Cmake{},
|
||||||
DART: &segments.Dart{},
|
DART: &segments.Dart{},
|
||||||
|
DENO: &segments.Deno{},
|
||||||
DOTNET: &segments.Dotnet{},
|
DOTNET: &segments.Dotnet{},
|
||||||
EXECUTIONTIME: &segments.Executiontime{},
|
EXECUTIONTIME: &segments.Executiontime{},
|
||||||
EXIT: &segments.Exit{},
|
EXIT: &segments.Exit{},
|
||||||
|
|
|
@ -34,5 +34,6 @@ func (a *Angular) Enabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Angular) getVersion() (string, error) {
|
func (a *Angular) getVersion() (string, error) {
|
||||||
|
// tested by nx_test.go
|
||||||
return getNodePackageVersion(a.language.env, filepath.Join("@angular", "core"))
|
return getNodePackageVersion(a.language.env, filepath.Join("@angular", "core"))
|
||||||
}
|
}
|
||||||
|
|
34
src/segments/deno.go
Normal file
34
src/segments/deno.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"oh-my-posh/environment"
|
||||||
|
"oh-my-posh/properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Deno struct {
|
||||||
|
language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Deno) Template() string {
|
||||||
|
return languageTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Deno) Init(props properties.Properties, env environment.Environment) {
|
||||||
|
d.language = language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: []string{"*.js", "*.ts"},
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "deno",
|
||||||
|
args: []string{"--version"},
|
||||||
|
regex: `(?:(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
versionURLTemplate: "https://github.com/denoland/deno/releases/tag/v{{.Full}}",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Deno) Enabled() bool {
|
||||||
|
return d.language.Enabled()
|
||||||
|
}
|
31
src/segments/deno_test.go
Normal file
31
src/segments/deno_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDeno(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "Deno 1.25.2", ExpectedString: "1.25.2", Version: "deno 1.25.2 (release, aarch64-apple-darwin)\nv8 10.6.194.5\ntypescript 4.7.4"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "deno",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.js",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
d := &Deno{}
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
|
@ -944,6 +944,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"const": "deno"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"title": "Deno CLI Segment",
|
||||||
|
"description": "https://ohmyposh.dev/docs/segments/deno",
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"properties": {
|
||||||
|
"home_enabled": {
|
||||||
|
"$ref": "#/definitions/home_enabled"
|
||||||
|
},
|
||||||
|
"fetch_version": {
|
||||||
|
"$ref": "#/definitions/fetch_version"
|
||||||
|
},
|
||||||
|
"display_mode": {
|
||||||
|
"$ref": "#/definitions/display_mode"
|
||||||
|
},
|
||||||
|
"version_url_template": {
|
||||||
|
"$ref": "#/definitions/version_url_template"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"if": {
|
"if": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
54
website/docs/segments/deno.mdx
Normal file
54
website/docs/segments/deno.mdx
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
---
|
||||||
|
id: deno
|
||||||
|
title: Deno
|
||||||
|
sidebar_label: Deno
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active [Deno CLI][deno-docs] version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "deno",
|
||||||
|
"style": "plain",
|
||||||
|
"foreground": "#3C82F6",
|
||||||
|
"template": " \ufbe4 {{ .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 active version or not; useful if all you need is an icon indicating `deno` |
|
||||||
|
| `display_mode` | `string` | <ul><li>`always`: the segment is always displayed</li><li>`files`: the segment is only displayed when `*.ts*` or `*.js` file 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 |
|
||||||
|
| `.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
|
||||||
|
[deno-docs]: https://deno.land/
|
|
@ -64,6 +64,7 @@ module.exports = {
|
||||||
"segments/cmake",
|
"segments/cmake",
|
||||||
"segments/crystal",
|
"segments/crystal",
|
||||||
"segments/dart",
|
"segments/dart",
|
||||||
|
"segments/deno",
|
||||||
"segments/dotnet",
|
"segments/dotnet",
|
||||||
"segments/executiontime",
|
"segments/executiontime",
|
||||||
"segments/exit",
|
"segments/exit",
|
||||||
|
|
Loading…
Reference in a new issue