Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cmd/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ func FormatServices(services []config.ServiceSummary) string {
table.AddFormattingFunction(8, endangeredPartitionsFormatter)
table.AddFormattingFunction(9, vulnerablePartitionsFormatter)
table.AddFormattingFunction(10, vulnerablePartitionsFormatter)
table.AddFormattingFunction(11, yesBoolFormatter)
table.AddFormattingFunction(12, yesBoolFormatter)
} else {
table.WithAlignment(L, L, R, L, R, R, R, L)
}
Expand Down
45 changes: 30 additions & 15 deletions pkg/cmd/formatting_functions.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/

package cmd

import (
"fmt"
"github.com/fatih/color"
"strconv"
"strings"
Expand All @@ -17,11 +18,25 @@ var (
yellow = color.New(color.FgHiYellow).SprintFunc()
)

const stopped = "stopped"
const (
stopped = "stopped"
startRed = "\x01"
startYellow = "\x02"
endColor = "\x03"
)

func setupColors() {
red = func(a ...interface{}) string {
return startRed + fmt.Sprint(a...) + endColor
}
yellow = func(a ...interface{}) string {
return startYellow + fmt.Sprint(a...) + endColor
}
}

// statusHAFormatter formats a column value and makes it Red if contains ENDANGERED.
var statusHAFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if strings.Contains(s, endangered) {
Expand All @@ -33,7 +48,7 @@ var statusHAFormatter = func(s string) string {

// hitRateFormatter formats a column value which represents a cache hit rate.
var hitRateFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
floatValue, err := strconv.ParseFloat(trimPercent(s), 32)
Expand All @@ -52,7 +67,7 @@ var hitRateFormatter = func(s string) string {

// machineMemoryFormatting formats a column value which represents machine percent memory used.
var machineMemoryFormatting = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
floatValue, err := strconv.ParseFloat(trimPercent(s), 32)
Expand All @@ -71,7 +86,7 @@ var machineMemoryFormatting = func(s string) string {

// errorFormatter formats a column value which represents an error or number that needs to be highlighted.
var errorFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
v, err := getInt64Value(s)
Expand All @@ -87,7 +102,7 @@ var errorFormatter = func(s string) string {

// endangeredPartitionsFormatter formats a column value which represents the number of endangered partitions.
var endangeredPartitionsFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
v, err := getInt64Value(s)
Expand All @@ -100,7 +115,7 @@ var endangeredPartitionsFormatter = func(s string) string {

// vulnerablePartitionsFormatter formats a column value which represents the number of vulnerable or unbalanced partitions.
var vulnerablePartitionsFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
v, err := getInt64Value(s)
Expand All @@ -113,7 +128,7 @@ var vulnerablePartitionsFormatter = func(s string) string {

// packetFormatter formats a column value which represents packages where higher numbers need to be highlighted.
var packetFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
v, err := getInt64Value(s)
Expand All @@ -133,7 +148,7 @@ var packetFormatter = func(s string) string {

// healthFormatter formats a column value when false will be displayed in red.
var healthFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if s == stringFalse {
Expand All @@ -144,7 +159,7 @@ var healthFormatter = func(s string) string {

// reporterFormatter formats a column value when "Stopped" will be displayed in red.
var reporterFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if strings.Contains(strings.ToLower(s), stopped) {
Expand All @@ -155,7 +170,7 @@ var reporterFormatter = func(s string) string {

// trueBoolFormatter formats a column value when true will be displayed in red.
var trueBoolFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if s == stringTrue {
Expand All @@ -166,7 +181,7 @@ var trueBoolFormatter = func(s string) string {

// falseBoolFormatter formats a column value when false will be displayed in red.
var falseBoolFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if s == stringFalse {
Expand All @@ -177,7 +192,7 @@ var falseBoolFormatter = func(s string) string {

// yesBoolFormatter formats a column value when yes will be displayed in red.
var yesBoolFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if strings.Contains(s, "yes") {
Expand All @@ -188,7 +203,7 @@ var yesBoolFormatter = func(s string) string {

// healthSummaryFormatter formats a column value for a health summary.
var healthSummaryFormatter = func(s string) string {
if monitorCluster || isWindows() {
if isWindows() {
return s
}
if !strings.Contains(s, "/") {
Expand Down
19 changes: 18 additions & 1 deletion pkg/cmd/monitor_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ Use --show-panels to show all available panels.`,
// set to tru to turn off incompatible color formatting
monitorCluster = true

setupColors()

found, _ := GetClusterConnection(clusterName)
if !found {
return errors.New(UnableToFindClusterMsg + clusterName)
Expand Down Expand Up @@ -1588,8 +1590,23 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
row := y1
col := x1
currentStyle := style

for _, r := range text {
s.SetContent(col, row, r, nil, style)
switch r {
case '\x01': // startRed
currentStyle = currentStyle.Foreground(tcell.ColorRed)
continue
case '\x02': // startYellow
currentStyle = currentStyle.Foreground(tcell.ColorYellow)
continue
case '\x03': // endColor
// Reset to the originally passed style
currentStyle = style
continue
}

s.SetContent(col, row, r, nil, currentStyle)
col++
if col >= x2 {
row++
Expand Down
Loading