import time
import curses
import curses.panel
import logging


class Base(object):
    def __init__(self, window):
        lines, columns = window.getmaxyx()
        self._window = curses.newwin(lines, columns)
        self._panel = curses.panel.new_panel(self._window)

    def writeStatusLine(self, measurements):
        line = 'time: {0}| {1} measurements, at most {2} visible'.format(time.asctime(), len(measurements), self.availableLines())
        columns = self.dimensions()['columns']
        self._window.addstr(0, 0, line.ljust(columns), curses.A_REVERSE)

    def availableLines(self):
        STATUS_LINE = 1
        return self.dimensions()['lines'] - STATUS_LINE

    def refresh(self):
        curses.panel.update_panels()
        curses.doupdate()

    def onTop(self):
        logging.info('put {0} view on top'.format(self.__class__.__name__))
        self._panel.top()
        curses.panel.update_panels()
        curses.doupdate()

    def clearScreen(self):
        self._window.clear()
        self._window.move(0, 0)

    def writeLine(self, thing, line):
        self._window.addstr(line, 0, str(thing))

    def dimensions(self):
        lines, columns = self._window.getmaxyx()
        return {'lines': lines, 'columns': columns}

import time
import curses
import curses.panel
import logging


class Base(object):
    def __init__(self, window):
        lines, columns = window.getmaxyx()
        self._window = curses.newwin(lines, columns)
        self._panel = curses.panel.new_panel(self._window)

    def writeStatusLine(self, measurements):
        line = 'time: {0}| {1} measurements, at most {2} visible'.format(time.asctime(), len(measurements), self.availableLines())
        columns = self.dimensions()['columns']
        self._window.addstr(0, 0, line.ljust(columns), curses.A_REVERSE)

    def availableLines(self):
        STATUS_LINE = 1
        return self.dimensions()['lines'] - STATUS_LINE

    def refresh(self):
        curses.panel.update_panels()
        curses.doupdate()

    def onTop(self):
        logging.info('put {0} view on top'.format(self.__class__.__name__))
        self._panel.top()
        curses.panel.update_panels()
        curses.doupdate()

    def clearScreen(self):
        self._window.erase()
        self._window.move(0, 0)

    def writeLine(self, thing, line):
        self._window.addstr(line, 0, str(thing))

    def dimensions(self):
        lines, columns = self._window.getmaxyx()
        return {'lines': lines, 'columns': columns}

Use 'erase' to clear the screen
tools/scyllatop: Use 'erase' to clear the screen

The 'clear' function explicitly clears the screen and repaints it which
causes really annoying flicker. Use 'erase' to make scyllatop more
pleasant on the eyes.

Message-Id: <2bf04f96d7d510dddf38de01959db6b168f25a31@scylladb.com>
