-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
71 lines (57 loc) · 1.75 KB
/
ui.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
package uihelpers
import (
"fmt"
"strings"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/terminal"
)
func ColoredAppState(app models.ApplicationFields) string {
appState := strings.ToLower(app.State)
if app.RunningInstances == 0 {
if appState == models.ApplicationStateStopped {
return appState
}
return terminal.CrashedColor(appState)
}
if app.RunningInstances < app.InstanceCount {
return terminal.WarningColor(appState)
}
return appState
}
func ColoredAppInstances(app models.ApplicationFields) string {
healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)
if app.RunningInstances < 0 {
healthString = fmt.Sprintf("?/%d", app.InstanceCount)
}
if app.RunningInstances == 0 {
if strings.ToLower(app.State) == models.ApplicationStateStopped {
return healthString
}
return terminal.CrashedColor(healthString)
}
if app.RunningInstances < app.InstanceCount {
return terminal.WarningColor(healthString)
}
return healthString
}
func ColoredInstanceState(instance models.AppInstanceFields) (colored string) {
state := string(instance.State)
switch state {
case models.ApplicationStateStarted, models.ApplicationStateRunning:
colored = T("running")
case models.ApplicationStateStopped:
colored = terminal.StoppedColor(T("stopped"))
case models.ApplicationStateCrashed:
colored = terminal.CrashedColor(T("crashed"))
case models.ApplicationStateFlapping:
colored = terminal.CrashedColor(T("crashing"))
case models.ApplicationStateDown:
colored = terminal.CrashedColor(T("down"))
case models.ApplicationStateStarting:
colored = terminal.AdvisoryColor(T("starting"))
default:
colored = terminal.WarningColor(state)
}
return
}