How to use the pikaur.pprint.PrintLock function in pikaur

To help you get started, we’ve selected a few pikaur examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionless / pikaur / pikaur / prompt.py View on Github external
def get_input(prompt: str, answers: Iterable[str] = ()) -> str:
    require_confirm = max(len(choice) > 1 for choice in answers) if answers else False
    with PrintLock():
        if not(
                require_confirm or PikaurConfig().ui.RequireEnterConfirm.get_bool()
        ):
            answer = read_answer_from_tty(prompt, answers=answers)
        else:
            from .pikspect import TTYRestore  # pylint:disable=import-outside-toplevel
            sub_tty = TTYRestore()
            TTYRestore.restore()
            try:
                answer = input(split_last_line(prompt)).lower()
            except EOFError:
                raise SysExit(125)
            finally:
                sub_tty.restore_new()
            if not answer:
                for choice in answers:
github actionless / pikaur / pikaur / pikspect.py View on Github external
def check_questions(self) -> None:
        # pylint: disable=too-many-branches
        try:
            historic_output = b''.join(self.historic_output).decode('utf-8')
        except UnicodeDecodeError:
            return

        clear_buffer = False

        for answer, questions in self.default_questions.items():
            for question in questions:
                if not _match(question, historic_output):
                    continue
                self.write_something((answer + '\n').encode('utf-8'))
                with PrintLock():
                    self.pty_in.write(answer)
                    sleep(SMALL_TIMEOUT)
                    self.pty_in.write('\n')
                    self.pty_in.flush()
                clear_buffer = True
                break

        if clear_buffer:
            self.historic_output = [b'']
github actionless / pikaur / pikaur / pprint.py View on Github external
def _print(destination: TextIO, message='', end='\n', flush=False, lock=True) -> None:
    if lock:
        PrintLock().__enter__()
    destination.write(f'{message}{end}')
    if flush:
        destination.flush()
    if lock:
        PrintLock().__exit__()
github actionless / pikaur / pikaur / pprint.py View on Github external
def _print(destination: TextIO, message='', end='\n', flush=False, lock=True) -> None:
    if lock:
        PrintLock().__enter__()
    destination.write(f'{message}{end}')
    if flush:
        destination.flush()
    if lock:
        PrintLock().__exit__()
github actionless / pikaur / pikaur / pikspect.py View on Github external
def write_something(self, output: bytes) -> None:
        if not self.print_output:
            return
        with PrintLock():
            self._write_buffer += output
            self.write_buffer_contents()