mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
parent
b651c9a065
commit
225b317e32
|
@ -21,6 +21,8 @@ const (
|
||||||
IgnoreFolders Property = "ignore_folders"
|
IgnoreFolders Property = "ignore_folders"
|
||||||
// DisplayVersion show the version number or not
|
// DisplayVersion show the version number or not
|
||||||
DisplayVersion Property = "display_version"
|
DisplayVersion Property = "display_version"
|
||||||
|
// AlwaysEnabled decides whether or not to always display the info
|
||||||
|
AlwaysEnabled Property = "always_enabled"
|
||||||
)
|
)
|
||||||
|
|
||||||
type properties struct {
|
type properties struct {
|
||||||
|
|
|
@ -10,12 +10,14 @@ type exit struct {
|
||||||
const (
|
const (
|
||||||
// DisplayExitCode shows or hides the error code
|
// DisplayExitCode shows or hides the error code
|
||||||
DisplayExitCode Property = "display_exit_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 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 shows error codes as numbers
|
||||||
AlwaysNumeric Property = "always_numeric"
|
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 {
|
func (e *exit) enabled() bool {
|
||||||
|
@ -43,7 +45,10 @@ func (e *exit) getFormattedText() string {
|
||||||
if e.env.lastErrorCode() != 0 && colorBackground {
|
if e.env.lastErrorCode() != 0 && colorBackground {
|
||||||
e.props.background = e.props.getColor(ErrorColor, e.props.background)
|
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 {
|
func (e *exit) getMeaningFromExitCode() string {
|
||||||
|
|
|
@ -7,49 +7,63 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExitWriterEnabled(t *testing.T) {
|
func TestExitWriterEnabled(t *testing.T) {
|
||||||
|
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 := new(MockedEnvironment)
|
||||||
env.On("lastErrorCode", nil).Return(102)
|
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||||
e := &exit{
|
e := &exit{
|
||||||
env: env,
|
env: env,
|
||||||
}
|
}
|
||||||
assert.True(t, e.enabled())
|
assert.Equal(t, tc.Expected, e.enabled())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExitWriterDisabled(t *testing.T) {
|
func TestExitWriterFormattedText(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
cases := []struct {
|
||||||
env.On("lastErrorCode", nil).Return(0)
|
ExitCode int
|
||||||
e := &exit{
|
Expected string
|
||||||
env: env,
|
SuccessIcon string
|
||||||
}
|
ErrorIcon string
|
||||||
assert.False(t, e.enabled())
|
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},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExitWriterStandardCode(t *testing.T) {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("lastErrorCode", nil).Return(129)
|
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||||
props := &properties{
|
props := &properties{
|
||||||
foreground: "#111111",
|
foreground: "#111111",
|
||||||
background: "#ffffff",
|
background: "#ffffff",
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
SuccessIcon: tc.SuccessIcon,
|
||||||
|
ErrorIcon: tc.ErrorIcon,
|
||||||
|
DisplayExitCode: tc.DisplayExitCode,
|
||||||
|
AlwaysNumeric: tc.AlwaysNumeric,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
e := &exit{
|
e := &exit{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
assert.Equal(t, "SIGHUP", e.getFormattedText())
|
assert.Equal(t, tc.Expected, 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) {
|
func TestGetMeaningFromExitCode(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue