oh-my-posh/src/segment_exit.go

91 lines
1.5 KiB
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
"strconv"
)
2019-03-13 04:14:30 -07:00
2022-01-26 05:10:18 -08:00
type Exit struct {
props properties.Properties
env environment.Environment
2019-03-13 04:14:30 -07:00
2021-11-14 04:39:00 -08:00
Text string
}
2019-03-13 04:14:30 -07:00
func (e *Exit) Template() string {
return "{{ .Text }}"
}
func (e *Exit) Enabled() bool {
e.Text = e.getMeaningFromExitCode(e.env.ErrorCode())
if e.props.GetBool(properties.AlwaysEnabled, false) {
2019-03-13 04:14:30 -07:00
return true
}
return e.env.ErrorCode() != 0
2019-03-13 04:14:30 -07:00
}
func (e *Exit) Init(props properties.Properties, env environment.Environment) {
2022-01-22 10:46:56 -08:00
e.props = props
e.env = env
}
2022-01-26 05:10:18 -08:00
func (e *Exit) getMeaningFromExitCode(code int) string {
2022-01-22 10:46:56 -08:00
switch code {
2019-03-13 04:14:30 -07:00
case 1:
return "ERROR"
case 2:
return "USAGE"
case 126:
return "NOPERM"
case 127:
return "NOTFOUND"
case 128 + 1:
return "SIGHUP"
case 128 + 2:
return "SIGINT"
case 128 + 3:
return "SIGQUIT"
case 128 + 4:
return "SIGILL"
case 128 + 5:
return "SIGTRAP"
case 128 + 6:
return "SIGIOT"
case 128 + 7:
return "SIGBUS"
case 128 + 8:
return "SIGFPE"
case 128 + 9:
return "SIGKILL"
case 128 + 10:
return "SIGUSR1"
case 128 + 11:
return "SIGSEGV"
case 128 + 12:
return "SIGUSR2"
case 128 + 13:
return "SIGPIPE"
case 128 + 14:
return "SIGALRM"
case 128 + 15:
return "SIGTERM"
case 128 + 16:
return "SIGSTKFLT"
case 128 + 17:
return "SIGCHLD"
case 128 + 18:
return "SIGCONT"
case 128 + 19:
return "SIGSTOP"
case 128 + 20:
return "SIGTSTP"
case 128 + 21:
return "SIGTTIN"
case 128 + 22:
return "SIGTTOU"
default:
2022-01-22 10:46:56 -08:00
return strconv.Itoa(code)
2019-03-13 04:14:30 -07:00
}
}