예제 #1
0
    def __InsertColHeader(self, stdscr, ch: CursesHelper):
        #o = TerminalOutput()
        hName = ch.AdjustColumn("Name", ch.width / 4)
        hStatus = ch.AdjustColumn("Status", ch.width / 4)
        hProtocol = ch.AdjustColumn("Protocol", ch.width / 4)
        hMs = ch.AdjustColumn("MS", ch.width / 4)
        header = f"{hName}{hStatus}{hProtocol}{hMs}"

        stdscr.attron(curses.color_pair(3))
        stdscr.addstr(1, 0, header)
        #stdscr.addstr(2, len(header), " " * (ch.width - len(header) - 1))
        stdscr.attroff(curses.color_pair(3))
        pass
예제 #2
0
 def __InsertLine(self, stdscr, ch: CursesHelper, yCord):
     #o = TerminalOutput()
     reports = self.monitor.report
     for i in reports:
         lName = ch.AdjustColumn(i.name, ch.width / 4)
         lStatus = ch.AdjustColumn(i.status, ch.width / 4)
         lProtocol = ch.AdjustColumn(i.protocol.upper(), ch.width / 4)
         lMs = ch.AdjustColumn(str(i.ms), ch.width / 4)
         line: str = f"{lName}{lStatus}{lProtocol}{lMs}"
         if i.status == "Offline":
             stdscr.attron(curses.color_pair(2))
             stdscr.addstr(yCord, 0, line)
             stdscr.attroff(curses.color_pair(2))
         elif i.status == "Online":
             stdscr.attron(curses.color_pair(4))
             stdscr.addstr(yCord, 0, line)
             stdscr.attroff(curses.color_pair(4))
         else:
             stdscr.addstr(yCord, 0, line)
         yCord = yCord + 1
     pass
예제 #3
0
    def __TuiHelp(self, stdscr):
        h = uiHelp()
        h.Start()

        ch = CursesHelper()
        curses.halfdelay(10)
        ch.stdscr = stdscr
        ch.SetCharacterBlockingMode(True)
        ch.WindowClear()
        ch.WindowRefresh()
        ch.key = 0
        return ch
예제 #4
0
    def __RenderWindow(self, stdscr):
        ch = CursesHelper()
        ch.stdscr = stdscr

        ch.WindowClear()
        ch.WindowRefresh()

        curses.start_color()
        curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
        while ch.key != curses.KEY_F12:
            ch.WindowClear()
            ch.CursorMove()

            self.__InsertHeader(stdscr)
            self.__InsertColHeader(stdscr, ch.width)
            self.__InsertLines(stdscr, ch.height, ch.width)
            self.__InsertFooter(stdscr, ch)

            ch.WindowRefresh()
            ch.GetCharacter()

        ch.WindowClose()
예제 #5
0
    def __TuiHelp(self, stdscr):
        h = uiHelp()
        h.Start()

        ch = CursesHelper()
        ch.stdscr = stdscr
        ch.WindowClear()
        ch.WindowRefresh()
        ch.key = 0
        return ch
예제 #6
0
    def __TuiLogs(self, stdscr):
        l = uiLogs()
        l.logs = self.logs
        l.Start()

        # Once we come back here, update ch with the current stdscr
        # Helps to make the window accept input again
        ch = CursesHelper()
        curses.halfdelay(10)
        ch.stdscr = stdscr
        ch.SetCharacterBlockingMode(True)
        ch.WindowClear()
        ch.WindowRefresh()
        ch.key = 0
        return ch
예제 #7
0
    def __TuiLogs(self, stdscr):
        l = uiLogs()
        l.logs = self.logs
        l.Start()

        # Once we come back here, update ch with the current stdscr
        # Helps to make the window accept input again
        ch = CursesHelper()
        ch.stdscr = stdscr
        ch.WindowClear()
        ch.WindowRefresh()
        ch.key = 0
        return ch
예제 #8
0
    def __InsertColHeader(self, stdscr, width):
        o = CursesHelper()
        col = 4
        #level   = o.AdjustColumn("Level", 6)
        dt = o.AdjustColumn("DateTime", 19)
        name = o.AdjustColumn('Name', 10)
        address = o.AdjustColumn('Address', 16)
        msg = o.AdjustColumn('Message', width - 6 - 10 - 16)

        line = f'{dt} {name}{address}{msg}'
        stdscr.attron(curses.color_pair(3))
        stdscr.addstr(1, 0, line)
        stdscr.attroff(curses.color_pair(3))
        pass
예제 #9
0
    def __InsertLines(self, stdscr, height: int, width: int):
        o = CursesHelper()
        x = 2
        col = 4

        for line in self.logs:
            if x <= height:
                #level   = o.AdjustColumn(line.level, 6)
                name = o.AdjustColumn(line.name, 10)
                address = o.AdjustColumn(line.address, 16)
                msg = o.AdjustColumn(line.message, width - 6 - 10 - 16)
                dt = o.AdjustColumn(str(line.time), 19)
                line = f"{dt} {name}{address}{msg}"

                #stdscr.attron(curses.color_pair(3))
                stdscr.addstr(x, 0, line)
                #stdscr.attroff(curses.color_pair(3))
                x = x + 1
예제 #10
0
    def __RenderWindow(self, stdscr):

        ch = CursesHelper()

        # Make this window not block.
        # Lets the window keep looping but at the same time watches for key strokes
        #stdscr.nodelay(True)

        curses.halfdelay(10)
        ch.stdscr = stdscr

        self.monitor.Start(True)

        self.__GenLogData()

        # clear the scree and refresh
        ch.WindowClear()
        ch.WindowRefresh()

        # Start colors in curses
        curses.start_color()
        curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)

        # Refresh the screen with new data every 5 seconds

        #dtRefresh = datetime.now()

        # Checking to see if the last key that was entered was 'F12'
        while (ch.key != curses.KEY_F12):
            #ch.WindowClear()
            #stdscr.clear()

            # Tells us the screens height and width
            ch.CursorMove()

            if ch.key == curses.KEY_F2:
                self.monitor.Start(force=True)
                ch.WindowClear()
                ch.WindowRefresh()
                ch.key = 0
            elif ch.key == curses.KEY_F10:
                ch = self.__TuiHelp(stdscr)
                ch.WindowRefresh()
            elif ch.key == curses.KEY_F9:
                ch = self.__TuiLogs(stdscr)
                ch.WindowRefresh()
            else:
                # Render title
                self.monitor.Start()
                #ch.WindowRefresh()
                ch.UpdateScreenSize()
                self.__InsertTitle(stdscr)
                self.__InsertColHeader(stdscr, ch)
                self.__InsertLine(stdscr, ch, 2)
                self.__InsertFooter(stdscr, ch)

                #ch.CursorMove()
                # Update the screen
            #ch.WindowRefresh()
            ch.GetCharacter()
            #time.sleep(.1)

        # Close key was pressed
        ch.WindowClose()
예제 #11
0
 def Start(self):
     ch = CursesHelper()
     ch.WindowNew()
     self.__RenderWindow(ch.stdscr)
     #curses.wrapper(self.__RenderWindow)
     pass
예제 #12
0
    def __RenderWindow(self, stdscr):

        ch = CursesHelper()
        ch.stdscr = stdscr

        #th = threading.Thread(target=self.monitor.Start, daemon=True)
        #th.start()

        self.monitor.Start(True)

        self.__GenLogData()

        # clear the scree and refresh
        ch.WindowClear()
        ch.WindowRefresh()

        # Start colors in curses
        curses.start_color()
        curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)

        # Refresh the screen with new data every 5 seconds

        dtRefresh = datetime.now()

        # Checking to see if the last key that was entered was 'F12'
        while (ch.key != curses.KEY_F12):
            ch.WindowClear()
            #stdscr.clear()

            # Tells us the screens height and width
            ch.CursorMove()

            if ch.key == curses.KEY_F2:
                self.monitor.Start(force=True)
                ch.WindowClear()
                ch.WindowRefresh()
                ch.key = 0
            elif ch.key == curses.KEY_F10:
                ch = self.__TuiHelp(stdscr)
            elif ch.key == curses.KEY_F9:
                ch = self.__TuiLogs(stdscr)
            else:
                # Render title
                self.monitor.Start()
                self.__InsertTitle(stdscr)
                self.__InsertColHeader(stdscr, ch)
                self.__InsertLine(stdscr, ch, 2)
                self.__InsertFooter(stdscr, ch)

                ch.CursorMove()
                # Update the screen
                ch.WindowRefresh()

                ch.GetCharacter()
                pass
        # Close key was pressed
        ch.WindowClose()