Пример #1
0
func RenderErrorSummary(s *models.Stage) {
	titleLine := fmt.Sprintf("Found following errors:")
	fmt.Printf("\n")
	fmt.Printf(tm.Bold(titleLine))
	fmt.Printf("\n")
	fmt.Printf("\n")
	_ = "breakpoint"
	for _, n := range s.Nodes {
		if n.HasError() {
			fmt.Printf(tm.Color(tm.Bold(n.Fqdn), tm.RED))
			fmt.Printf("\n")
			for _, e := range n.Errors {
				ErrorString := fmt.Sprintf("%v", e.Error())
				fmt.Printf(" - ")
				fmt.Printf(tm.Color(ErrorString, tm.RED))
				fmt.Printf("\n")
			}
			for k, v := range n.RepositoryError {
				reposiroryErrorString := fmt.Sprintf("%v: ", k)
				fmt.Printf(" - ")
				fmt.Printf(tm.Color(reposiroryErrorString, tm.RED))
				fmt.Printf(v.Error())
				fmt.Printf("\n")
			}
			fmt.Printf("\n")
		}
	}
}
Пример #2
0
Файл: main.go Проект: rmg/tyk
// Display introductory details
func intro() {
	fmt.Print("\n\n")
	fmt.Println(goterm.Bold(goterm.Color("Tyk.io Gateway API v1.0", goterm.GREEN)))
	fmt.Println(goterm.Bold(goterm.Color("=======================", goterm.GREEN)))
	fmt.Print("Copyright Jively Ltd. 2014")
	fmt.Print("\nhttp://www.tyk.io\n\n")
}
Пример #3
0
func GetText(message string, defaultText string) string {
	fmt.Printf("%s", goterm.Color(goterm.Bold(message), goterm.GREEN))

	if defaultText != "" {
		fmt.Printf(" %s%s%s",
			goterm.Color(goterm.Bold("["), goterm.GREEN),
			goterm.Color(defaultText, goterm.YELLOW),
			goterm.Color(goterm.Bold("]"), goterm.GREEN))
	}

	fmt.Printf("%s ", goterm.Color(goterm.Bold(":"), goterm.GREEN))

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')

	if text[len(text)-1] == '\n' {
		text = text[:len(text)-1]
	}

	if text == "" {
		text = defaultText
	}

	return text
}
Пример #4
0
func format(text string, color int, isBold bool) string {
	if isBold {
		return goterm.Bold(goterm.Color(text, color))
	} else {
		return normal(goterm.Color(text, color))
	}

}
Пример #5
0
func errRatioToString(r float64) string {
	failRatioS := fmt.Sprintf("%0.2f", r*100)
	if r != 0 {
		return goterm.Color(failRatioS, goterm.RED)
	} else {
		return goterm.Color(failRatioS, goterm.GREEN)
	}
}
Пример #6
0
func printHosts(lastApiResponse *healthd.ApiResponseHosts, status *healthdStatus) {
	goterm.Clear() // Clear current screen
	goterm.MoveCursor(1, 1)
	defer goterm.Flush()
	goterm.Println("Current Time:", status.FmtNow(), "   Status:", status.FmtStatus())

	//
	if lastApiResponse == nil {
		goterm.Println("no data yet")
		return
	}

	columns := []string{
		"Host:Port",
		"Status",
		"Last Checked",
		"Last Response Time",
	}

	for i, s := range columns {
		columns[i] = goterm.Bold(goterm.Color(s, goterm.BLACK))
	}

	table := goterm.NewTable(0, goterm.Width()-1, 5, ' ', 0)
	fmt.Fprintf(table, "%s\n", strings.Join(columns, "\t"))

	for _, host := range lastApiResponse.Hosts {
		printHost(table, host)
	}

	goterm.Println(table)
}
Пример #7
0
func (m *Menu) DrawMenuItems(redraw bool) {
	if redraw {
		// Move cursor up by number of menu items.  Assumes each menu item is ONE line.
		fmt.Printf("\033[%dA", len(m.MenuItems)-1)
	}

	for index, menuItem := range m.MenuItems {
		var newline = "\n"
		if index == len(m.MenuItems)-1 {
			newline = ""
		}

		prefix := "  "
		if m.Type == ButtonType {
			prefix = fmt.Sprintf("%d: ", index+1)
		} else if m.Type == CheckboxType {
			if menuItem.Selected {
				prefix = "\u25c9 "
			} else {
				prefix = "\u25ef "
			}
		}

		if index == m.CursorPos {
			cursor := goterm.Color("> ", goterm.CYAN)
			fmt.Printf("\r%s%s %s%s", cursor, prefix, menuItem.Text, newline)
		} else {
			fmt.Printf("\r%s%s %s%s", "  ", prefix, menuItem.Text, newline)
		}
	}
}
Пример #8
0
// simple view. No in place updates
func RenderQuietView(progressChannel chan models.SyncProgress, wg *sync.WaitGroup) {
	depthChar := "--- "
	defer wg.Done()
	syncStates := make(map[string]map[string]string)
	for sp := range progressChannel {
		if _, exists := syncStates[sp.Node.Fqdn]; !exists {
			syncStates[sp.Node.Fqdn] = make(map[string]string)
		}
		switch sp.State {
		case "skipped":
			for i := 0; i < sp.Node.Depth; i++ {
				fmt.Printf(depthChar)
			}
			line := fmt.Sprintf("%v %v %v", sp.Node.Fqdn, sp.Repository, sp.State)
			tm.Printf(tm.Color(tm.Bold(line), tm.MAGENTA))
			tm.Flush()
		case "error":
			for i := 0; i < sp.Node.Depth; i++ {
				fmt.Printf(depthChar)
			}
			line := fmt.Sprintf("%v %v %v", sp.Node.Fqdn, sp.Repository, sp.State)
			tm.Printf(tm.Color(tm.Bold(line), tm.RED))
			tm.Flush()
		case "running":
			// only output state changes
			if syncStates[sp.Node.Fqdn][sp.Repository] != sp.State {
				for i := 0; i < sp.Node.Depth; i++ {
					fmt.Printf(depthChar)
				}
				line := fmt.Sprintf("%v %v %v", sp.Node.Fqdn, sp.Repository, sp.State)
				tm.Printf(tm.Color(line, tm.BLUE))
				tm.Flush()
			}
			syncStates[sp.Node.Fqdn][sp.Repository] = sp.State
		case "finished":
			for i := 0; i < sp.Node.Depth; i++ {
				fmt.Printf(depthChar)
			}
			line := fmt.Sprintf("%v %v %v", sp.Node.Fqdn, sp.Repository, sp.State)
			tm.Printf(tm.Color(tm.Bold(line), tm.GREEN))
			tm.Flush()
		}
	}
}
Пример #9
0
func (m *Menu) Render() {
	if m.Heading != "" {
		fmt.Println(m.Heading)
	}

	fmt.Printf("%s\n", goterm.Color(goterm.Bold(m.Question)+":", goterm.GREEN))

	m.DrawMenuItems(false)

	// Hide cursor.
	fmt.Printf("\033[?25l")
}
Пример #10
0
func printJobs(lastApiResponse *healthd.ApiResponseJobs, status *healthdStatus) {
	goterm.Clear() // Clear current screen
	goterm.MoveCursor(1, 1)
	defer goterm.Flush()
	goterm.Println("Current Time:", status.FmtNow(), "   Status:", status.FmtStatus())

	if lastApiResponse == nil {
		goterm.Println("no data yet")
		return
	}

	columns := []string{
		"Job",
		//		"Jobs/Second", //minute? flag?
		"Total Count",
		"Success",
		"ValidationError",
		"Panic",
		"Error",
		"Junk",
		"Avg Response Time",
		"Stddev",
		"Min",
		"Max",
		"Total",
	}

	for i, s := range columns {
		columns[i] = goterm.Bold(goterm.Color(s, goterm.BLACK))
	}

	table := goterm.NewTable(0, goterm.Width()-1, 5, ' ', 0)
	fmt.Fprintf(table, "%s\n", strings.Join(columns, "\t"))

	for _, job := range lastApiResponse.Jobs {
		printJob(table, job)
	}

	goterm.Println(table)
}
Пример #11
0
func (cmd *Command) printOk(message string, params ...interface{}) {
	fmt.Fprintf(cmd.out, goterm.Color(fmt.Sprintf("OK: %s\n", fmt.Sprintf(message, params...)), goterm.GREEN)+"\n")
}
Пример #12
0
func (cmd *Command) printError(err error) {
	fmt.Fprint(cmd.out, goterm.Color(fmt.Sprintf("ERROR: %s", err), goterm.RED)+"\n")
}
Пример #13
0
			if v != nil {
				srvrs[i] = *v
				//log.Infof("Added %s", v.Properties.IP)
			} else {
				//log.Info("No server in this iteration")
			}
			i++
		}

		switch viper.GetString(SORTFLAG) {
		case DISTANCE:
			ipv.OrderedBy(ipv.Distance).Sort(servers)
		case LATENCY:
			ipv.OrderedBy(ipv.Latency).Sort(servers)
		case CAPACITY:
			ipv.OrderedBy(ipv.Distance, ipv.Capacity).Sort(servers)
		}

		numresults, _ := strconv.Atoi(cmd.Flags().Lookup("results").Value.String())
		for _, server := range servers[:numresults] {
			fmt.Printf("Host %v has %v utilization, is %v miles away, with %vms latency\n",
				tm.Color(server.Properties.Hostname, tm.CYAN),
				tm.Color(strconv.Itoa(server.Properties.Capacity)+"%", capacityColor(server.Properties.Capacity)),
				tm.Color(strconv.FormatFloat(server.Distance, 'f', 0, 64), tm.RED),
				tm.Color(strconv.FormatInt(int64(time.Duration(server.Latency)/time.Millisecond), 10), tm.GREEN),
			)
		}

	},
}
Пример #14
0
			servers[i].Distance = dist * 0.621371
		}

		switch viper.GetString(SORTFLAG) {
		case DISTANCE:
			ipv.OrderedBy(ipv.Distance).Sort(servers)
		case LATENCY:
			ipv.OrderedBy(ipv.Distance, ipv.Latency).Sort(servers)
		case CAPACITY:
			ipv.OrderedBy(ipv.Distance, ipv.Capacity).Sort(servers)
		}

		results, _ := strconv.Atoi(cmd.Flags().Lookup("results").Value.String())
		for _, server := range servers[:results] {
			fmt.Printf("Host %v has %v utilization and is %v miles away\n",
				tm.Color(server.Properties.Hostname, tm.CYAN),
				tm.Color(strconv.Itoa(server.Properties.Capacity)+"%", capacityColor(server.Properties.Capacity)),
				tm.Color(strconv.FormatFloat(server.Distance, 'f', 0, 64), tm.RED),
			)
		}
	},
}

func capacityColor(capacity int) int {
	if capacity >= 75 {
		return tm.RED
	} else if capacity >= 25 && capacity < 75 {
		return tm.YELLOW
	} else if capacity < 25 {
		return tm.GREEN
	}