Example #1
0
    def _print_tweet(self, tweet, line_number):
        """
        Print formatted tweet
        """
        formatted = self._format_tweet(tweet)
        used_lines = compute_used_lines(self._window, formatted)

        self._window.addstr(line_number, 0, formatted)

        return int(used_lines)
Example #2
0
 def refresh(self):
     self._window.clear()
     start_line = 0
     for message in self._messages:
         if message[1] == InfoWindow.INFO:
             color_attr = curses.color_pair(3)
         elif message[1] == InfoWindow.WARNING:
             color_attr = curses.color_pair(4)
         elif message[1] == InfoWindow.ERROR:
             color_attr = curses.color_pair(5)
         text = '[{}] {}'.format(message[0], message[2])
         self._window.addstr(
             start_line, 0, text, color_attr
         )
         start_line += compute_used_lines(self._window, text)
     self._window.refresh()
Example #3
0
    def _get_tweets(self):
        """
        Fetch tweets which will be printed. It fetch only tweets that can be fully
        displayed.
        """
        keys = reversed(self._tweet_database.keys())
        total_lines = 0
        tweets = OrderedDict()
        for key in keys:
            tweet = self._tweet_database[key]
            formatted = self._format_tweet((key, tweet))
            used_lines = compute_used_lines(self._window, formatted)
            window_size = self._window.getmaxyx()
            if total_lines + used_lines <= window_size[0]:
                total_lines += used_lines
                tweets[key] = tweet

        return reversed(list(tweets.items()))