Example #1
0
    def curses(self, stdscr):
        curses.curs_set(False)
        curses.start_color()
        curses.use_default_colors()
        stdscr.keypad(True)
        stdscr.refresh()

        if curses.COLORS < 256 or curses.COLOR_PAIRS < 256:
            raise NotImplementedError("curses output requires 256-color terms")

        for i in range(256):
            curses.init_pair(i, -1, i)

        pad = curses.newpad(self.rows+1, self.cols+1)
        for rn in range(self.rows):
            for cn in range(self.cols):
                pad.addch(rn, cn, ' ', curses.color_pair(self.map[rn][cn]))

        trow, tcol = get_terminal_size()
        cy = cx = 0

        while True:
            pad.refresh(cy, cx, 0, 0, trow-1, tcol-1)
            ch = stdscr.getch()

            if ch in [27, ord('q')]:
                break
            elif ch in [curses.KEY_UP, ord('k')]:
                cy = max(cy-1, 0)
            elif ch in [curses.KEY_DOWN, ord('j')]:
                cy = min(cy+1, self.rows)
            elif ch in [curses.KEY_LEFT, ord('h')]:
                cx = max(cx-1, 0)
            elif ch in [curses.KEY_RIGHT, ord('l')]:
                cx = min(cx+1, self.cols)
Example #2
0
            ch = stdscr.getch()

            if ch in [27, ord('q')]:
                break
            elif ch in [curses.KEY_UP, ord('k')]:
                cy = max(cy-1, 0)
            elif ch in [curses.KEY_DOWN, ord('j')]:
                cy = min(cy+1, self.rows)
            elif ch in [curses.KEY_LEFT, ord('h')]:
                cx = max(cx-1, 0)
            elif ch in [curses.KEY_RIGHT, ord('l')]:
                cx = min(cx+1, self.cols)


if __name__ == "__main__":
    termsize = get_terminal_size()

    parser = argparse.ArgumentParser()
    parser.add_argument("file", type=TerminalImage,
                        help="path to the image file")
    parser.add_argument("-c", "--col", type=int, default=termsize[1],
                        help="number of cols",)
    parser.add_argument("-r", "--row", type=int, default=termsize[0],
                        help="number of rows")
    parser.add_argument("-f", "--fast", action="store_true",
                        help="use a faster color-mapping algorithm")
    parser.add_argument("-m", "--map",
                        help="color map (quite fast for big image)")
    parser.add_argument("-p", "--parallel", action="store_true",
                        help="use multi-process")
    parser.add_argument("-u", "--curses", action="store_true",