github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/ui_helpers/ui.go (about)

     1  package ui_helpers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	. "github.com/cloudfoundry/cli/cf/i18n"
     8  
     9  	"github.com/cloudfoundry/cli/cf/models"
    10  	"github.com/cloudfoundry/cli/cf/terminal"
    11  )
    12  
    13  func ColoredAppState(app models.ApplicationFields) string {
    14  	appState := strings.ToLower(app.State)
    15  
    16  	if app.RunningInstances == 0 {
    17  		if appState == "stopped" {
    18  			return appState
    19  		} else {
    20  			return terminal.CrashedColor(appState)
    21  		}
    22  	}
    23  
    24  	if app.RunningInstances < app.InstanceCount {
    25  		return terminal.WarningColor(appState)
    26  	}
    27  
    28  	return appState
    29  }
    30  
    31  func ColoredAppInstances(app models.ApplicationFields) string {
    32  	healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)
    33  
    34  	if app.RunningInstances < 0 {
    35  		healthString = fmt.Sprintf("?/%d", app.InstanceCount)
    36  	}
    37  
    38  	if app.RunningInstances == 0 {
    39  		if strings.ToLower(app.State) == "stopped" {
    40  			return healthString
    41  		} else {
    42  			return terminal.CrashedColor(healthString)
    43  		}
    44  	}
    45  
    46  	if app.RunningInstances < app.InstanceCount {
    47  		return terminal.WarningColor(healthString)
    48  	}
    49  
    50  	return healthString
    51  }
    52  
    53  func ColoredInstanceState(instance models.AppInstanceFields) (colored string) {
    54  	state := string(instance.State)
    55  	switch state {
    56  	case "started", "running":
    57  		colored = T("running")
    58  	case "stopped":
    59  		colored = terminal.StoppedColor(T("stopped"))
    60  	case "flapping":
    61  		colored = terminal.CrashedColor(T("crashing"))
    62  	case "down":
    63  		colored = terminal.CrashedColor(T("down"))
    64  	case "starting":
    65  		colored = terminal.AdvisoryColor(T("starting"))
    66  	default:
    67  		colored = terminal.WarningColor(state)
    68  	}
    69  
    70  	return
    71  }