github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/util/ui/ui_for_app.go (about)

     1  package ui
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/fatih/color"
     7  )
     8  
     9  func (ui *UI) DisplayInstancesTableForApp(table [][]string) {
    10  	redColor := color.New(color.FgRed, color.Bold)
    11  	trDown, trCrashed := ui.TranslateText("down"), ui.TranslateText("crashed")
    12  
    13  	for i, row := range table {
    14  		if row[1] == trDown || row[1] == trCrashed {
    15  			table[i][1] = ui.modifyColor(row[1], redColor)
    16  		}
    17  	}
    18  	ui.DisplayTableWithHeader("", table, 3)
    19  }
    20  
    21  func (ui *UI) DisplayKeyValueTableForApp(table [][]string) {
    22  	runningInstances := strings.Split(table[2][1], "/")[0]
    23  	state := table[1][1]
    24  
    25  	if runningInstances == "0" && state != ui.TranslateText("stopped") {
    26  		redColor := color.New(color.FgRed, color.Bold)
    27  		table[1][1] = ui.modifyColor(table[1][1], redColor)
    28  		table[2][1] = ui.modifyColor(table[2][1], redColor)
    29  	}
    30  	ui.DisplayKeyValueTable("", table, 3)
    31  }
    32  
    33  func (ui *UI) DisplayKeyValueTableForV3App(table [][]string, crashedProcesses []string) {
    34  	if len(crashedProcesses) > 0 {
    35  		redColor := color.New(color.FgRed, color.Bold)
    36  		table[1][1] = ui.modifyColor(table[1][1], redColor)
    37  
    38  		processes := strings.Split(table[2][1], ",")
    39  		newProcesses := []string{}
    40  		for _, process := range processes {
    41  			parts := strings.Split(process, ":")
    42  			isCrashedProcess := false
    43  			for _, crashedProcess := range crashedProcesses {
    44  				if parts[0] == crashedProcess {
    45  					isCrashedProcess = true
    46  					break
    47  				}
    48  			}
    49  
    50  			if isCrashedProcess {
    51  				newProcesses = append(newProcesses, ui.modifyColor(process, redColor))
    52  			} else {
    53  				newProcesses = append(newProcesses, process)
    54  			}
    55  		}
    56  
    57  		table[2][1] = strings.Join(newProcesses, ",")
    58  	}
    59  
    60  	ui.DisplayKeyValueTable("", table, 3)
    61  }