X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=screen%2Fscreen.go;h=4d40793d3404d827d20571d2f8cdcbb660988464;hb=HEAD;hp=6a9a78818e21be8322b946fbad65c60bb3eddb4e;hpb=22b9be6e17f9ae78c7bff19696ce9da44d6c8189;p=pstop.git diff --git a/screen/screen.go b/screen/screen.go index 6a9a788..4d40793 100644 --- a/screen/screen.go +++ b/screen/screen.go @@ -19,7 +19,56 @@ type TermboxScreen struct { fg, bg termbox.Attribute } -type TermboxAttribute termbox.Attribute +// 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.Flush() +} + +// clear the screen +func (s *TermboxScreen) Clear() { + termbox.Clear(termbox.ColorDefault, termbox.ColorDefault) +} + +// close the screen +func (s *TermboxScreen) Close() { + termbox.Close() +} + +// display a help page +func (s *TermboxScreen) DisplayHelp() { + s.PrintAt(0, 0, lib.MyName()+" version "+version.Version()+" "+lib.Copyright()) + + 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") +} + +// 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() { @@ -34,19 +83,30 @@ func (s *TermboxScreen) Initialise() { s.fg = termbox.ColorDefault s.bg = termbox.ColorDefault - x, y := termbox.Size() - s.SetSize(x, y) + s.SetSize(termbox.Size()) } -// clear the screen -func (s *TermboxScreen) Clear() { - termbox.Clear(termbox.ColorWhite, termbox.ColorBlack) +// print the characters but don't print them outside the screen +func (s *TermboxScreen) PrintAt(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, s.bg) + offset++ + } + } + s.Flush() } -func (s *TermboxScreen) Flush() { - termbox.Flush() +// Clear EOL +func (s *TermboxScreen) ClearLine(x int, y int) { + for i := x; i < s.width; i++ { + termbox.SetCell(i, y, ' ', termbox.ColorDefault, termbox.ColorDefault) + } + s.Flush() } +// 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++ { @@ -58,43 +118,19 @@ func (s *TermboxScreen) SetSize(width, height int) { s.height = height } +// return the current (width, height) of the screen func (s *TermboxScreen) Size() (int, int) { return s.width, s.height } -func (s *TermboxScreen) Height() int { - return s.height -} - -// print the characters but don't print them outside the screen -func (s *TermboxScreen) PrintAt(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, s.bg) - offset++ +// create a channel for termbox.Events and run a poller to send +// these events to the channel. Return the channel. +func (s TermboxScreen) TermBoxChan() chan termbox.Event { + termboxChan := make(chan termbox.Event) + go func() { + for { + termboxChan <- termbox.PollEvent() } - } - 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, " - change display modes between: latency, ops, file I/O, lock and user modes") - s.PrintAt(0, 14, "Press h to return to main screen") -} - -func (s *TermboxScreen) Close() { - termbox.Close() + }() + return termboxChan }