Skip to content

Commit

Permalink
Minor update to use mouse to select panel (#225)
Browse files Browse the repository at this point in the history
* Minor update to use mouse to select panel
* more changes
  • Loading branch information
tmiddlet2666 authored Aug 26, 2024
1 parent 99c4c33 commit 6e2f1d9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
13 changes: 6 additions & 7 deletions docs/reference/99_monitor_clusters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ cohctl monitor cluster local
Output:
[source,bash,subs="attributes"]
----
Coherence CLI: 2024-05-06 13:25:17 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] to toggle expand, ? = help).
(75.289463ms)
Coherence CLI: 2024-05-06 13:25:17 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] or mouse to toggle expand, ? = help). (75.289463ms)
┌─Members [1]─(trimmed)──────────────────────────────────────────┐┌─Health Summary [2]────────────────────────────────────────────┐
│Total cluster members: 3 ││NAME SUB TYPE MEMBERS STARTED LIVE READY │
│Storage enabled count: 3 ││$SYS:Config Service 3 3 3 3 │
Expand Down Expand Up @@ -91,15 +90,15 @@ You can press `?` to display the help which is shown below:
- '+' 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
- Key in [] or click mouse to expand that panel
- ESC / CTRL-C to exit monitoring
Press any key to exit help.
----
NOTE: If the title of a panel includes "trimmed" it means there are more rows to display.
You can press the key indicated in the `[]` to expand that panel.
You can press the key indicated in the `[]` to expand that panel. You can also click the mouse
in the panel you wish to expand.
**Monitor the cluster and specify the panels for services and caches on one line and then members on the next**
Expand All @@ -110,7 +109,7 @@ cohctl monitor cluster local -l services,caches:members
Output:
[source,bash]
----
Coherence CLI: 2024-05-06 13:26:47 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] to toggle expand, ? = help).
Coherence CLI: 2024-05-06 13:26:47 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] or mouse to toggle expand, ? = help).
┌─Services [1]─(trimmed)─────────────────────────────────────────┐┌─Caches [2]────────────────────────────────────────────────────┐
│SERVICE NAME TYPE MEMBERS STATUS HA ST││Total Caches: 3, Total primary storage: 4 MB │
Expand Down Expand Up @@ -145,7 +144,7 @@ cohctl monitor cluster local -l default-cache -C test1
Output:
[source,bash]
----
Coherence CLI: 2024-05-06 11:13:59 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] to toggle expand, ? = help).
Coherence CLI: 2024-05-06 11:13:59 - Monitoring cluster local (22.06.8) ESC to quit (press key in [] or mouse to toggle expand, ? = help).
┌─Caches [1]─────────────────────────────────────────────────────┐┌─Cache Indexes (PartitionedCache/test1) [2]────────────────────┐
│Total Caches: 3, Total primary storage: 4 MB ││Total Indexing Bytes: 0 │
Expand Down
67 changes: 52 additions & 15 deletions pkg/cmd/monitor_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

const (
defaultLayoutName = "default"
pressAdditional = "(press key in [] to toggle expand, ? = help)"
pressAdditionalReset = "(press key in [] to exit expand)"
pressAdditional = "(press key in [] or mouse to toggle expand, ? = help)"
pressAdditionalReset = "(press key in [] or mouse to exit expand)"
noContent = " No Content"
errorContent = "Unable to retrieve data"
unableToFindPanel = "unable to find panel [%v], use --help or --show-panels to see all options"
Expand All @@ -36,7 +36,7 @@ const (

var (
defaultMap = map[string]string{
"default": "members:services,caches:proxies,http-servers:machines,network-stats",
"default": "members,healthSummary:services,caches:proxies,http-servers:machines,network-stats",
"default-service": "services:service-members:service-distributions",
"default-cache": "caches,cache-indexes:cache-access:cache-storage:cache-stores:cache-partitions",
"default-topic": "topics:topic-members:subscribers:subscriber-groups",
Expand Down Expand Up @@ -69,6 +69,7 @@ var (
allBaseData []string
heightAdjust int
noContentArray = []string{" ", noContent, " "}
drawnPositions map[rune]position
)

var validPanels = []panelImpl{
Expand Down Expand Up @@ -108,6 +109,13 @@ var validPanels = []panelImpl{
createContentPanel(8, "view-caches", "View Caches", "show view caches", viewCachesContent, servicesPanelData),
}

type position struct {
x int
y int
width int
height int
}

// monitorClusterCmd represents the monitor cluster command
var monitorClusterCmd = &cobra.Command{
Use: "cluster connection-name",
Expand Down Expand Up @@ -186,6 +194,7 @@ Use --show-panels to show all available panels.`,
return err
}
defer screen.Fini()
screen.EnableMouse(tcell.MouseButtonEvents)

screen.SetStyle(tcell.StyleDefault)

Expand Down Expand Up @@ -234,6 +243,20 @@ Use --show-panels to show all available panels.`,
panic(err)
}
screen.Sync()
case *tcell.EventMouse:
if ev.Buttons() == tcell.Button1 {
if expandedPanel == "" {
x, y := ev.Position()
for r, pos := range drawnPositions {
if x >= pos.x && x < pos.x+pos.width && y >= pos.y && y < pos.y+pos.height {
updateExpanded(r, screen, dataFetcher, parsedLayout)
break
}
}
} else {
updateExpanded(rune('0'), screen, dataFetcher, parsedLayout)
}
}
case *tcell.EventKey:
pressedKey := ev.Rune()
// Exit for 'q', ESC, or CTRL-C
Expand Down Expand Up @@ -268,22 +291,26 @@ Use --show-panels to show all available panels.`,
}
} else if (pressedKey >= '1' && pressedKey <= '9' && pressedKey <= lastPanelCode) ||
(pressedKey >= 'a' && pressedKey <= 'z' && pressedKey <= lastPanelCode) {
if expandedPanel != "" {
expandedPanel = ""
additionalMonitorMsg = pressAdditional
} else {
expandedPanel = string(pressedKey)
additionalMonitorMsg = pressAdditionalReset
}
if err := refresh(screen, dataFetcher, parsedLayout, false); err != nil {
panic(err)
}
updateExpanded(pressedKey, screen, dataFetcher, parsedLayout)
}
}
}
},
}

func updateExpanded(pressedKey rune, screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout []string) {
if expandedPanel != "" {
expandedPanel = ""
additionalMonitorMsg = pressAdditional
} else {
expandedPanel = string(pressedKey)
additionalMonitorMsg = pressAdditionalReset
}
if err := refresh(screen, dataFetcher, parsedLayout, false); err != nil {
panic(err)
}
}

func increaseMaxHeight() {
for i := range validPanels {
validPanels[i].MaxHeight++
Expand Down Expand Up @@ -327,7 +354,7 @@ func showHelp(screen tcell.Screen) {
" - '+' 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",
" - Key in [] or click mouse to expand that panel",
" - ESC / CTRL-C to exit monitoring",
" ",
" Press any key to exit help.",
Expand All @@ -341,7 +368,7 @@ func showHelp(screen tcell.Screen) {
x := w/2 - 25
y := h/2 - lenHelp

drawBox(screen, x, y, x+50, y+lenHelp+2, tcell.StyleDefault, "Help")
drawBox(screen, x, y, x+53, y+lenHelp+2, tcell.StyleDefault, "Help")

for line := 1; line <= lenHelp; line++ {
drawText(screen, x+1, y+line, x+w-1, y+h-1, tcell.StyleDefault, help[line-1])
Expand Down Expand Up @@ -393,6 +420,9 @@ func updateScreen(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout

drawHeader(screen, w, h, cluster, dataFetcher)

// re-create the list of drawn positions, so we can determine mouse click location
drawnPositions = make(map[rune]position, 0)

var (
widths []int
panelNumber = 0
Expand Down Expand Up @@ -452,6 +482,9 @@ func updateScreen(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout
if rows > maxHeight {
maxHeight = rows
}

// save the position of the panel
drawnPositions[panelCode] = position{x: realStartX, y: realStartY, width: realWidth, height: maxHeight}
}
panelNumber++
}
Expand Down Expand Up @@ -1210,6 +1243,10 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
}
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, tcell.StyleDefault.Reverse(true), title)
}
Expand Down

0 comments on commit 6e2f1d9

Please sign in to comment.