Example #1
0
    def _append_metadata_lines(self,
                               window,
                               string,
                               output_lines,
                               attr=-1,
                               add_blank=False) -> None:
        """Appends properly formatted lines to the 2D output_lines array.

        Args:
            window: the curses window which will display the metadata
            string: the string to add to output_lines
            output_lines: 2D array, each element is [attr, str]
            attr: (optional) the attribute (i.e. curses.A_BOLD)
        """
        max_lines = int(0.7 * window.getmaxyx()[0])
        max_line_width = window.getmaxyx()[1] - 1
        lines = cjkwrap.wrap(string, max_line_width)

        # truncate to at most 70% of the total lines on the screen
        lines = lines[:max_lines]

        # add all lines to array
        for line in lines:
            output_lines.append([attr, line])

        # add a blank line afterward, if necessary
        if add_blank:
            output_lines.append([-1, ""])
Example #2
0
    def _draw_metadata(self, window) -> None:
        """Draws the metadata of the selected feed/episode onto the window.

        Exactly one of feed or episode must be specified.

        Args:
            window: the curses window which will display the metadata
        """
        assert window is not None

        output_lines = []

        max_lines = int(0.7 * window.getmaxyx()[0])
        max_line_width = window.getmaxyx()[1] - 1

        # clear the window by drawing blank lines
        for y in range(2, window.getmaxyx()[0]):
            window.addstr(y, 0, " " * max_line_width)

        metadata = self._get_active_menu().metadata()
        temp_lines = metadata.split('\n')

        lines = []
        for line in temp_lines:
            parts = cjkwrap.wrap(line,
                                 window.getmaxyx()[1] - 1,
                                 replace_whitespace=True)
            if len(parts) == 0:
                lines.append('')
            else:
                for part in parts:
                    lines.append(part.strip())

        # truncate to at most 70% of the total lines on the screen
        lines = lines[:max_lines]

        y = 2
        for line in lines[:max_lines]:
            if line.startswith('\cb'):
                window.attron(curses.A_BOLD)
                line = line[3:]
            else:
                window.attrset(curses.color_pair(1))

            window.addstr(y, 0, line)
            y += 1
Example #3
0
def split_text(text, width, height, unicode_aware=True):
    if not unicode_aware:
        return _split_text(text, width, height, unicode_aware)
    result = []
    for i in text.split("\n"):
        if not i:
            result.append(i)
        else:
            result += cjkwrap.wrap(i, width)

    # Check for a height overrun and truncate.
    if len(result) > height:
        result = result[:height]
        result[height - 1] = result[height - 1][:width - 3] + "..."

    # Very small columns could be shorter than individual words - truncate
    # each line if necessary.
    for i, line in enumerate(result):
        if len(line) > width:
            result[i] = line[:width - 3] + "..."
    return result
Example #4
0
    def _draw_metadata(self, window) -> None:
        """Draws the metadata of the selected feed/episode onto the window.

        Args:
            window: the curses window which will display the metadata
        """
        assert window is not None

        max_lines = window.getmaxyx()[0] - 4
        max_line_width = window.getmaxyx()[1] - 1

        # clear the window by drawing blank lines
        for y in range(2, window.getmaxyx()[0] - 2):
            window.addstr(y, 0, " " * max_line_width)

        metadata = self._get_active_menu().metadata
        temp_lines = metadata.split('\n')

        lines = []
        for line in temp_lines:
            parts = cjkwrap.wrap(line,
                                 window.getmaxyx()[1] - 1,
                                 replace_whitespace=True)
            if len(parts) == 0:
                lines.append('')
            else:
                for part in parts:
                    lines.append(part.strip())

        y = 2
        for line in lines[:max_lines]:
            attr = curses.color_pair(1)
            if line.startswith('!cb'):
                attr |= curses.A_BOLD
                line = line[3:]

            window.addstr(y, 0, line, attr)
            y += 1
Example #5
0
 def textwrapper(txt, width):
     return cjkwrap.wrap(txt, width)
def print_wrapped(text):
    paras = text.split("\n")
    for i in paras:
        print(*cjkwrap.wrap(i), sep="\n")
Example #7
0
def wrap_fix(s, n):
    return '\n'.join(cjkwrap.wrap(s, n, replace_whitespace=False)).split('\n')