Ejemplo n.º 1
0
def print_meta(video: MappedVideo, stream: TextIO = sys.stdout) -> None:
    with StdOutOverride(stream):

        def print_separator(text: Optional[str] = None,
                            fat: bool = False) -> None:
            columns = shutil.get_terminal_size().columns
            sep = "━" if fat else "─"
            if not text:
                print(sep * columns)
            else:
                sep_len = (columns - len(text) - 2)
                padding = sep_len // 2
                printt(sep * padding)
                printt(" ", text, " ", bold=fat)
                printtln(sep * (padding + (sep_len % 2)))

        print_separator("Playing now", fat=True)
        printt(_("         Title: "))
        printtln(video.title, bold=True)
        printt(_("In playlist(s): "))
        printtln(", ".join(v.name for v in video.playlists), bold=True)

        description = video.description
        if description is not None:
            columns = shutil.get_terminal_size().columns
            lines = description.splitlines()
            print_separator(_("Video description"))

            for line in lines:
                print(wrap.fill(line, width=columns))

        print_separator(fat=True)
        print()
Ejemplo n.º 2
0
 def print_prompt():
     prompt_format = "{prompt_text} > "
     prompt = prompt_format.format(prompt_text=self.get_prompt_text())
     printt(prompt,
            foreground=self.get_prompt_color(),
            bold=True,
            replace=True)
Ejemplo n.º 3
0
 def print_separator(text: Optional[str] = None,
                     fat: bool = False) -> None:
     columns = shutil.get_terminal_size().columns
     sep = "━" if fat else "─"
     if not text:
         print(sep * columns)
     else:
         sep_len = (columns - len(text) - 2)
         padding = sep_len // 2
         printt(sep * padding)
         printt(" ", text, " ", bold=fat)
         printtln(sep * (padding + (sep_len % 2)))
Ejemplo n.º 4
0
    def print_row(columns: List[str], widths: List[int],
                  bold: bool = False, background: Optional[int] = None) -> None:

        if len(widths) != len(columns) and not columns:
            raise ValueError("For every column, a width must be specified, "
                             "and columns must not be empty")

        for column, width in zip(columns[:-1], widths[:-1]):
            TablePrinter.print_col(column, width, background, bold)
            printt("│", background=background, bold=False)

        TablePrinter.print_col(columns[-1], widths[-1], background, bold)
        print()
Ejemplo n.º 5
0
    def command_line(self, tags: List[str]) -> Tuple[str, bool]:
        def print_prompt():
            prompt_format = "{prompt_text} > "
            prompt = prompt_format.format(prompt_text=self.get_prompt_text())
            printt(prompt,
                   foreground=self.get_prompt_color(),
                   bold=True,
                   replace=True)

        print()
        print(_("Type a valid TAG. <F1> for help."))
        print_prompt()

        tag = ""
        hook_triggered = False
        while tag not in tags:
            char: Optional[str] = terminal.getkey()

            if char in self.hooks:
                hook_triggered = True
                if self.hooks[char]():
                    break

                char = None

            if char in {"\x04", "\x03"}:  # Ctrl+d, Ctrl+d
                hook_triggered = False
                break

            if char in {"\r", ""} and tags:
                tag = tags[0]
                break

            if char == FKeys.DEL:
                tag = tag[:-1]
            elif char and char in config.tui.alphabet:
                tag += char

            print_prompt()
            printt(tag)

        print()
        return tag, hook_triggered
Ejemplo n.º 6
0
 def print_col(text: str, width: int, background: Optional[int], bold: bool):
     padding = " " * max(0, (width - wcswidth(text)))
     padded = text + padding
     printt(" " + padded + " ", background=background, bold=bold)