mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat(segment): added cmake segment
This commit is contained in:
parent
0deccc956e
commit
3a8907c48e
|
@ -90,6 +90,8 @@ const (
|
|||
CF SegmentType = "cf"
|
||||
// Cloud Foundry logged in target
|
||||
CFTARGET SegmentType = "cftarget"
|
||||
// CMAKE writes the active cmake version
|
||||
CMAKE SegmentType = "cmake"
|
||||
// CMD writes the output of a shell command
|
||||
CMD SegmentType = "command"
|
||||
// CRYSTAL writes the active crystal version
|
||||
|
@ -268,6 +270,7 @@ func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error
|
|||
CFTARGET: &segments.CfTarget{},
|
||||
CMD: &segments.Cmd{},
|
||||
CRYSTAL: &segments.Crystal{},
|
||||
CMAKE: &segments.Cmake{},
|
||||
DART: &segments.Dart{},
|
||||
DOTNET: &segments.Dotnet{},
|
||||
EXECUTIONTIME: &segments.Executiontime{},
|
||||
|
|
34
src/segments/cmake.go
Normal file
34
src/segments/cmake.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package segments
|
||||
|
||||
import (
|
||||
"oh-my-posh/environment"
|
||||
"oh-my-posh/properties"
|
||||
)
|
||||
|
||||
type Cmake struct {
|
||||
language
|
||||
}
|
||||
|
||||
func (c *Cmake) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (c *Cmake) Init(props properties.Properties, env environment.Environment) {
|
||||
c.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
extensions: []string{"*.cmake", "CMakeLists.txt"},
|
||||
commands: []*cmd{
|
||||
{
|
||||
executable: "cmake",
|
||||
args: []string{"--version"},
|
||||
regex: `cmake version (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||
},
|
||||
},
|
||||
versionURLTemplate: "https://cmake.org/cmake/help/v{{ .Major }}.{{ .Minor }}",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cmake) Enabled() bool {
|
||||
return c.language.Enabled()
|
||||
}
|
34
src/segments/cmake_test.go
Normal file
34
src/segments/cmake_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package segments
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCmake(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
}{
|
||||
{Case: "Cmake 3.23.2", ExpectedString: "3.23.2", Version: "cmake version 3.23.2"},
|
||||
{Case: "Cmake 2.3.13", ExpectedString: "2.3.12", Version: "cmake version 2.3.12"},
|
||||
{Case: "", ExpectedString: "", Version: ""},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
params := &mockedLanguageParams{
|
||||
cmd: "cmake",
|
||||
versionParam: "--version",
|
||||
versionOutput: tc.Version,
|
||||
extension: "*.cmake",
|
||||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
c := &Cmake{}
|
||||
c.Init(props, env)
|
||||
failMsg := fmt.Sprintf("Failed in case: %s", tc.Case)
|
||||
assert.True(t, c.Enabled(), failMsg)
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, c.Template(), c), failMsg)
|
||||
}
|
||||
}
|
|
@ -205,6 +205,7 @@
|
|||
"cds",
|
||||
"cf",
|
||||
"cftarget",
|
||||
"cmake",
|
||||
"dotnet",
|
||||
"dart",
|
||||
"exit",
|
||||
|
@ -536,6 +537,40 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "cmake"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"title": "Cmake Segment",
|
||||
"description": "https://ohmyposh.dev/docs/segments/cmake",
|
||||
"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"
|
||||
},
|
||||
"version_url_template": {
|
||||
"$ref": "#/definitions/version_url_template"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
|
|
56
website/docs/segments/cmake.mdx
Normal file
56
website/docs/segments/cmake.mdx
Normal file
|
@ -0,0 +1,56 @@
|
|||
---
|
||||
id: cmake
|
||||
title: Cmake
|
||||
sidebar_label: Cmake
|
||||
---
|
||||
|
||||
## What
|
||||
|
||||
Display the currently active [Cmake][cmake-github] version.
|
||||
|
||||
## Sample Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "cmake",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "\uE0B0",
|
||||
"foreground": "#E8EAEE",
|
||||
"background": "#1E9748",
|
||||
"template": " \ue61e \ue61d cmake {{ .Full }} "
|
||||
}
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
|
||||
- fetch_version: `boolean` - display the cmake 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 `*.cmake` or `CMakeLists.txt` files 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
|
||||
|
||||
[cmake-github]: https://github.com/Kitware/CMake
|
||||
[go-text-template]: https://golang.org/pkg/text/template/
|
||||
[templates]: /docs/configuration/templates
|
|
@ -62,6 +62,7 @@ module.exports = {
|
|||
"segments/crystal",
|
||||
"segments/cf",
|
||||
"segments/cftarget",
|
||||
"segments/cmake",
|
||||
"segments/dart",
|
||||
"segments/dotnet",
|
||||
"segments/executiontime",
|
||||
|
|
Loading…
Reference in a new issue