mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat: php language segment
This commit is contained in:
parent
457cd35e64
commit
42aac1fbf4
36
docs/docs/segment-php.md
Normal file
36
docs/docs/segment-php.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
id: php
|
||||
title: php
|
||||
sidebar_label: php
|
||||
---
|
||||
|
||||
## What
|
||||
|
||||
Display the currently active php version.
|
||||
|
||||
## Sample Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "php",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "\uE0B0",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#4063D8",
|
||||
"properties": {
|
||||
"prefix": " \ue73d ",
|
||||
"enable_hyperlink": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false`
|
||||
- display_version: `boolean` - display the php 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 `*.php` files are present (default)
|
||||
- enable_hyperlink: `bool` - display an hyperlink to the php release notes - defaults to `false`
|
|
@ -59,6 +59,7 @@ module.exports = {
|
|||
"text",
|
||||
"time",
|
||||
"ytm",
|
||||
"php",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -127,6 +127,8 @@ const (
|
|||
Memory SegmentType = "memory"
|
||||
// Angular writes which angular cli version us currently active
|
||||
Angular SegmentType = "angular"
|
||||
// PHP writes which php version is currently active
|
||||
PHP SegmentType = "php"
|
||||
)
|
||||
|
||||
func (segment *Segment) string() string {
|
||||
|
@ -259,6 +261,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
|
|||
Rust: &rust{},
|
||||
Memory: &memory{},
|
||||
Angular: &angular{},
|
||||
PHP: &php{},
|
||||
}
|
||||
if writer, ok := functions[segment.Type]; ok {
|
||||
props := &properties{
|
||||
|
|
29
src/segment_php.go
Normal file
29
src/segment_php.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
type php struct {
|
||||
language *language
|
||||
}
|
||||
|
||||
func (n *php) string() string {
|
||||
return n.language.string()
|
||||
}
|
||||
|
||||
func (n *php) init(props *properties, env environmentInfo) {
|
||||
n.language = &language{
|
||||
env: env,
|
||||
props: props,
|
||||
extensions: []string{"*.php", "composer.json", ".php-version"},
|
||||
commands: []*cmd{
|
||||
{
|
||||
executable: "php",
|
||||
args: []string{"--version"},
|
||||
regex: `(?:PHP (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
|
||||
},
|
||||
},
|
||||
versionURLTemplate: "[%[1]s](https://www.php.net/ChangeLog-%[2]s.php#PHP_%[2]s_%[3]s)",
|
||||
}
|
||||
}
|
||||
|
||||
func (n *php) enabled() bool {
|
||||
return n.language.enabled()
|
||||
}
|
32
src/segment_php_test.go
Normal file
32
src/segment_php_test.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPhp(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
}{
|
||||
{Case: "PHP 6.1.0", ExpectedString: "6.1.0", Version: "PHP 6.1.0(cli) (built: Jul 2 2021 03:59:48) ( NTS )"},
|
||||
{Case: "php 7.4.21", ExpectedString: "7.4.21", Version: "PHP 7.4.21 (cli) (built: Jul 2 2021 03:59:48) ( NTS )"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
params := &mockedLanguageParams{
|
||||
cmd: "php",
|
||||
versionParam: "--version",
|
||||
versionOutput: tc.Version,
|
||||
extension: "*.php",
|
||||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
j := &php{}
|
||||
j.init(props, env)
|
||||
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, j.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
|
@ -170,7 +170,8 @@
|
|||
"rust",
|
||||
"owm",
|
||||
"memory",
|
||||
"angularcli"
|
||||
"angularcli",
|
||||
"php"
|
||||
]
|
||||
},
|
||||
"style": {
|
||||
|
@ -828,6 +829,35 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": { "const": "php" }
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"title": "PHP Segment",
|
||||
"description": "https://ohmyposh.dev/docs/php",
|
||||
"properties": {
|
||||
"properties": {
|
||||
"properties": {
|
||||
"display_version": {
|
||||
"$ref": "#/definitions/display_version"
|
||||
},
|
||||
"display_mode": {
|
||||
"$ref": "#/definitions/display_mode"
|
||||
},
|
||||
"missing_command_text": {
|
||||
"$ref": "#/definitions/missing_command_text"
|
||||
},
|
||||
"enable_hyperlink": {
|
||||
"$ref": "#/definitions/enable_hyperlink"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
|
|
Loading…
Reference in a new issue