Skip to content

Commit 94d6049

Browse files
author
Tim Middleton
authored
Remove mouse-click and create style option in monitor clusters (#332)
1 parent 93c4fd5 commit 94d6049

File tree

4 files changed

+177
-28
lines changed

4 files changed

+177
-28
lines changed

docs/reference/monitor_clusters.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ NOTE: The `monitor cluster` command is currently experimental only and may be ch
2222
* <<get-panels, `cohctl get panels`>> - displays the panels that have been created
2323
* <<add-panel, `cohctl add panel`>> - adds a panel to the list of panels that can be displayed
2424
* <<remove-panel, `cohctl remove panel`>> - removes a panel that has been created
25+
* <<set-default-style, `cohctl set default-style`>> - sets the default style for monitor clusters command
26+
* <<get-default-style, `cohctl get default-style`>> - gets the default style for monitor clusters command
2527
2628
[#monitor-cluster]
2729
==== Monitor Cluster
@@ -243,6 +245,28 @@ Are you sure you want to remove the panel my-panel? (y/n) y
243245
panel my-panel was removed
244246
----
245247
248+
[#set-default-style]
249+
==== Set Default Style
250+
251+
include::../../build/_output/docs-gen/set_default_style.adoc[tag=text]
252+
253+
[source,bash]
254+
----
255+
cohctl set default style ice
256+
Default style is now set to ice
257+
----
258+
259+
[#get-default-style]
260+
==== Get Default Style
261+
262+
include::../../build/_output/docs-gen/get_default_style.adoc[tag=text]
263+
264+
[source,bash]
265+
----
266+
cohctl get default style ice
267+
Default style is: ice
268+
----
269+
246270
=== See Also
247271
248272
* xref:clusters.adoc[Clusters]

pkg/cmd/monitor_cluster.go

Lines changed: 140 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/oracle/coherence-cli/pkg/fetcher"
1616
"github.com/oracle/coherence-cli/pkg/utils"
1717
"github.com/spf13/cobra"
18+
"github.com/spf13/viper"
1819
"log"
1920
"strings"
2021
"sync"
@@ -23,15 +24,17 @@ import (
2324

2425
const (
2526
defaultLayoutName = "default"
26-
pressAdditional = "(press key in [] or mouse to toggle expand, ? = help)"
27-
pressAdditionalReset = "(press key in [] or mouse/ESC to exit expand)"
27+
pressAdditional = "(press key in [] to toggle expand, ? = help)"
28+
pressAdditionalReset = "(press key in [] ESC to exit expand)"
2829
noContent = " No Content"
2930
errorContent = "Unable to retrieve data"
3031
unableToFindPanel = "unable to find panel [%v], use --help or --show-panels to see all options"
3132
serviceNameToken = "%SERVICE"
3233
cacheNameToken = "%CACHE"
3334
topicNameToken = "%TOPIC"
3435
subscriberToken = "%SUBSCRIBER"
36+
setDefaultStyleMsg = "Default style is now set to "
37+
getDefaultStyleMsg = "Default style is: "
3538
)
3639

3740
var (
@@ -55,6 +58,7 @@ var (
5558
setMaxHeight int
5659
originalMaxHeight int
5760
padMaxHeightParam = true
61+
colorStyleParam string
5862
showAllPanels bool
5963
ignoreRESTErrors bool
6064
disablePadding bool
@@ -74,8 +78,62 @@ var (
7478
heightAdjust int
7579
noContentArray = []string{" ", noContent, " "}
7680
drawnPositions map[rune]position
81+
82+
// color styles
83+
boxStyle = tcell.StyleDefault
84+
titleStyle = tcell.StyleDefault
85+
textStyle = tcell.StyleDefault
7786
)
7887

88+
type StyleConfig struct {
89+
TextStyle tcell.Style
90+
TitleStyle tcell.Style
91+
BoxStyle tcell.Style
92+
}
93+
94+
var styleConfigsMap = map[string]StyleConfig{
95+
"default": {
96+
TextStyle: tcell.StyleDefault,
97+
TitleStyle: tcell.StyleDefault,
98+
BoxStyle: tcell.StyleDefault,
99+
},
100+
"vintage": {
101+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorWheat),
102+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorCoral),
103+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorWhite),
104+
},
105+
"oceanic": {
106+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorLightCyan),
107+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorTurquoise),
108+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorNavy),
109+
},
110+
"tty": {
111+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorGreen),
112+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorWhite),
113+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorGray),
114+
},
115+
"monokai": {
116+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorDarkKhaki),
117+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorOrangeRed),
118+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorSlateGray),
119+
},
120+
"ice": {
121+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorLightSteelBlue),
122+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorCoral),
123+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorSlateGray),
124+
},
125+
"high-contrast": {
126+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorWhite),
127+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorRed),
128+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorWhite),
129+
},
130+
"light-mode": {
131+
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorBlack),
132+
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorDarkBlue),
133+
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorDarkGray),
134+
},
135+
}
136+
79137
var validPanels = []panelImpl{
80138
createContentPanel(7, "caches", "Caches", "show caches", cachesContent, cachesPanelData, servicesPanelData),
81139
createContentPanel(7, "cache-access", "Cache Access (%SERVICE/%CACHE)", "show cache access", cacheAccessContent, cachesPanelData, servicesPanelData),
@@ -169,6 +227,10 @@ Use --show-panels to show all available panels.`,
169227
return err
170228
}
171229

230+
if err = setColorStyle(); err != nil {
231+
return err
232+
}
233+
172234
if disablePadding {
173235
padMaxHeightParam = false
174236
}
@@ -214,7 +276,6 @@ Use --show-panels to show all available panels.`,
214276
return err
215277
}
216278
defer screen.Fini()
217-
screen.EnableMouse(tcell.MouseButtonEvents)
218279

219280
screen.SetStyle(tcell.StyleDefault)
220281

@@ -265,20 +326,6 @@ Use --show-panels to show all available panels.`,
265326
panic(err)
266327
}
267328
screen.Sync()
268-
case *tcell.EventMouse:
269-
if ev.Buttons() == tcell.Button1 {
270-
if expandedPanel == "" {
271-
x, y := ev.Position()
272-
for r, pos := range drawnPositions {
273-
if x >= pos.x && x < pos.x+pos.width && y >= pos.y && y < pos.y+pos.height {
274-
updateExpanded(r, screen, dataFetcher, parsedLayout)
275-
break
276-
}
277-
}
278-
} else {
279-
updateExpanded(rune('0'), screen, dataFetcher, parsedLayout)
280-
}
281-
}
282329
case *tcell.EventKey:
283330
pressedKey := ev.Rune()
284331
// Exit for 'q', ESC, or CTRL-C
@@ -320,6 +367,72 @@ Use --show-panels to show all available panels.`,
320367
},
321368
}
322369

370+
// setDefaultStyleCmd represents the set default-style or command.
371+
var setDefaultStyleCmd = &cobra.Command{
372+
Use: "default-style style",
373+
Short: "set default style for monitor clusters command",
374+
Long: `The 'set default-style' command sets the default style for monitor clusters command.`,
375+
Args: cobra.ExactArgs(1),
376+
RunE: func(cmd *cobra.Command, args []string) error {
377+
value := args[0]
378+
379+
_, err := getStyleValue(value)
380+
if err != nil {
381+
return err
382+
}
383+
384+
viper.Set(defaultStyleKey, value)
385+
err = WriteConfig()
386+
if err != nil {
387+
return err
388+
}
389+
cmd.Println(setDefaultStyleMsg + value)
390+
return nil
391+
},
392+
}
393+
394+
// getDefaultStyleCmd represents the get default-style command.
395+
var getDefaultStyleCmd = &cobra.Command{
396+
Use: "default-style",
397+
Short: "display the current default style for monitor clusters",
398+
Long: `The 'get default-style' command displays the current style for monitor clusters.`,
399+
Args: cobra.ExactArgs(0),
400+
RunE: func(cmd *cobra.Command, _ []string) error {
401+
cmd.Printf("%s%v\n", getDefaultStyleMsg, Config.DefaultStyle)
402+
return nil
403+
},
404+
}
405+
406+
func setColorStyle() error {
407+
// use default style if none specified
408+
if colorStyleParam == "" {
409+
colorStyleParam = Config.DefaultStyle
410+
}
411+
style, err := getStyleValue(colorStyleParam)
412+
if err != nil {
413+
return err
414+
}
415+
416+
textStyle = style.TextStyle
417+
titleStyle = style.TitleStyle
418+
boxStyle = style.BoxStyle
419+
420+
return nil
421+
}
422+
423+
func getStyleValue(styleValue string) (StyleConfig, error) {
424+
style, ok := styleConfigsMap[styleValue]
425+
if !ok {
426+
valid := make([]string, 0, len(styleConfigsMap))
427+
for k := range styleConfigsMap {
428+
valid = append(valid, k)
429+
}
430+
return StyleConfig{}, fmt.Errorf("invalid color style %s, valid values are %v", colorStyleParam, valid)
431+
}
432+
433+
return style, nil
434+
}
435+
323436
func updateExpanded(pressedKey rune, screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout []string) {
324437
if expandedPanel != "" {
325438
expandedPanel = ""
@@ -383,7 +496,7 @@ func showHelp(screen tcell.Screen) {
383496
" - '+' to increase max height of all panels",
384497
" - '-' to decrease max height of all panels",
385498
" - '0' to reset max height of all panels",
386-
" - Key in [] or click mouse to expand that panel",
499+
" - Key in [] to expand that panel",
387500
" - ESC / CTRL-C to exit monitoring",
388501
" ",
389502
" Press any key to exit help.",
@@ -397,10 +510,10 @@ func showHelp(screen tcell.Screen) {
397510
x := w/2 - 25
398511
y := h/2 - lenHelp
399512

400-
drawBox(screen, x, y, x+53, y+lenHelp+2, tcell.StyleDefault, "Help")
513+
drawBox(screen, x, y, x+53, y+lenHelp+2, boxStyle, "Help")
401514

402515
for line := 1; line <= lenHelp; line++ {
403-
drawText(screen, x+1, y+line, x+w-1, y+h-1, tcell.StyleDefault, help[line-1])
516+
drawText(screen, x+1, y+line, x+w-1, y+h-1, textStyle, help[line-1])
404517
}
405518
screen.Show()
406519
_ = screen.PollEvent()
@@ -422,7 +535,7 @@ func updateScreen(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout
422535
if refresh {
423536
startTime := time.Now()
424537
if initialRefresh {
425-
drawText(screen, w-20, 0, w, 0, tcell.StyleDefault, " Retrieving data...")
538+
drawText(screen, w-20, 0, w, 0, textStyle, " Retrieving data...")
426539
screen.Show()
427540
initialRefresh = false
428541
}
@@ -449,7 +562,7 @@ func updateScreen(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout
449562

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

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

455568
var (
@@ -1309,10 +1422,10 @@ func drawContent(screen tcell.Screen, dataFetcher fetcher.Fetcher, panel panelIm
13091422
trimmedText = fmt.Sprintf("%v%s", string(tcell.RuneHLine), "(trimmed)")
13101423
}
13111424

1312-
drawBox(screen, x, y, x+w-1, y+h, tcell.StyleDefault, fmt.Sprintf("%s[%v]%s", parseTitle(title), string(code), trimmedText))
1425+
drawBox(screen, x, y, x+w-1, y+h, boxStyle, fmt.Sprintf("%s[%v]%s", parseTitle(title), string(code), trimmedText))
13131426

13141427
for line := 1; line <= rows; line++ {
1315-
drawText(screen, x+1, y+line, x+w-1, y+h-1, tcell.StyleDefault, content[line-1])
1428+
drawText(screen, x+1, y+line, x+w-1, y+h-1, textStyle, content[line-1])
13161429
}
13171430

13181431
return rows + 2, nil
@@ -1364,7 +1477,7 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
13641477
title = fmt.Sprintf("%s%-*s", title, w-titleLen-2, " ")
13651478
}
13661479
}
1367-
drawText(screen, 1, 0, w-1, h-1, tcell.StyleDefault.Reverse(true), title)
1480+
drawText(screen, 1, 0, w-1, h-1, textStyle.Reverse(true), title)
13681481
}
13691482

13701483
// drawText draws text on the screen.
@@ -1416,7 +1529,7 @@ func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, title string
14161529
s.SetContent(x2, y2, tcell.RuneLRCorner, nil, style)
14171530
}
14181531

1419-
drawText(s, x1+2, y1, x2-1, y2-1, style, title)
1532+
drawText(s, x1+2, y1, x2-1, y2-1, titleStyle, title)
14201533
}
14211534

14221535
// getValidPanelTypes returns the list of panels for the --help command.
@@ -1462,6 +1575,7 @@ func init() {
14621575
monitorClusterCmd.Flags().StringVarP(&serviceName, serviceNameOption, "S", "", serviceNameDescription)
14631576
monitorClusterCmd.Flags().StringVarP(&selectedCache, "cache-name", "C", "", "cache name")
14641577
monitorClusterCmd.Flags().StringVarP(&selectedTopic, "topic-name", "T", "", "topic name")
1578+
monitorClusterCmd.Flags().StringVarP(&colorStyleParam, "style", "", "", "color style")
14651579
monitorClusterCmd.Flags().Int64VarP(&subscriber, "subscriber-id", "B", 0, "subscriber")
14661580
monitorClusterCmd.Flags().IntVarP(&setMaxHeight, "max-height", "M", 0, "override max height for all panels")
14671581
monitorClusterCmd.Flags().BoolVarP(&ignoreSpecialCaches, "ignore-special", "", false, ignoreCachesDescription)

pkg/cmd/root.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const (
7272
currentContextKey = "currentContext"
7373
debugContextKey = "debug"
7474
colorContextKey = "color"
75+
defaultStyleKey = "defaultStyle"
7576
useGradleContextKey = "useGradle"
7677
ignoreCertsContextKey = "ignoreInvalidCerts"
7778
requestTimeoutKey = "requestTimeout"
@@ -193,6 +194,7 @@ type CoherenceCLIConfig struct {
193194
UseGradle bool `json:"useGradle"`
194195
Profiles []ProfileValue `mapstructure:"profiles"`
195196
Panels []Panel `mapstructure:"panels"`
197+
DefaultStyle string `json:"defaultStyle"`
196198
}
197199

198200
// ProfileValue describes a profile to be used for creating and starting clusters.
@@ -366,7 +368,7 @@ func initConfig() {
366368

367369
viper.AutomaticEnv() // read in environment variables that match
368370

369-
if err := viper.ReadInConfig(); err != nil {
371+
if err = viper.ReadInConfig(); err != nil {
370372
_, foundError := err.(viper.ConfigFileNotFoundError)
371373
_, pathError := err.(*os.PathError)
372374

@@ -403,7 +405,7 @@ func initConfig() {
403405
}
404406
} else {
405407
// load the config
406-
if err := viper.Unmarshal(&Config); err != nil {
408+
if err = viper.Unmarshal(&Config); err != nil {
407409
rootCmd.Println(err)
408410
os.Exit(1)
409411
}
@@ -419,6 +421,11 @@ func initConfig() {
419421
}
420422
}
421423

424+
// default defaultStyle
425+
if Config.DefaultStyle == "" {
426+
Config.DefaultStyle = "default"
427+
}
428+
422429
// setup logs directory
423430
logsDirectory = filepath.Join(cfgDirectory, logsDirName)
424431
err = ensureLogsDir()
@@ -578,6 +585,7 @@ func Initialize(command *cobra.Command) *cobra.Command {
578585
getCmd.AddCommand(getFederationIncomingCmd)
579586
getCmd.AddCommand(getFederationOutgoingCmd)
580587
getCmd.AddCommand(getPanelsCmd)
588+
getCmd.AddCommand(getDefaultStyleCmd)
581589

582590
// set command
583591
command.AddCommand(setCmd)
@@ -598,6 +606,7 @@ func Initialize(command *cobra.Command) *cobra.Command {
598606
setCmd.AddCommand(setFederationCmd)
599607
setCmd.AddCommand(setColorCmd)
600608
setCmd.AddCommand(setClusterCmd)
609+
setCmd.AddCommand(setDefaultStyleCmd)
601610

602611
// run command
603612
command.AddCommand(runCmd)

scripts/generate-doc-snippets.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ create_doc $DOCS_DIR/discover_clusters "${COHCTL} discover clusters --help"
4848
create_doc $DOCS_DIR/get_cluster_config "${COHCTL} get cluster-config --help"
4949
create_doc $DOCS_DIR/get_cluster_description "${COHCTL} get cluster-description --help"
5050
create_doc $DOCS_DIR/monitor_cluster "${COHCTL} monitor cluster --help"
51+
create_doc $DOCS_DIR/set_default_style "${COHCTL} set default-style --help"
52+
create_doc $DOCS_DIR/get_default_style "${COHCTL} get default-style --help"
5153
create_doc $DOCS_DIR/add_panel "${COHCTL} add panel --help"
5254
create_doc $DOCS_DIR/get_panels "${COHCTL} get panels --help"
5355
create_doc $DOCS_DIR/remove_panel "${COHCTL} remove panel --help"

0 commit comments

Comments
 (0)