forked from justjanne/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment-exitcode.go
50 lines (43 loc) · 895 Bytes
/
segment-exitcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"strconv"
"github.com/justjanne/powerline-go/exitcode"
pwl "github.com/justjanne/powerline-go/powerline"
)
var exitCodes = map[int]string{
1: "ERROR",
2: "USAGE",
127: "NOTFOUND",
}
func getMeaningFromExitCode(exitCode int) string {
if exitCode < 128 {
name, ok := exitCodes[exitCode]
if ok {
return name
}
} else {
name, ok := exitcode.Signals[exitCode-128]
if ok {
return name
}
}
return fmt.Sprintf("%d", exitCode)
}
func segmentExitCode(p *powerline) []pwl.Segment {
var meaning string
if p.cfg.PrevError == 0 {
return []pwl.Segment{}
}
if p.cfg.NumericExitCodes {
meaning = strconv.Itoa(p.cfg.PrevError)
} else {
meaning = getMeaningFromExitCode(p.cfg.PrevError)
}
return []pwl.Segment{{
Name: "exit",
Content: meaning,
Foreground: p.theme.CmdFailedFg,
Background: p.theme.CmdFailedBg,
}}
}