/
helpers.go
79 lines (71 loc) · 1.87 KB
/
helpers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package page
import (
"github.com/gdamore/tcell"
"github.com/slok/brigadeterm/pkg/controller"
)
const (
successedIcon = "✔"
failedIcon = "✖"
runningIcon = "▶"
pendingIcon = "⟳"
unknownIcon = "?"
successedColor = tcell.ColorGreen
failedColor = tcell.ColorRed
runningColor = tcell.ColorYellow
pendingColor = tcell.ColorWhite
unknownColor = tcell.ColorGrey
successedTextColor = "[green]"
failedTextColor = "[red]"
runningTextColor = "[yellow]"
pendingTextColor = "[white]"
unknownTextColor = "[grey]"
)
// getColorFromState gets the color from the state.
func getColorFromState(state controller.State) tcell.Color {
switch state {
case controller.SuccessedState:
return successedColor
case controller.FailedState:
return failedColor
case controller.RunningState:
return runningColor
case controller.PendingState:
return pendingColor
default:
return unknownColor
}
}
// getTextFromState gets the text color from the state.
func getTextColorFromState(state controller.State) string {
switch state {
case controller.SuccessedState:
return successedTextColor
case controller.FailedState:
return failedTextColor
case controller.RunningState:
return runningTextColor
case controller.PendingState:
return pendingTextColor
default:
return unknownTextColor
}
}
// getIconFromState gets the icon from the state.
func getIconFromState(state controller.State) string {
switch state {
case controller.SuccessedState:
return successedIcon
case controller.FailedState:
return failedIcon
case controller.RunningState:
return runningIcon
case controller.PendingState:
return pendingIcon
default:
return unknownIcon
}
}
// hasFinished returns true if the state is in one of the finished states.
func hasFinished(state controller.State) bool {
return state == controller.SuccessedState || state == controller.FailedState
}