github.com/loafoe/cli@v7.1.0+incompatible/cf/uihelpers/ui.go (about)

     1  package uihelpers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	. "code.cloudfoundry.org/cli/cf/i18n"
     8  
     9  	"code.cloudfoundry.org/cli/cf/models"
    10  	"code.cloudfoundry.org/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 == models.ApplicationStateStopped {
    18  			return appState
    19  		}
    20  		return terminal.CrashedColor(appState)
    21  	}
    22  
    23  	if app.RunningInstances < app.InstanceCount {
    24  		return terminal.WarningColor(appState)
    25  	}
    26  
    27  	return appState
    28  }
    29  
    30  func ColoredAppInstances(app models.ApplicationFields) string {
    31  	healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)
    32  
    33  	if app.RunningInstances < 0 {
    34  		healthString = fmt.Sprintf("?/%d", app.InstanceCount)
    35  	}
    36  
    37  	if app.RunningInstances == 0 {
    38  		if strings.ToLower(app.State) == models.ApplicationStateStopped {
    39  			return healthString
    40  		}
    41  		return terminal.CrashedColor(healthString)
    42  	}
    43  
    44  	if app.RunningInstances < app.InstanceCount {
    45  		return terminal.WarningColor(healthString)
    46  	}
    47  
    48  	return healthString
    49  }
    50  
    51  func ColoredInstanceState(instance models.AppInstanceFields) (colored string) {
    52  	state := string(instance.State)
    53  	switch state {
    54  	case models.ApplicationStateStarted, models.ApplicationStateRunning:
    55  		colored = T("running")
    56  	case models.ApplicationStateStopped:
    57  		colored = terminal.StoppedColor(T("stopped"))
    58  	case models.ApplicationStateCrashed:
    59  		colored = terminal.CrashedColor(T("crashed"))
    60  	case models.ApplicationStateFlapping:
    61  		colored = terminal.CrashedColor(T("crashing"))
    62  	case models.ApplicationStateDown:
    63  		colored = terminal.CrashedColor(T("down"))
    64  	case models.ApplicationStateStarting:
    65  		colored = terminal.AdvisoryColor(T("starting"))
    66  	default:
    67  		colored = terminal.WarningColor(state)
    68  	}
    69  
    70  	return
    71  }