@@ -21,6 +21,7 @@ import (
2121 "strings"
2222 "sync"
2323 "time"
24+ "unicode/utf8"
2425)
2526
2627const (
8990
9091 currentScreenWidth int
9192 currentScreenHeight int
93+ screenOffsetX int
9294)
9395
9496type StyleConfig struct {
@@ -379,7 +381,20 @@ Use --show-panels to show all available panels.`,
379381 close (exit )
380382 return nil
381383 }
382- if pressedKey == '?' {
384+
385+ if ev .Key () == tcell .KeyLeft {
386+ if screenOffsetX > 0 {
387+ screenOffsetX --
388+ if err := refresh (screen , dataFetcher , parsedLayout , false ); err != nil {
389+ panic (err )
390+ }
391+ }
392+ } else if ev .Key () == tcell .KeyRight {
393+ screenOffsetX ++
394+ if err := refresh (screen , dataFetcher , parsedLayout , false ); err != nil {
395+ panic (err )
396+ }
397+ } else if pressedKey == '?' {
383398 showHelp (screen )
384399 if err := refresh (screen , dataFetcher , parsedLayout , true ); err != nil {
385400 panic (err )
@@ -408,6 +423,7 @@ Use --show-panels to show all available panels.`,
408423 (pressedKey >= 'a' && pressedKey <= 'z' && pressedKey <= lastPanelCode ) {
409424 updateExpanded (pressedKey , screen , dataFetcher , parsedLayout )
410425 }
426+
411427 }
412428 }
413429 },
@@ -604,16 +620,19 @@ func refresh(screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout []st
604620func showHelp (screen tcell.Screen ) {
605621 help := []string {
606622 "" ,
607- " Monitor Cluster CLI Help " ,
623+ " Monitor Cluster CLI Help " ,
608624 "" ,
609- " - 'p' to toggle panel row padding" ,
610- " - '+' to increase max height of all panels" ,
611- " - '-' to decrease max height of all panels" ,
612- " - '0' to reset max height of all panels" ,
613- " - Key in [] to expand that panel" ,
614- " - ESC / CTRL-C to exit monitoring" ,
625+ " - 'p' toggle panel row padding" ,
626+ " - '+' increase max height of all panels" ,
627+ " - '-' decrease max height of all panels" ,
628+ " - '0' reset max height of all panels" ,
629+ " - '->' scroll right in text" ,
630+ " - '<-' scroll left in text" ,
631+ " " ,
632+ " - Key in [] to expand that panel" ,
633+ " - ESC / CTRL-C to exit monitoring" ,
615634 " " ,
616- " Press any key to exit help." ,
635+ " Press any key to exit help." ,
617636 }
618637
619638 inHelp = true
@@ -625,10 +644,10 @@ func showHelp(screen tcell.Screen) {
625644 x := currentScreenWidth / 2 - 25
626645 y := currentScreenHeight / 2 - lenHelp
627646
628- drawBox (screen , x , y , x + 53 , y + lenHelp + 2 , boxStyle , "Help" )
647+ drawBox (screen , x , y , x + 50 , y + lenHelp + 2 , boxStyle , "Help" )
629648
630649 for line := 1 ; line <= lenHelp ; line ++ {
631- drawText (screen , x + 1 , y + line , x + currentScreenWidth - 1 , y + currentScreenHeight - 1 , textStyle , help [line - 1 ])
650+ drawText (screen , x + 1 , y + line , x + currentScreenWidth - 1 , y + currentScreenHeight - 1 , textStyle , help [line - 1 ], true )
632651 }
633652 screen .Show ()
634653 _ = screen .PollEvent ()
@@ -1643,6 +1662,7 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
16431662 title string
16441663 padding = " "
16451664 height = "0"
1665+ scroll = "S0 "
16461666 )
16471667 if cluster .ClusterName == "" && ignoreRESTErrors {
16481668 title = errorContent + " from " + dataFetcher .GetURL ()
@@ -1656,43 +1676,73 @@ func drawHeader(screen tcell.Screen, w, h int, cluster config.Cluster, dataFetch
16561676 } else if heightAdjust > 0 {
16571677 height = fmt .Sprintf ("+%v " , heightAdjust )
16581678 }
1659- title = fmt .Sprintf ("Coherence CLI: %s - %s (%s) ESC to quit %s. %s%s(%v)" ,
1660- time .Now ().Format (time .DateTime ), cluster .ClusterName , version [0 ], additionalMonitorMsg , padding , height , lastDuration )
1679+
1680+ if screenOffsetX > 0 {
1681+ scroll = fmt .Sprintf ("S+%v " , screenOffsetX )
1682+ }
1683+
1684+ title = fmt .Sprintf ("Coherence CLI: %s - %s %s %s ESC to quit. %s %s%s(%v)" ,
1685+ time .Now ().Format (time .DateTime ), cluster .ClusterName , version [0 ], additionalMonitorMsg , padding , height , scroll , lastDuration )
16611686 titleLen := len (title )
16621687 if titleLen < w - 2 {
16631688 title = fmt .Sprintf ("%s%-*s" , title , w - titleLen - 2 , " " )
16641689 }
16651690 }
1666- drawText (screen , 1 , 0 , w - 1 , h - 1 , textStyle .Reverse (true ), title )
1691+ drawText (screen , 1 , 0 , w - 1 , h - 1 , textStyle .Reverse (true ), title , true )
16671692}
16681693
16691694// drawText draws text on the screen.
1670- func drawText (s tcell.Screen , x1 , y1 , x2 , y2 int , style tcell.Style , text string ) {
1695+ func drawText (s tcell.Screen , x1 , y1 , x2 , y2 int , style tcell.Style , text string , header ... bool ) {
1696+ var scrollX = screenOffsetX
1697+
1698+ if len (header ) > 0 && header [0 ] {
1699+ scrollX = 0
1700+ }
1701+
16711702 row := y1
16721703 col := x1
16731704 currentStyle := style
16741705
1675- for _ , r := range text {
1676- switch r {
1706+ visibleCols := x2 - x1
1707+ displayedCols := 0
1708+ charsSkipped := 0
1709+
1710+ for i := 0 ; i < len (text ); {
1711+ // Handle control characters
1712+ switch text [i ] {
16771713 case '\x01' : // startRed
16781714 currentStyle = currentStyle .Foreground (tcell .ColorRed )
1715+ i ++
16791716 continue
16801717 case '\x02' : // startYellow
16811718 currentStyle = currentStyle .Foreground (tcell .ColorYellow )
1719+ i ++
16821720 continue
1683- case '\x03' : // endColor
1684- // Reset to the originally passed style
1721+ case '\x03' : // end color
16851722 currentStyle = style
1723+ i ++
16861724 continue
16871725 }
16881726
1727+ // Decode the next rune
1728+ r , size := utf8 .DecodeRuneInString (text [i :])
1729+ i += size
1730+
1731+ if charsSkipped < scrollX {
1732+ charsSkipped ++
1733+ continue
1734+ }
1735+
1736+ // Draw the character
16891737 s .SetContent (col , row , r , nil , currentStyle )
16901738 col ++
1739+ displayedCols ++
1740+
16911741 if col >= x2 {
16921742 row ++
16931743 col = x1
16941744 }
1695- if row > y2 {
1745+ if row > y2 || displayedCols >= visibleCols {
16961746 break
16971747 }
16981748 }
@@ -1730,7 +1780,7 @@ func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, title string
17301780 s .SetContent (x2 , y2 , tcell .RuneLRCorner , nil , style )
17311781 }
17321782
1733- drawText (s , x1 + 2 , y1 , x2 - 1 , y2 - 1 , titleStyle , title )
1783+ drawText (s , x1 + 2 , y1 , x2 - 1 , y2 - 1 , titleStyle , title , true )
17341784}
17351785
17361786// getValidPanelTypes returns the list of panels for the --help command.
0 commit comments