Ejemplo n.º 1
0
    def _print_item(item):
        def wrap_text(text, width):
            wrapper = TextWrapper(width=width,
                                  break_long_words=False,
                                  break_on_hyphens=False)
            return chain(*[wrapper.wrap(l) for l in text.split("\n")])

        def timeline_rows(item):
            display_name = item['account']['display_name']
            username = "******" + item['account']['username']
            time = item['time'].strftime('%Y-%m-%d %H:%M%Z')

            left_column = [display_name]
            if display_name != username:
                left_column.append(username)
            left_column.append(time)
            if item['reblogged']:
                left_column.append("Reblogged @{}".format(item['reblogged']))

            right_column = wrap_text(item['text'], 80)

            return zip_longest(left_column, right_column, fillvalue="")

        for left, right in timeline_rows(item):
            print_out("{:30} │ {}".format(trunc(left, 30), right))
Ejemplo n.º 2
0
Archivo: app.py Proyecto: anjandev/toot
    def draw_status_row(self,
                        status,
                        index,
                        highlight=False,
                        draw_divider=True):
        offset = 3 * index

        height, width = self.pad.getmaxyx()
        color = Color.GREEN if highlight else Color.WHITE

        trunc_width = width - 15
        acct = trunc("@" + status['account']['acct'],
                     trunc_width).ljust(trunc_width)
        display_name = trunc(status['account']['display_name'],
                             trunc_width).ljust(trunc_width)

        if status['account']['display_name']:
            self.pad.addstr(offset + 1, 14, display_name, color)
            self.pad.addstr(offset + 2, 14, acct, color)
        else:
            self.pad.addstr(offset + 1, 14, acct, color)

        date, time = status['created_at']
        self.pad.addstr(offset + 1, 1, " " + date.ljust(12), color)
        self.pad.addstr(offset + 2, 1, " " + time.ljust(12), color)

        # Redraw box borders to mitigate unicode overflow issues
        self.pad.addch(offset + 1, 0, "│")
        self.pad.addch(offset + 2, 0, "│")
        self.pad.addch(offset + 1, width - 1, "│")
        self.pad.addch(offset + 2, width - 1, "│")

        if draw_divider:
            draw_horizontal_divider(self.pad, offset + 3)

        self.refresh()
Ejemplo n.º 3
0
Archivo: app.py Proyecto: anjandev/toot
 def draw_message(self, text, color):
     text = trunc(text, self.width - 1).ljust(self.width - 1)
     self.window.addstr(1, 0, text, color)
     self.window.refresh()
Ejemplo n.º 4
0
Archivo: app.py Proyecto: anjandev/toot
 def draw_status(self, selected, count):
     text = "Showing toot {} of {}".format(selected + 1, count)
     text = trunc(text, self.width - 1).ljust(self.width - 1)
     self.window.addstr(0, 0, text, Color.WHITE_ON_BLUE | curses.A_BOLD)
     self.window.refresh()