6060 originalMaxHeight int
6161 padMaxHeightParam = true
6262 colorStyleParam string
63+ previewStylesParam bool
6364 showAllPanels bool
6465 ignoreRESTErrors bool
6566 disablePadding bool
@@ -158,6 +159,11 @@ var styleConfigsMap = map[string]StyleConfig{
158159 TitleStyle : tcell .StyleDefault .Foreground (tcell .ColorPeru ),
159160 BoxStyle : tcell .StyleDefault .Foreground (tcell .ColorMaroon ),
160161 },
162+ "fog" : {
163+ TextStyle : tcell .StyleDefault .Foreground (tcell .ColorGainsboro ),
164+ TitleStyle : tcell .StyleDefault .Foreground (tcell .ColorSlateGray ),
165+ BoxStyle : tcell .StyleDefault .Foreground (tcell .ColorDarkSlateGray ),
166+ },
161167}
162168
163169var validPanels = []panelImpl {
@@ -220,7 +226,7 @@ require you to specify cache, service, topic or subscriber.
220226Use --show-panels to show all available panels.` ,
221227 ValidArgsFunction : completionAllClusters ,
222228 Args : func (cmd * cobra.Command , args []string ) error {
223- if len (args ) != 1 && ! showAllPanels {
229+ if len (args ) != 1 && ( ! showAllPanels && ! previewStylesParam ) {
224230 displayErrorAndExit (cmd , youMustProviderConnectionMessage )
225231 }
226232 return nil
@@ -238,6 +244,10 @@ Use --show-panels to show all available panels.`,
238244 return nil
239245 }
240246
247+ if previewStylesParam {
248+ return previewAllStyles ()
249+ }
250+
241251 clusterName = args [0 ]
242252
243253 // set to tru to turn off incompatible color formatting
@@ -429,6 +439,68 @@ var getDefaultStyleCmd = &cobra.Command{
429439 },
430440}
431441
442+ func previewAllStyles () error {
443+ screen , err := tcell .NewScreen ()
444+ if err != nil {
445+ return err
446+ }
447+ if err = screen .Init (); err != nil {
448+ return err
449+ }
450+ defer screen .Fini ()
451+
452+ screen .SetStyle (tcell .StyleDefault )
453+
454+ // ensure we reset the screen on any panic
455+ defer func () {
456+ if r := recover (); r != nil {
457+ screen .Clear ()
458+ screen .Show ()
459+ screen .Fini ()
460+ log .Println ("Panic: " , r )
461+ }
462+ }()
463+
464+ sortedStyles := getAllSortedStyles ()
465+
466+ y := 1
467+ x := 2
468+ row := 1
469+ for _ , styleKey := range sortedStyles {
470+ if style , ok := styleConfigsMap [styleKey ]; ok {
471+ titleStyle = style .TitleStyle
472+ drawBox (screen , x , y , x + 40 , y + 4 , style .BoxStyle , fmt .Sprintf ("Example style: [%s]" , styleKey ))
473+ drawText (screen , x + 1 , y + 1 , x + 39 , y + 1 , style .TextStyle , "NODE ID ADDRESS PORT PROCESS" )
474+ drawText (screen , x + 1 , y + 2 , x + 39 , y + 2 , style .TextStyle , " 1 /127.0.0.1 58086 97529" )
475+ drawText (screen , x + 1 , y + 3 , x + 39 , y + 3 , style .TextStyle , " 2 /127.0.0.1 58044 66466" )
476+ }
477+
478+ if row % 2 == 0 {
479+ // move to next line
480+ y += 5
481+ x = 2
482+ } else {
483+ // move across
484+ x += 45
485+ }
486+ row ++
487+ }
488+
489+ drawText (screen , 2 , y + 1 , 40 , y + 40 , tcell .StyleDefault , "Press any key to continue" )
490+
491+ screen .Show ()
492+
493+ // Wait for any key press
494+ for {
495+ ev := screen .PollEvent ()
496+ if _ , ok := ev .(* tcell.EventKey ); ok {
497+ break
498+ }
499+ }
500+
501+ return nil
502+ }
503+
432504func setColorStyle () error {
433505 // use default style if none specified
434506 if colorStyleParam == "" {
@@ -449,17 +521,22 @@ func setColorStyle() error {
449521func getStyleValue (styleValue string ) (StyleConfig , error ) {
450522 style , ok := styleConfigsMap [styleValue ]
451523 if ! ok {
452- valid := make ([]string , 0 , len (styleConfigsMap ))
453- for k := range styleConfigsMap {
454- valid = append (valid , k )
455- }
456- sort .Strings (valid )
457- return StyleConfig {}, fmt .Errorf ("invalid color style %s, valid values are %v" , colorStyleParam , valid )
524+ return StyleConfig {}, fmt .Errorf ("invalid color style %s, valid values are %v" , colorStyleParam , getAllSortedStyles ())
458525 }
459526
460527 return style , nil
461528}
462529
530+ func getAllSortedStyles () []string {
531+ sortedList := make ([]string , 0 , len (styleConfigsMap ))
532+ for k := range styleConfigsMap {
533+ sortedList = append (sortedList , k )
534+ }
535+ sort .Strings (sortedList )
536+
537+ return sortedList
538+ }
539+
463540func updateExpanded (pressedKey rune , screen tcell.Screen , dataFetcher fetcher.Fetcher , parsedLayout []string ) {
464541 if expandedPanel != "" {
465542 expandedPanel = ""
@@ -1606,4 +1683,5 @@ func init() {
16061683 monitorClusterCmd .Flags ().Int64VarP (& subscriber , "subscriber-id" , "B" , 0 , "subscriber" )
16071684 monitorClusterCmd .Flags ().IntVarP (& setMaxHeight , "max-height" , "M" , 0 , "override max height for all panels" )
16081685 monitorClusterCmd .Flags ().BoolVarP (& ignoreSpecialCaches , "ignore-special" , "" , false , ignoreCachesDescription )
1686+ monitorClusterCmd .Flags ().BoolVarP (& previewStylesParam , "preview-styles" , "" , false , "preview all the styles" )
16091687}
0 commit comments