From c72057ae6bd4a976a079773c0c42bedb69589541 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Tue, 24 Feb 2015 08:08:09 +0100 Subject: [PATCH] screen: Reorder functions alphabetically and minor cleanup --- screen/screen.go | 113 ++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/screen/screen.go b/screen/screen.go index 4484e45..c29c6ba 100644 --- a/screen/screen.go +++ b/screen/screen.go @@ -19,23 +19,16 @@ type TermboxScreen struct { fg, bg termbox.Attribute } -type TermboxAttribute termbox.Attribute - -// reset the termbox to a clear screen -func (s *TermboxScreen) Initialise() { - err := termbox.Init() - if err != nil { - fmt.Println("Could not start termbox for " + lib.MyName() + ". View ~/." + lib.MyName() + ".log for error messages.") - log.Printf("Cannot start "+lib.MyName()+", termbox.Init() gave an error:\n%s\n", err) - os.Exit(1) +// print the characters in bold (for headings) but don't print them outside the screen +func (s *TermboxScreen) BoldPrintAt(x int, y int, text string) { + offset := 0 + for c := range text { + if (x + offset) < s.width { + termbox.SetCell(x+offset, y, rune(text[c]), s.fg|termbox.AttrBold, s.bg) + offset++ + } } - - s.Clear() - s.fg = termbox.ColorDefault - s.bg = termbox.ColorDefault - - x, y := termbox.Size() - s.SetSize(x, y) + s.Flush() } // clear the screen @@ -43,29 +36,56 @@ func (s *TermboxScreen) Clear() { termbox.Clear(termbox.ColorWhite, termbox.ColorBlack) } -func (s *TermboxScreen) Flush() { - termbox.Flush() +// close the screen +func (s *TermboxScreen) Close() { + termbox.Close() } -func (s *TermboxScreen) SetSize(width, height int) { - // if we get bigger then clear out the bottom line - for x := 0; x < s.width; x++ { - termbox.SetCell(x, s.height-1, ' ', s.fg, s.bg) - } - s.Flush() +// display a help page +func (s *TermboxScreen) DisplayHelp() { + s.PrintAt(0, 0, lib.MyName()+" version "+version.Version()+" "+lib.Copyright()) - s.width = width - s.height = height + s.PrintAt(0, 2, "Program to show the top I/O information by accessing information from the") + s.PrintAt(0, 3, "performance_schema schema. Ideas based on mysql-sys.") + + s.PrintAt(0, 5, "Keys:") + s.PrintAt(0, 6, "- - reduce the poll interval by 1 second (minimum 1 second)") + s.PrintAt(0, 7, "+ - increase the poll interval by 1 second") + s.PrintAt(0, 8, "h/? - this help screen") + s.PrintAt(0, 9, "q - quit") + s.PrintAt(0, 10, "t - toggle between showing time since resetting statistics or since P_S data was collected") + s.PrintAt(0, 11, "z - reset statistics") + s.PrintAt(0, 12, " or - change display modes between: latency, ops, file I/O, lock and user modes") + s.PrintAt(0, 13, " - change display modes to the previous screen (see above)") + s.PrintAt(0, 15, "Press h to return to main screen") } -func (s *TermboxScreen) Size() (int, int) { - return s.width, s.height +// flush changes to screen +func (s *TermboxScreen) Flush() { + termbox.Flush() } +// return the current height of the screen func (s *TermboxScreen) Height() int { return s.height } +// reset the termbox to a clear screen +func (s *TermboxScreen) Initialise() { + err := termbox.Init() + if err != nil { + fmt.Println("Could not start termbox for " + lib.MyName() + ". View ~/." + lib.MyName() + ".log for error messages.") + log.Printf("Cannot start "+lib.MyName()+", termbox.Init() gave an error:\n%s\n", err) + os.Exit(1) + } + + s.Clear() + s.fg = termbox.ColorDefault + s.bg = termbox.ColorDefault + + s.SetSize( termbox.Size() ) +} + // print the characters but don't print them outside the screen func (s *TermboxScreen) PrintAt(x int, y int, text string) { offset := 0 @@ -78,36 +98,19 @@ func (s *TermboxScreen) PrintAt(x int, y int, text string) { s.Flush() } -// print the characters in bold (for headings) but don't print them outside the screen -func (s *TermboxScreen) BoldPrintAt(x int, y int, text string) { - offset := 0 - for c := range text { - if (x + offset) < s.width { - termbox.SetCell(x+offset, y, rune(text[c]), s.fg|termbox.AttrBold, s.bg) - offset++ - } +// set the screen size +func (s *TermboxScreen) SetSize(width, height int) { + // if we get bigger then clear out the bottom line + for x := 0; x < s.width; x++ { + termbox.SetCell(x, s.height-1, ' ', s.fg, s.bg) } s.Flush() -} -func (s *TermboxScreen) DisplayHelp() { - s.PrintAt(0, 0, lib.MyName()+" version "+version.Version()+" (C) 2014 Simon J Mudd ") - - s.PrintAt(0, 2, "Program to show the top I/O information by accessing information from the") - s.PrintAt(0, 3, "performance_schema schema. Ideas based on mysql-sys.") - - s.PrintAt(0, 5, "Keys:") - s.PrintAt(0, 6, "- - reduce the poll interval by 1 second (minimum 1 second)") - s.PrintAt(0, 7, "+ - increase the poll interval by 1 second") - s.PrintAt(0, 8, "h/? - this help screen") - s.PrintAt(0, 9, "q - quit") - s.PrintAt(0, 10, "t - toggle between showing time since resetting statistics or since P_S data was collected") - s.PrintAt(0, 11, "z - reset statistics") - s.PrintAt(0, 12, " or - change display modes between: latency, ops, file I/O, lock and user modes") - s.PrintAt(0, 13, " - change display modes to the previous screen (see above)") - s.PrintAt(0, 15, "Press h to return to main screen") + s.width = width + s.height = height } -func (s *TermboxScreen) Close() { - termbox.Close() +// return the current (width, height) of the screen +func (s *TermboxScreen) Size() (int, int) { + return s.width, s.height } -- 2.20.1