Skip to content
Merged
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
92 changes: 21 additions & 71 deletions pkg/cmd/monitor_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"
"sync"
"time"
"unicode/utf8"
)

const (
Expand Down Expand Up @@ -90,7 +89,6 @@ var (

currentScreenWidth int
currentScreenHeight int
screenOffsetX int
)

type StyleConfig struct {
Expand Down Expand Up @@ -381,20 +379,7 @@ Use --show-panels to show all available panels.`,
close(exit)
return nil
}

if ev.Key() == tcell.KeyLeft {
if screenOffsetX > 0 {
screenOffsetX--
if err := refresh(screen, dataFetcher, parsedLayout, false); err != nil {
panic(err)
}
}
} else if ev.Key() == tcell.KeyRight {
screenOffsetX++
if err := refresh(screen, dataFetcher, parsedLayout, false); err != nil {
panic(err)
}
} else if pressedKey == '?' {
if pressedKey == '?' {
showHelp(screen)
if err := refresh(screen, dataFetcher, parsedLayout, true); err != nil {
panic(err)
Expand Down Expand Up @@ -423,7 +408,6 @@ Use --show-panels to show all available panels.`,
(pressedKey >= 'a' && pressedKey <= 'z' && pressedKey <= lastPanelCode) {
updateExpanded(pressedKey, screen, dataFetcher, parsedLayout)
}

}
}
},
Expand Down Expand Up @@ -620,19 +604,16 @@ func refresh(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout []st
func showHelp(screen tcell.Screen) {
help := []string{
"",
" Monitor Cluster CLI Help ",
" Monitor Cluster CLI Help ",
"",
" - 'p' toggle panel row padding",
" - '+' increase max height of all panels",
" - '-' decrease max height of all panels",
" - '0' reset max height of all panels",
" - '->' scroll right in text",
" - '<-' scroll left in text",
" ",
" - Key in [] to expand that panel",
" - ESC / CTRL-C to exit monitoring",
" - 'p' to toggle panel row padding",
" - '+' to increase max height of all panels",
" - '-' to decrease max height of all panels",
" - '0' to reset max height of all panels",
" - Key in [] to expand that panel",
" - ESC / CTRL-C to exit monitoring",
" ",
" Press any key to exit help.",
" Press any key to exit help.",
}

inHelp = true
Expand All @@ -644,10 +625,10 @@ func showHelp(screen tcell.Screen) {
x := currentScreenWidth/2 - 25
y := currentScreenHeight/2 - lenHelp

drawBox(screen, x, y, x+50, y+lenHelp+2, boxStyle, "Help")
drawBox(screen, x, y, x+53, y+lenHelp+2, boxStyle, "Help")

for line := 1; line <= lenHelp; line++ {
drawText(screen, x+1, y+line, x+currentScreenWidth-1, y+currentScreenHeight-1, textStyle, help[line-1], true)
drawText(screen, x+1, y+line, x+currentScreenWidth-1, y+currentScreenHeight-1, textStyle, help[line-1])
}
screen.Show()
_ = screen.PollEvent()
Expand Down Expand Up @@ -1662,7 +1643,6 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
title string
padding = " "
height = "0"
scroll = "S0 "
)
if cluster.ClusterName == "" && ignoreRESTErrors {
title = errorContent + " from " + dataFetcher.GetURL()
Expand All @@ -1676,73 +1656,43 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
} else if heightAdjust > 0 {
height = fmt.Sprintf("+%v ", heightAdjust)
}

if screenOffsetX > 0 {
scroll = fmt.Sprintf("S+%v ", screenOffsetX)
}

title = fmt.Sprintf("Coherence CLI: %s - %s %s %s ESC to quit. %s %s%s(%v)",
time.Now().Format(time.DateTime), cluster.ClusterName, version[0], additionalMonitorMsg, padding, height, scroll, lastDuration)
title = fmt.Sprintf("Coherence CLI: %s - %s (%s) ESC to quit %s. %s%s(%v)",
time.Now().Format(time.DateTime), cluster.ClusterName, version[0], additionalMonitorMsg, padding, height, lastDuration)
titleLen := len(title)
if titleLen < w-2 {
title = fmt.Sprintf("%s%-*s", title, w-titleLen-2, " ")
}
}
drawText(screen, 1, 0, w-1, h-1, textStyle.Reverse(true), title, true)
drawText(screen, 1, 0, w-1, h-1, textStyle.Reverse(true), title)
}

// drawText draws text on the screen.
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string, header ...bool) {
var scrollX = screenOffsetX

if len(header) > 0 && header[0] {
scrollX = 0
}

func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
row := y1
col := x1
currentStyle := style

visibleCols := x2 - x1
displayedCols := 0
charsSkipped := 0

for i := 0; i < len(text); {
// Handle control characters
switch text[i] {
for _, r := range text {
switch r {
case '\x01': // startRed
currentStyle = currentStyle.Foreground(tcell.ColorRed)
i++
continue
case '\x02': // startYellow
currentStyle = currentStyle.Foreground(tcell.ColorYellow)
i++
continue
case '\x03': // end color
case '\x03': // endColor
// Reset to the originally passed style
currentStyle = style
i++
continue
}

// Decode the next rune
r, size := utf8.DecodeRuneInString(text[i:])
i += size

if charsSkipped < scrollX {
charsSkipped++
continue
}

// Draw the character
s.SetContent(col, row, r, nil, currentStyle)
col++
displayedCols++

if col >= x2 {
row++
col = x1
}
if row > y2 || displayedCols >= visibleCols {
if row > y2 {
break
}
}
Expand Down Expand Up @@ -1780,7 +1730,7 @@ func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, title string
s.SetContent(x2, y2, tcell.RuneLRCorner, nil, style)
}

drawText(s, x1+2, y1, x2-1, y2-1, titleStyle, title, true)
drawText(s, x1+2, y1, x2-1, y2-1, titleStyle, title)
}

// getValidPanelTypes returns the list of panels for the --help command.
Expand Down
Loading