Exemple #1
0
def draw(stdscr, table_pad, output_pad, offset, table):
    top_offset, left_offset = offset

    mi, mj = stdscr.getmaxyx()
    # Clear all pads and windows
    stdscr.clear()
    table_pad.clear()
    output_pad.clear()

    # Draw table
    top_offset, left_offset = table.draw(stdscr,
                                         table_pad, top_offset, left_offset)

    stdscr.move(mi / 2 + 1, 0)

    # Draw instructions
    printstr(stdscr, "[q] abort / [arrows] move / [space] (un)select cell / [d] clear selection / [c] select column", curses.color_pair(3))
    printstr(stdscr, "[enter] print and copyselected cells(protip: use `pbpaste | ...` to pipe forward)", curses.color_pair(3))
    printstr(stdscr)

    # Output preview
    if table.selection:
        printstr(stdscr, "[{}] cells selected".format(len(table.selection)), curses.color_pair(3))
        output_pad.move(0, 0)
        for content in table.selection_content:
            i, j = output_pad.getyx()
            writestr(output_pad, " |=> ", curses.color_pair(1))
            printstr(output_pad, content, curses.color_pair(1))
            output_pad.move(i + 1, j)

    # Refresh
    stdscr.refresh()
    table_pad.refresh(top_offset, table.get_column_offset(left_offset), 0, 0, mi / 2 - 1, mj - 1)
    output_pad.refresh(0, 0, mi / 2 + 6, 0, mi - 1, mj - 1)
    return (top_offset, left_offset)
 def draw_preview(self, pad):
     if self._table.selection:
         pad.move(0, 0)
         printstr(pad, "[{}] cells selected".format(len(self._table.selection)), curses.color_pair(7))
         for content in self._table.selection_content:
             i, j = pad.getyx()
             writestr(pad, " |=> ", curses.color_pair(1))
             printstr(pad, content, curses.color_pair(1))
             pad.move(i + 1, j)
 def draw_preview(self, pad):
     # TODO: Create custom method draw_subtable in Table class instead of having to create a new object here
     if self._table.selection:
         pad.move(0, 0)
         output = self._structured_output()
         output_table = Table(output)
         printstr(pad, "Table {}x{} with {} filled cells".format(output_table.height, output_table.ncolumns,
                                                                 len(self._table.selection)),
                  curses.color_pair(7))
         output_table.draw(pad, lambda p, content: 0, margin=(1, 0))
Exemple #4
0
 def draw_preview(self, pad):
     # TODO: Create custom method draw_subtable in Table class instead of having to create a new object here
     if self._table.selection:
         pad.move(0, 0)
         output = self._structured_output()
         output_table = Table(output)
         printstr(
             pad, "Table {}x{} with {} filled cells".format(
                 output_table.height, output_table.ncolumns,
                 len(self._table.selection)), curses.color_pair(7))
         output_table.draw(pad, lambda p, content: 0, margin=(1, 0))
Exemple #5
0
 def draw_preview(self, pad):
     if self._table.selection:
         pad.move(0, 0)
         printstr(pad,
                  "[{}] cells selected".format(len(self._table.selection)),
                  curses.color_pair(7))
         for content in self._table.selection_content:
             i, j = pad.getyx()
             writestr(pad, " |=> ", curses.color_pair(1))
             printstr(pad, content, curses.color_pair(1))
             pad.move(i + 1, j)
Exemple #6
0
def draw(stdscr, table_pad, output_pad, offset, table):
    top_offset, left_offset = offset

    mi, mj = stdscr.getmaxyx()
    # Clear all pads and windows
    stdscr.clear()
    table_pad.clear()
    output_pad.clear()

    # Draw table
    top_offset, left_offset = table.draw(stdscr, table_pad, top_offset,
                                         left_offset)

    stdscr.move(mi / 2 + 1, 0)

    # Draw instructions
    printstr(
        stdscr,
        "[q] abort / [arrows] move / [space] (un)select cell / [d] clear selection / [c] select column",
        curses.color_pair(3))
    printstr(
        stdscr,
        "[enter] print and copyselected cells(protip: use `pbpaste | ...` to pipe forward)",
        curses.color_pair(3))
    printstr(stdscr)

    # Output preview
    if table.selection:
        printstr(stdscr, "[{}] cells selected".format(len(table.selection)),
                 curses.color_pair(3))
        output_pad.move(0, 0)
        for content in table.selection_content:
            i, j = output_pad.getyx()
            writestr(output_pad, " |=> ", curses.color_pair(1))
            printstr(output_pad, content, curses.color_pair(1))
            output_pad.move(i + 1, j)

    # Refresh
    stdscr.refresh()
    table_pad.refresh(top_offset, table.get_column_offset(left_offset), 0, 0,
                      mi / 2 - 1, mj - 1)
    output_pad.refresh(0, 0, mi / 2 + 6, 0, mi - 1, mj - 1)
    return (top_offset, left_offset)
Exemple #7
0
    def draw(self, resizing, redraw_output):

        # Compute table_pad dimensions
        top_margin, left_margin = self.MARGIN
        mi, mj = self.screen.getmaxyx()
        table_pad_height = mi / 2 - top_margin
        table_pad_width = mj - left_margin

        # Clear all pads and windows
        self.screen.clear()
        self._selector.clear(self.table_pad)
        if redraw_output:
            self.output_pad.clear()

        # Draw table
        self._selector.draw(self.table_pad)

        # Scroll up/down
        top_offset, left_offset = self.table_offset
        i, j = self._selector.position
        if i > top_offset + table_pad_height - 1:
            top_offset += 1
        elif i < top_offset:
            top_offset -= 1

        # Scroll left/right
        # There's no guarantee that shifting the table one column to the right will make the entire column of the
        # current position visible bc unlike rows columns can have variable width. So, we shift until the column is
        # fully visible.
        shift_left = lambda left: self._table.column_offset(j + 1) > self._table.column_offset(left) + table_pad_width - 1
        if shift_left(left_offset):
            while shift_left(left_offset):
                left_offset += 1
        elif resizing:
            while left_offset >= 1 and self._table.column_offset(j + 1) - self._table.column_offset(left_offset - 1) < table_pad_width:
                left_offset -= 1
        if j < left_offset:
            left_offset -= 1

        # Set h/v scroll
        self.table_offset = (top_offset, left_offset)

        # Draw instructions
        self.screen.move(top_margin + table_pad_height + 1, left_margin)
        h1, _ = self.screen.getyx()
        self._selector.draw_instructions(self.screen)
        printstr(self.screen, self._output_processor.name, curses.color_pair(7))
        next_output_processor = self._output_processors[self._next_output_processor_index()]
        printstr(self.screen, "     [o] {} mode".format(next_output_processor.name), curses.color_pair(3))
        printstr(self.screen)
        h2, _ = self.screen.getyx()
        instructions_h = h2 - h1

        # Output preview
        self._output_processor.draw_preview(self.output_pad)

        # Refresh
        self.screen.noutrefresh()
        self.table_pad.noutrefresh(top_offset, self._table.column_offset(left_offset), top_margin, left_margin,
                                   top_margin + table_pad_height - 1, left_margin + table_pad_width - 1)
        self.output_pad.noutrefresh(0, 0, top_margin + table_pad_height + instructions_h + 1, left_margin, mi - 1, mj - 1)
        curses.doupdate()
Exemple #8
0
    def draw(self, resizing, redraw_output):

        # Compute table_pad dimensions
        top_margin, left_margin = self.MARGIN
        mi, mj = self.screen.getmaxyx()
        table_pad_height = mi / 2 - top_margin
        table_pad_width = mj - left_margin

        # Clear all pads and windows
        self.screen.clear()
        self._selector.clear(self.table_pad)
        if redraw_output:
            self.output_pad.clear()

        # Draw table
        self._selector.draw(self.table_pad)

        # Scroll up/down
        top_offset, left_offset = self.table_offset
        i, j = self._selector.position
        if i > top_offset + table_pad_height - 1:
            top_offset += 1
        elif i < top_offset:
            top_offset -= 1

        # Scroll left/right
        # There's no guarantee that shifting the table one column to the right will make the entire column of the
        # current position visible bc unlike rows columns can have variable width. So, we shift until the column is
        # fully visible.
        shift_left = lambda left: self._table.column_offset(j + 1) > self._table.column_offset(left) + table_pad_width - 1
        if shift_left(left_offset):
            while shift_left(left_offset):
                left_offset += 1
        elif resizing:
            while left_offset >= 1 and self._table.column_offset(j + 1) - self._table.column_offset(left_offset - 1) < table_pad_width:
                left_offset -= 1
        if j < left_offset:
            left_offset -= 1

        # Set h/v scroll
        self.table_offset = (top_offset, left_offset)

        # Draw instructions
        self.screen.move(top_margin + table_pad_height + 1, left_margin)
        h1, _ = self.screen.getyx()
        self._selector.draw_instructions(self.screen)
        printstr(self.screen, self._output_processor.name, curses.color_pair(7))
        next_output_processor = self._output_processors[self._next_output_processor_index()]
        printstr(self.screen, "     [o] {} mode".format(next_output_processor.name), curses.color_pair(3))
        printstr(self.screen)
        h2, _ = self.screen.getyx()
        instructions_h = h2 - h1

        # Output preview
        self._output_processor.draw_preview(self.output_pad)

        # Refresh
        self.screen.noutrefresh()
        self.table_pad.noutrefresh(top_offset, self._table.column_offset(left_offset), top_margin, left_margin,
                                   top_margin + table_pad_height - 1, left_margin + table_pad_width - 1)
        self.output_pad.noutrefresh(0, 0, top_margin + table_pad_height + instructions_h + 1, left_margin, mi - 1, mj - 1)
        curses.doupdate()
 def draw_instructions(self, pad):
     # TODO: Remove hard-coded dependency on next selector, see View class for details
     printstr(pad, "Multi-selection", curses.color_pair(7))
     printstr(pad, "     [i] single-selection                                                     ", curses.color_pair(3))
     printstr(pad, "[arrows] move                               [d] start/end subtable deselection", curses.color_pair(3))
     printstr(pad, " [space] start/end subtable selection   [enter] print and copy                ", curses.color_pair(3))
     printstr(pad, "     [p] print current                      [q] abort                         ", curses.color_pair(3))
     printstr(pad)
    def draw_instructions(self, pad):
        # TODO: Remove hard-coded dependency on next selector, see View class for details
        printstr(pad, "Single-selection", curses.color_pair(7))
        printstr(pad, "     [i] multi-selection                                               ", curses.color_pair(3))
        printstr(pad, "[arrows] move              [c] select column         [p] print current ", curses.color_pair(3))
        printstr(pad, " [space] (un)select cell   [d] clear selection   [enter] print and copy", curses.color_pair(3))
        printstr(pad, "                                                     [q] abort         ", curses.color_pair(3))

        printstr(pad)
Exemple #11
0
    def draw_instructions(self, pad):
        # TODO: Remove hard-coded dependency on next selector, see View class for details
        printstr(pad, "Single-selection", curses.color_pair(7))
        printstr(
            pad,
            "     [i] multi-selection                                               ",
            curses.color_pair(3))
        printstr(
            pad,
            "[arrows] move              [c] select column         [p] print current ",
            curses.color_pair(3))
        printstr(
            pad,
            " [space] (un)select cell   [d] clear selection   [enter] print and copy",
            curses.color_pair(3))
        printstr(
            pad,
            "                                                     [q] abort         ",
            curses.color_pair(3))

        printstr(pad)
Exemple #12
0
 def draw_instructions(self, pad):
     # TODO: Remove hard-coded dependency on next selector, see View class for details
     printstr(pad, "Multi-selection", curses.color_pair(7))
     printstr(
         pad,
         "     [i] single-selection                                                     ",
         curses.color_pair(3))
     printstr(
         pad,
         "[arrows] move                               [d] start/end subtable deselection",
         curses.color_pair(3))
     printstr(
         pad,
         " [space] start/end subtable selection   [enter] print and copy                ",
         curses.color_pair(3))
     printstr(
         pad,
         "     [p] print current                      [q] abort                         ",
         curses.color_pair(3))
     printstr(pad)