mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 04:21:19 -08:00
feat: ocaml segment
This commit is contained in:
parent
8145d595c6
commit
5786720f21
|
@ -186,6 +186,8 @@ const (
|
||||||
NPM SegmentType = "npm"
|
NPM SegmentType = "npm"
|
||||||
// NX writes which Nx version us currently active
|
// NX writes which Nx version us currently active
|
||||||
NX SegmentType = "nx"
|
NX SegmentType = "nx"
|
||||||
|
// OCAML writes the active Ocaml version
|
||||||
|
OCAML SegmentType = "ocaml"
|
||||||
// OS write os specific icon
|
// OS write os specific icon
|
||||||
OS SegmentType = "os"
|
OS SegmentType = "os"
|
||||||
// OWM writes the weather coming from openweatherdata
|
// OWM writes the weather coming from openweatherdata
|
||||||
|
@ -310,6 +312,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
|
||||||
NODE: func() SegmentWriter { return &segments.Node{} },
|
NODE: func() SegmentWriter { return &segments.Node{} },
|
||||||
NPM: func() SegmentWriter { return &segments.Npm{} },
|
NPM: func() SegmentWriter { return &segments.Npm{} },
|
||||||
NX: func() SegmentWriter { return &segments.Nx{} },
|
NX: func() SegmentWriter { return &segments.Nx{} },
|
||||||
|
OCAML: func() SegmentWriter { return &segments.OCaml{} },
|
||||||
OS: func() SegmentWriter { return &segments.Os{} },
|
OS: func() SegmentWriter { return &segments.Os{} },
|
||||||
OWM: func() SegmentWriter { return &segments.Owm{} },
|
OWM: func() SegmentWriter { return &segments.Owm{} },
|
||||||
PATH: func() SegmentWriter { return &segments.Path{} },
|
PATH: func() SegmentWriter { return &segments.Path{} },
|
||||||
|
|
33
src/segments/ocaml.go
Normal file
33
src/segments/ocaml.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OCaml struct {
|
||||||
|
language
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OCaml) Template() string {
|
||||||
|
return languageTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OCaml) Init(props properties.Properties, env platform.Environment) {
|
||||||
|
o.language = language{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
extensions: []string{"*.ml", "*.mli", "dune", "dune-project", "dune-workspace"},
|
||||||
|
commands: []*cmd{
|
||||||
|
{
|
||||||
|
executable: "ocaml",
|
||||||
|
args: []string{"-version"},
|
||||||
|
regex: `The OCaml toplevel, version (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))(-(?P<prerelease>[a-z]+))?)`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OCaml) Enabled() bool {
|
||||||
|
return o.language.Enabled()
|
||||||
|
}
|
33
src/segments/ocaml_test.go
Normal file
33
src/segments/ocaml_test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package segments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOCaml(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "OCaml 4.12.0", ExpectedString: "4.12.0", Version: "The OCaml toplevel, version 4.12.0"},
|
||||||
|
{Case: "OCaml 4.11.0", ExpectedString: "4.11.0", Version: "The OCaml toplevel, version 4.11.0"},
|
||||||
|
{Case: "OCaml 4.13.0", ExpectedString: "4.13.0", Version: "The OCaml toplevel, version 4.13.0"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "ocaml",
|
||||||
|
versionParam: "-version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.ml",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
o := &OCaml{}
|
||||||
|
o.Init(props, env)
|
||||||
|
assert.True(t, o.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, renderTemplate(env, o.Template(), o), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
|
@ -286,6 +286,7 @@
|
||||||
"node",
|
"node",
|
||||||
"npm",
|
"npm",
|
||||||
"nx",
|
"nx",
|
||||||
|
"ocaml",
|
||||||
"os",
|
"os",
|
||||||
"owm",
|
"owm",
|
||||||
"path",
|
"path",
|
||||||
|
@ -2578,6 +2579,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"const": "ocaml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"title": "OCaml Segment",
|
||||||
|
"description": "https://ohmyposh.dev/docs/segments/ocaml",
|
||||||
|
"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": {
|
||||||
|
|
53
website/docs/segments/ocaml.mdx
Normal file
53
website/docs/segments/ocaml.mdx
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
---
|
||||||
|
id: ocaml
|
||||||
|
title: Ocaml
|
||||||
|
sidebar_label: Ocaml
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display the currently active OCaml version.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
import Config from '@site/src/components/Config.js';
|
||||||
|
|
||||||
|
<Config data={{
|
||||||
|
"type": "ocaml",
|
||||||
|
"style": "powerline",
|
||||||
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"foreground": "#d08770",
|
||||||
|
"template": " \ue67a {{ .Full }} "
|
||||||
|
}}/>
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| `home_enabled` | `boolean` | display the segment in the HOME folder or not - defaults to `false` |
|
||||||
|
| `fetch_version` | `boolean` | display the ocaml version (`ocaml -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 `*.rs`, `Cargo.toml` or `Cargo.lock` files are present (**default**)</li></ul> |
|
||||||
|
|
||||||
|
## 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 |
|
||||||
|
| `.Prerelease` | `string` | channel name |
|
||||||
|
| `.Error` | `string` | error encountered when fetching the version string |
|
||||||
|
|
||||||
|
[templates]: /docs/configuration/templates
|
|
@ -96,6 +96,7 @@ module.exports = {
|
||||||
"segments/node",
|
"segments/node",
|
||||||
"segments/npm",
|
"segments/npm",
|
||||||
"segments/nx",
|
"segments/nx",
|
||||||
|
"segments/ocaml",
|
||||||
"segments/os",
|
"segments/os",
|
||||||
"segments/owm",
|
"segments/owm",
|
||||||
"segments/path",
|
"segments/path",
|
||||||
|
|
Loading…
Reference in a new issue