Exemplo n.º 1
0
    def redraw(self, wnd: _curses.window):
        "Refresh debug window"
        lines, cols = wnd.getmaxyx()
        wnd.erase()
        wnd.hline(0, 0, curses.ACS_HLINE, cols)

        self._logs = self._logs[-(lines-1):]
        line = 1
        for log in self._logs:
            wnd.addstr(line, 0, log[:cols-1])
            line += 1

        wnd.refresh()
Exemplo n.º 2
0
def main_page(scr: window):
    curses.curs_set(0)
    scr.noutrefresh()
    callbacks = {}

    def command_callback(command: str, **kwargs: Any):
        if command in callbacks:
            callbacks[command](**kwargs)

    setup_colours()
    max_rows, max_cols = scr.getmaxyx()
    views: dict[str, AbstractView] = {
        'header': HeaderView(max_cols),
        'footer': FooterView(max_rows, max_cols),
        'a2z': A2ZView(max_rows, command_callback),
        'tabs': TabView(max_cols, command_callback),
        'content': ContentView(max_rows, max_cols, command_callback)
    }
    keypress_table: dict[str, Callable[[int], None]] = {name: view.process_keystroke for name, view in views.items()}
    focus: list[str] = ['a2z']
    dispatch_to: list[Callable[[int], None]] = [keypress_table[focus[0]]]

    full_render_current_state(scr, views, focus[0])
    curses.doupdate()

    callbacks = setup_callbacks(views, focus, dispatch_to)
    command_callback('LOAD_PAGE', page='HOMEPAGE')

    keep_going = True
    while keep_going:
        update_render_current_state(scr, views)
        curses.doupdate()

        key: int = scr.getch()
        if key == ord('q'):
            keep_going = False
        elif key == ord('\t'):
            focus[0] = next_focus(focus[0])
            update_focuses(views, focus[0])
            dispatch_to[0] = keypress_table[focus[0]]
        elif key == curses.KEY_RESIZE:
            curses.resizeterm(*scr.getmaxyx())
            scr.erase()
            scr.noutrefresh()
            resize_all(focus[0], views, scr)
        else:
            dispatch_to[0](key)
Exemplo n.º 3
0
    def redraw(self, wnd: _curses.window):
        "Refresh the view display"
        lines, cols = wnd.getmaxyx()
        wnd.erase()

        line = 0
        wnd.addstr(line, 0, f"View screen ({self.ticks} ticks):")
        line += 1
        for i in range(0, curses.COLORS):
            wnd.addstr(line, i % cols, str(i % 10), curses.color_pair(i))
            if (i+1) % cols == 0:
                line += 1

        line += 1
        for i, message in enumerate(self.messages):
            wnd.addstr(i + line, 0, "Msg: " + message)
        wnd.refresh()
Exemplo n.º 4
0
    def redraw(self, wnd: _curses.window):
        "Refresh the view display"
        lines, cols = wnd.getmaxyx()
        wnd.erase()
        msg = "Incremental search: " + self.query
        wnd.addstr(0, 0, msg)
        cursor_position = len(msg)

        self._update_search_state()

        msg = "{}/{}".format(len(self.results), len(self.all_issues))
        wnd.addstr(0, cols - len(msg), msg)

        if self.selected_idx >= len(self.results):
            self.selected_idx = max(0, len(self.results) - 1)

        line = 1
        max_summary = cols - 10 - 5
        for i, result in enumerate(self.results):
            if i == self.selected_idx:
                th_key = self.app.theme.ISSUE_KEY_SELECTED
                th_summary = self.app.theme.ISSUE_SUMMARY_SELECTED
            else:
                th_key = self.app.theme.ISSUE_KEY
                th_summary = self.app.theme.ISSUE_SUMMARY

            # TODO: Unified table generator
            j = result['fields']
            summary = j["summary"]
            if len(summary) > max_summary:
                summary = summary[:max_summary] + "…"
            summary += " " * (cols - len(summary) - 16)
            msg = f"{result['key']:10s} {summary}"
            wnd.addstr(line, 0, "{:15}".format(result['key']), th_key)
            wnd.addstr(line, 15, summary[:cols - 15 - 1], th_summary)
            line += 1
            if line == lines:
                break

        wnd.move(0, cursor_position)
Exemplo n.º 5
0
    def redraw(self, wnd: _curses.window):
        "Refresh status and keybindings display"
        # Update size on resize events
        self.lines_max, self.cols_max = wnd.getmaxyx()
        wnd.erase()
        wnd.hline(0, 0, curses.ACS_HLINE, self.cols_max)

        state = self.app.bindings.get_current()
        if state.render_callback is not None:
            state.render_callback()
        cmds = state.commands[:]

        col = self.margin_left

        while cmds:
            cmds, max_width = self._draw_column(wnd, col, cmds, state.disabled)
            col += max_width + self.margin_column

        hints = self.app.bindings.get_current().hints[:]
        while hints:
            hints, max_width = self._draw_hints(wnd, col, hints)
            col += max_width + self.margin_column

        wnd.refresh()
Exemplo n.º 6
0
 def redraw(self, wnd: _curses.window):
     "Refresh the view display"
     wnd.erase()
     wnd.addstr(0, 0, "Secondary view.")