mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
parent
b651c9a065
commit
225b317e32
|
@ -21,6 +21,8 @@ const (
|
|||
IgnoreFolders Property = "ignore_folders"
|
||||
// DisplayVersion show the version number or not
|
||||
DisplayVersion Property = "display_version"
|
||||
// AlwaysEnabled decides whether or not to always display the info
|
||||
AlwaysEnabled Property = "always_enabled"
|
||||
)
|
||||
|
||||
type properties struct {
|
||||
|
|
|
@ -10,12 +10,14 @@ type exit struct {
|
|||
const (
|
||||
// DisplayExitCode shows or hides the error code
|
||||
DisplayExitCode Property = "display_exit_code"
|
||||
// AlwaysEnabled decides whether or not to always display the exitcode info
|
||||
AlwaysEnabled Property = "always_enabled"
|
||||
// ErrorColor specify a different foreground color for the error text when using always_show = true
|
||||
ErrorColor Property = "error_color"
|
||||
// AlwaysNumeric shows error codes as numbers
|
||||
AlwaysNumeric Property = "always_numeric"
|
||||
// SuccessIcon displays when there's no error and AlwaysEnabled = true
|
||||
SuccessIcon Property = "success_icon"
|
||||
// ErrorIcon displays when there's an error
|
||||
ErrorIcon Property = "error_icon"
|
||||
)
|
||||
|
||||
func (e *exit) enabled() bool {
|
||||
|
@ -43,7 +45,10 @@ func (e *exit) getFormattedText() string {
|
|||
if e.env.lastErrorCode() != 0 && colorBackground {
|
||||
e.props.background = e.props.getColor(ErrorColor, e.props.background)
|
||||
}
|
||||
return exitCode
|
||||
if e.env.lastErrorCode() == 0 {
|
||||
return e.props.getString(SuccessIcon, "")
|
||||
}
|
||||
return fmt.Sprintf("%s%s", e.props.getString(ErrorIcon, ""), exitCode)
|
||||
}
|
||||
|
||||
func (e *exit) getMeaningFromExitCode() string {
|
||||
|
|
|
@ -7,49 +7,63 @@ import (
|
|||
)
|
||||
|
||||
func TestExitWriterEnabled(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(102)
|
||||
e := &exit{
|
||||
env: env,
|
||||
cases := []struct {
|
||||
ExitCode int
|
||||
Expected bool
|
||||
}{
|
||||
{ExitCode: 102, Expected: true},
|
||||
{ExitCode: 0, Expected: false},
|
||||
{ExitCode: -1, Expected: true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||
e := &exit{
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, tc.Expected, e.enabled())
|
||||
}
|
||||
assert.True(t, e.enabled())
|
||||
}
|
||||
|
||||
func TestExitWriterDisabled(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(0)
|
||||
e := &exit{
|
||||
env: env,
|
||||
func TestExitWriterFormattedText(t *testing.T) {
|
||||
cases := []struct {
|
||||
ExitCode int
|
||||
Expected string
|
||||
SuccessIcon string
|
||||
ErrorIcon string
|
||||
DisplayExitCode bool
|
||||
AlwaysNumeric bool
|
||||
}{
|
||||
{ExitCode: 129, Expected: "SIGHUP", DisplayExitCode: true},
|
||||
{ExitCode: 5001, Expected: "5001", DisplayExitCode: true},
|
||||
{ExitCode: 147, Expected: "SIGSTOP", DisplayExitCode: true},
|
||||
{ExitCode: 147, Expected: "", DisplayExitCode: false},
|
||||
{ExitCode: 147, Expected: "147", DisplayExitCode: true, AlwaysNumeric: true},
|
||||
{ExitCode: 0, Expected: "wooopie", SuccessIcon: "wooopie"},
|
||||
{ExitCode: 129, Expected: "err SIGHUP", ErrorIcon: "err ", DisplayExitCode: true},
|
||||
{ExitCode: 129, Expected: "err", ErrorIcon: "err", DisplayExitCode: false},
|
||||
}
|
||||
assert.False(t, e.enabled())
|
||||
}
|
||||
|
||||
func TestExitWriterStandardCode(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(129)
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
background: "#ffffff",
|
||||
for _, tc := range cases {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
background: "#ffffff",
|
||||
values: map[Property]interface{}{
|
||||
SuccessIcon: tc.SuccessIcon,
|
||||
ErrorIcon: tc.ErrorIcon,
|
||||
DisplayExitCode: tc.DisplayExitCode,
|
||||
AlwaysNumeric: tc.AlwaysNumeric,
|
||||
},
|
||||
}
|
||||
e := &exit{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.Equal(t, tc.Expected, e.getFormattedText())
|
||||
}
|
||||
e := &exit{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.Equal(t, "SIGHUP", e.getFormattedText())
|
||||
}
|
||||
|
||||
func TestExitWriterNonStandardCode(t *testing.T) {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("lastErrorCode", nil).Return(5001)
|
||||
props := &properties{
|
||||
foreground: "#111111",
|
||||
background: "#ffffff",
|
||||
}
|
||||
e := &exit{
|
||||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.Equal(t, "5001", e.getFormattedText())
|
||||
}
|
||||
|
||||
func TestGetMeaningFromExitCode(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue