mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat: 'exit' segment: option to always use numeric codes
This commit is contained in:
parent
6f1a7b9d39
commit
bfb21739d4
|
@ -34,5 +34,6 @@ Displays the last exit code or that the last command failed based on the configu
|
||||||
- always_enabled: `boolean` - always show the status - defaults to `false`
|
- always_enabled: `boolean` - always show the status - defaults to `false`
|
||||||
- color_background: `boolean` - color the background or foreground when an error occurs - defaults to `false`
|
- color_background: `boolean` - color the background or foreground when an error occurs - defaults to `false`
|
||||||
- error_color: `string` [color][colors] - color to use when an error occured
|
- error_color: `string` [color][colors] - color to use when an error occured
|
||||||
|
- always_numeric: `boolean` - always display exit code as a number - defaults to `false`
|
||||||
|
|
||||||
[colors]: /docs/configure#colors
|
[colors]: /docs/configure#colors
|
||||||
|
|
|
@ -14,6 +14,8 @@ const (
|
||||||
AlwaysEnabled Property = "always_enabled"
|
AlwaysEnabled Property = "always_enabled"
|
||||||
// ErrorColor specify a different foreground color for the error text when using always_show = true
|
// ErrorColor specify a different foreground color for the error text when using always_show = true
|
||||||
ErrorColor Property = "error_color"
|
ErrorColor Property = "error_color"
|
||||||
|
// AlwaysNumeric shows error codes as numbers
|
||||||
|
AlwaysNumeric Property = "always_numeric"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *exit) enabled() bool {
|
func (e *exit) enabled() bool {
|
||||||
|
@ -48,6 +50,9 @@ func (e *exit) getMeaningFromExitCode() string {
|
||||||
if !e.props.getBool(DisplayExitCode, true) {
|
if !e.props.getBool(DisplayExitCode, true) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
if e.props.getBool(AlwaysNumeric, false) {
|
||||||
|
return fmt.Sprintf("%d", e.env.lastErrorCode())
|
||||||
|
}
|
||||||
switch e.env.lastErrorCode() {
|
switch e.env.lastErrorCode() {
|
||||||
case 1:
|
case 1:
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
|
|
|
@ -91,3 +91,18 @@ func TestGetMeaningFromExitCode(t *testing.T) {
|
||||||
assert.Equal(t, want, e.getMeaningFromExitCode())
|
assert.Equal(t, want, e.getMeaningFromExitCode())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAlwaysNumericExitCode(t *testing.T) {
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("lastErrorCode", nil).Return(1)
|
||||||
|
props := &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
AlwaysNumeric: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
e := &exit{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
}
|
||||||
|
assert.Equal(t, "1", e.getMeaningFromExitCode())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue