@@ -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
2425const (
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
3740var (
5558 setMaxHeight int
5659 originalMaxHeight int
5760 padMaxHeightParam = true
61+ colorStyleParam string
5862 showAllPanels bool
5963 ignoreRESTErrors bool
6064 disablePadding bool
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+
79137var 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+
323436func 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 )
0 commit comments