Example #1
0
    def start(self) -> (int, int):
        """Main loop"""
        self.maybe_move_down()

        self.spaces = self.start_spaces
        self.valid = True

        with TERM.cbreak():
            while True:
                if self.is_input_valid():
                    self.hide_show_print()

                ans = TERM.inkey()
                utils.quit_on_q(ans)

                if ans.name == 'KEY_ENTER' and self.image:
                    self.maybe_erase()
                    lscat.api.hide(self.image)
                    if self.static:
                        lscat.api.hide(self.static)
                    return self.return_tup()

                if ans in PLUS:
                    self.spaces += 1
                    self.valid = True

                elif ans in MINUS and self.spaces > self.start_spaces:
                    self.spaces -= 1
                    self.valid = True

                else:
                    self.valid = False
Example #2
0
def _pick_dir_loop(path: 'Path', basetitle: str, actions,
                   modes: 'list[str]') -> 'Path':
    title = basetitle

    while True:
        picker = _pick_dirs_picker(actions, title)
        _, ans = picker.start()
        utils.quit_on_q(ans)

        if ans == 'y' and files.path_valid(path):
            return path

        elif ans == 'b':
            path = handle_back(path)

        elif ans == 'd':
            path = handle_delete(path)

        elif ans == 'f':
            title, actions, modes = handle_filter(path, basetitle)
            continue

        elif ans == 'c':
            handle_clear()

        elif isinstance(ans, int):
            path, modes = handle_cd(path, actions[ans], modes)

        actions = actions_from_dir(path, modes)
Example #3
0
def scroll_prompt(tracker, data, max_images):
    show = True
    terminal_page = 0
    images = []

    if tracker is lscat.TrackDownloadsUsers:
        max_scrolls = utils.max_terminal_scrolls(data, False)
    else:
        max_scrolls = utils.max_terminal_scrolls(data, True)

    with TERM.cbreak():
        while True:
            if show:
                lscat.api.hide_all(images)
                myslice = utils.slice_images(max_images, terminal_page)
                images = lscat.handle_scroll(tracker, data, myslice)

            ans = TERM.inkey()
            utils.quit_on_q(ans)

            if ans.name == 'KEY_DOWN' and terminal_page + 1 < max_scrolls:
                terminal_page += 1
                show = True

            elif ans.name == 'KEY_UP' and terminal_page > 0:
                terminal_page -= 1
                show = True

            else:
                print('Out of bounds!')
                show = False
Example #4
0
def center_spaces_assistant():
    """=== Ueberzug center image ===
    Use +/= to move the image right, and -/_ to move it left
    Adjust the position to the center of your terminal

    Use q to exit the program, and press enter to confirm the current position
    """
    if not config.api.use_ueberzug():
        print('Center images assistant is only for ueberzug!')
        return -1

    # Setup
    image = WELCOME_IMAGE.parent / '79494300_p0.png'
    valid = True
    spacing = 0
    i = 0

    # Start
    printer.print_doc(center_spaces_assistant.__doc__)
    print('\n' * (TERM.height - 9), f'Current position: {spacing:01}')

    with TERM.cbreak():
        while True:
            if valid:
                printer.move_cursor_up(1)
                print(f'Current position: {spacing:02}')
                placement = lscat.api.show(image, spacing, 0, 500)

            ans = TERM.inkey()
            utils.quit_on_q(ans)

            if ans in PLUS:
                spacing += 1
                valid = True

            elif ans in MINUS and spacing > 0:
                spacing -= 1
                valid = True

            elif ans.name == 'KEY_ENTER':
                os.system('clear')
                lscat.api.hide(placement)
                return spacing

            else:
                valid = False

            if valid:
                lscat.api.hide(placement)
                i += 1
Example #5
0
def gallery_print_spacing_assistant(size, xpadding, image_width,
                                    image_height: int) -> 'list[int]':
    """=== Gallery print spacing ===
    Use +/= to increase the spacing, and -/_ to decrease it
    Use q to exit the program, and press enter to go to the next assistant
    Use left and right arrow keys to change the current space selection

    Do you want to preview an existing cache dir? [y/N]
    To keep your chosen thumbnail size, image width and x spacing, enter 'n'.
    """
    printer.print_doc(
        gallery_print_spacing_assistant.__doc__)  # Action before start
    ans = input()

    # Setup variables
    ncols, images = _display_inital_row(ans, size, xpadding, image_width,
                                        image_height)

    # Just the default settings; len(first_list) == 5
    spacings = [9, 17, 17, 17, 17] + [17] * (ncols - 5)
    current_selection = 0

    # Start
    print('\n')
    with TERM.cbreak():
        while True:
            printer.update_gallery_info(spacings, ncols, current_selection)

            ans = TERM.inkey()
            utils.quit_on_q(ans)

            if ans in PLUS and pure.line_width(spacings, ncols) < TERM.width:
                spacings[current_selection] += 1

            elif ans in MINUS and spacings[current_selection] > 0:
                spacings[current_selection] -= 1

            # right arrow
            elif (ans.name == 'KEY_RIGHT' or ans in {'d', 'l'}
                  and current_selection < len(spacings) - 1):
                current_selection += 1

            # left arrow
            elif ans.name == 'KEY_LEFT' or ans in {'a', 'h'
                                                   } and current_selection > 0:
                current_selection -= 1

            elif ans.name == 'KEY_ENTER':
                lscat.api.hide_all(images)
                return spacings
Example #6
0
    def start(self) -> 'IO':
        show_images = True
        self.terminal_page = 0

        with TERM.cbreak():
            while True:
                if show_images:
                    self.show_func()
                    self.maybe_show_preview()
                    self.report()

                ans = TERM.inkey()
                print(ans)
                utils.quit_on_q(ans)

                if ans == 'n' and self.current_page == self.max_pages:
                    print('This is the last cached page!')
                    show_images = False

                elif ans == 'p' and self.current_page == self.condition:
                    print('This is the last page!')
                    show_images = False

                elif ans == 'n':
                    os.system('clear')
                    self.current_page += 1
                    show_images = True

                elif ans == 'p':
                    os.system('clear')
                    self.current_page -= 1
                    show_images = True

                elif (ans.name == 'KEY_DOWN' and self.scrollable
                      and self.terminal_page + 1 < self.max_scrolls):
                    self.terminal_page += 1
                    show_images = True

                elif (ans.name == 'KEY_UP' and self.scrollable
                      and self.terminal_page > 0):
                    self.terminal_page -= 1
                    show_images = True

                else:
                    print('Invalid input!')
                    show_images = False

                if show_images:
                    self.end_func()
Example #7
0
def thumbnail_size_assistant() -> 'IO[int]':
    """=== Thumbnail size ===
    This will display an image whose thumbnail size can be varied
    Use +/= to increase the size, and -/_ to decrease it
    Use q to exit the program, and press enter to confirm the size

    Keep in mind this size will be used for a grid of images
    """
    # Setup
    images = []
    size = 300
    previous_size = 300

    # Start
    printer.print_doc(thumbnail_size_assistant.__doc__)

    with TERM.cbreak():
        while True:
            images.append(lscat.api.show(WELCOME_IMAGE, 0, 0, size))
            with TERM.location(0, (TERM.height - 10)):
                print(f'size = {size}')

            ans = TERM.inkey()
            utils.quit_on_q(ans)

            if ans in PLUS:
                previous_size = size
                size += 20

            # +, +, +, -, +
            # |     |  ^  |> Do nothing here as well
            # |     |  |
            # |     |  |
            # |     |  This is where all images should be hidden
            # |     |
            # No images hidden in this range
            elif ans in MINUS:
                previous_size = size
                size -= 20
                if previous_size > size:
                    lscat.api.hide_all(images)

            elif ans.name == 'KEY_ENTER':
                lscat.api.hide_all(images)
                return size
Example #8
0
def user_info_assistant(thumbnail_size, xpadding, image_width: int) -> int:
    """=== User print name xcoord ===
    Use +/= to move the text right, and -/_ to move it left
    Adjust the position as you see fit

    Use q to exit the program, and press enter to confirm the current position
    """
    # Setup variables
    spacing, _ = config.api.gen_users_settings()  # Default
    preview_xcoords = pure.xcoords(TERM.width, image_width, xpadding, 1)[-3:]

    # Start
    printer.print_doc(user_info_assistant.__doc__)

    images = lscat.api.show_user_row(WELCOME_IMAGE, preview_xcoords, xpadding,
                                     thumbnail_size)

    if not config.api.use_ueberzug():
        printer.move_cursor_up(5)
    else:
        printer.move_cursor_down(3)

    with TERM.cbreak():
        while True:
            printer.update_user_info(spacing)

            ans = TERM.inkey()
            utils.quit_on_q(ans)

            if ans in PLUS:
                spacing += 1

            elif ans in MINUS and spacing > 0:
                spacing -= 1

            elif ans.name == 'KEY_ENTER':
                print('\n' * 3)
                lscat.api.hide_all(images)
                return spacing
Example #9
0
def test_quit_on_q_no_quit(monkeypatch):
    assert utils.quit_on_q('not_q') is None
Example #10
0
def test_quit_on_q_quit(monkeypatch):
    monkeypatch.setattr('koneko.utils.sys.exit', raises_customexit)
    with pytest.raises(CustomExit):
        utils.quit_on_q('q')