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 type TermboxAttribute termbox.Attribute
24 // reset the termbox to a clear screen
25 func (s *TermboxScreen) Initialise() {
28 fmt.Println("Could not start termbox for " + lib.MyName() + ". View ~/." + lib.MyName() + ".log for error messages.")
29 log.Printf("Cannot start "+lib.MyName()+", termbox.Init() gave an error:\n%s\n", err)
34 s.fg = termbox.ColorDefault
35 s.bg = termbox.ColorDefault
37 x, y := termbox.Size()
42 func (s *TermboxScreen) Clear() {
43 termbox.Clear(termbox.ColorWhite, termbox.ColorBlack)
46 func (s *TermboxScreen) Flush() {
50 func (s *TermboxScreen) SetSize(width, height int) {
51 // if we get bigger then clear out the bottom line
52 for x := 0; x < s.width; x++ {
53 termbox.SetCell(x, s.height-1, ' ', s.fg, s.bg)
61 func (s *TermboxScreen) Size() (int, int) {
62 return s.width, s.height
65 func (s *TermboxScreen) Height() int {
69 // print the characters but don't print them outside the screen
70 func (s *TermboxScreen) PrintAt(x int, y int, text string) {
73 if (x + offset) < s.width {
74 termbox.SetCell(x+offset, y, rune(text[c]), s.fg, s.bg)
81 // print the characters in bold (for headings) but don't print them outside the screen
82 func (s *TermboxScreen) BoldPrintAt(x int, y int, text string) {
85 if (x + offset) < s.width {
86 termbox.SetCell(x+offset, y, rune(text[c]), s.fg | termbox.AttrBold, s.bg)
93 func (s *TermboxScreen) DisplayHelp() {
94 s.PrintAt(0, 0, lib.MyName()+" version "+version.Version()+" (C) 2014 Simon J Mudd <sjmudd@pobox.com>")
96 s.PrintAt(0, 2, "Program to show the top I/O information by accessing information from the")
97 s.PrintAt(0, 3, "performance_schema schema. Ideas based on mysql-sys.")
99 s.PrintAt(0, 5, "Keys:")
100 s.PrintAt(0, 6, "- - reduce the poll interval by 1 second (minimum 1 second)")
101 s.PrintAt(0, 7, "+ - increase the poll interval by 1 second")
102 s.PrintAt(0, 8, "h/? - this help screen")
103 s.PrintAt(0, 9, "q - quit")
104 s.PrintAt(0, 10, "t - toggle between showing time since resetting statistics or since P_S data was collected")
105 s.PrintAt(0, 11, "z - reset statistics")
106 s.PrintAt(0, 12, "<tab> or <right arrow> - change display modes between: latency, ops, file I/O, lock and user modes")
107 s.PrintAt(0, 13, "<left arrow> - change display modes to the previous screen (see above)")
108 s.PrintAt(0, 15, "Press h to return to main screen")
111 func (s *TermboxScreen) Close() {