1 // This file configures the screen, basically remembering the size
2 // and foreground and background colours.
10 "github.com/nsf/termbox-go"
12 "github.com/sjmudd/pstop/lib"
13 "github.com/sjmudd/pstop/version"
16 // this just allows me to use stuff with it
17 type TermboxScreen struct {
19 fg, bg termbox.Attribute
22 // print the characters in bold (for headings) but don't print them outside the screen
23 func (s *TermboxScreen) BoldPrintAt(x int, y int, text string) {
26 if (x + offset) < s.width {
27 termbox.SetCell(x+offset, y, rune(text[c]), s.fg|termbox.AttrBold, s.bg)
35 func (s *TermboxScreen) Clear() {
36 termbox.Clear(termbox.ColorWhite, termbox.ColorBlack)
40 func (s *TermboxScreen) Close() {
44 // display a help page
45 func (s *TermboxScreen) DisplayHelp() {
46 s.PrintAt(0, 0, lib.MyName()+" version "+version.Version()+" "+lib.Copyright())
48 s.PrintAt(0, 2, "Program to show the top I/O information by accessing information from the")
49 s.PrintAt(0, 3, "performance_schema schema. Ideas based on mysql-sys.")
51 s.PrintAt(0, 5, "Keys:")
52 s.PrintAt(0, 6, "- - reduce the poll interval by 1 second (minimum 1 second)")
53 s.PrintAt(0, 7, "+ - increase the poll interval by 1 second")
54 s.PrintAt(0, 8, "h/? - this help screen")
55 s.PrintAt(0, 9, "q - quit")
56 s.PrintAt(0, 10, "t - toggle between showing time since resetting statistics or since P_S data was collected")
57 s.PrintAt(0, 11, "z - reset statistics")
58 s.PrintAt(0, 12, "<tab> or <right arrow> - change display modes between: latency, ops, file I/O, lock and user modes")
59 s.PrintAt(0, 13, "<left arrow> - change display modes to the previous screen (see above)")
60 s.PrintAt(0, 15, "Press h to return to main screen")
63 // flush changes to screen
64 func (s *TermboxScreen) Flush() {
68 // return the current height of the screen
69 func (s *TermboxScreen) Height() int {
73 // reset the termbox to a clear screen
74 func (s *TermboxScreen) Initialise() {
77 fmt.Println("Could not start termbox for " + lib.MyName() + ". View ~/." + lib.MyName() + ".log for error messages.")
78 log.Printf("Cannot start "+lib.MyName()+", termbox.Init() gave an error:\n%s\n", err)
83 s.fg = termbox.ColorDefault
84 s.bg = termbox.ColorDefault
86 s.SetSize( termbox.Size() )
89 // print the characters but don't print them outside the screen
90 func (s *TermboxScreen) PrintAt(x int, y int, text string) {
93 if (x + offset) < s.width {
94 termbox.SetCell(x+offset, y, rune(text[c]), s.fg, s.bg)
101 // set the screen size
102 func (s *TermboxScreen) SetSize(width, height int) {
103 // if we get bigger then clear out the bottom line
104 for x := 0; x < s.width; x++ {
105 termbox.SetCell(x, s.height-1, ' ', s.fg, s.bg)
113 // return the current (width, height) of the screen
114 func (s *TermboxScreen) Size() (int, int) {
115 return s.width, s.height
118 // create a channel for termbox.Events and run a poller to send
119 // these events to the channel. Return the channel.
120 func (s TermboxScreen) TermBoxChan() chan termbox.Event {
121 termboxChan := make(chan termbox.Event)
124 termboxChan <- termbox.PollEvent()