Example #1
0
 def _draw(self):
     i = 0
     lines = self._text.split('\n')
     for s in reduce(lambda x, y: x+y,
                     map(lambda line: split_from_width(line, self.width-1), lines),
                     []):
         if i >= self.height:
             break
         self._win.addstr(i, 0, s)
         i += 1
Example #2
0
    def _draw(self):
        if self._status is None: return
        name = (u'%s(%s)' % (self._status.user.name, self._status.user.screen_name))
        source = self._status.source
        info = (u'%s from %s' % (self._status.created_at+datetime.timedelta(hours=9), source))
        self._win.addstr(0, 0, adjust_n_width(name, self.width-1, fill=u''))

        h, i = 1, 0
        lines = self._status.text.split('\n')
        strings = reduce(lambda x, y: x+y,
                         map(lambda line: split_from_width(line, self.width-1, translate=False), lines),
                         [])
        rem = 0
        while h < self.height-1 and i < len(strings):
            self._win.move(h, 0)
            if rem:
                self._win.addstr(adjust_n_width(strings[i][:rem]), curses.A_REVERSE)

            start, end = rem, rem
            target = strings[i]
            if i != len(strings)-1:
                target += strings[i+1][:len(self._keyword)-1]

            if self._keyword:
                while target[start:].find(self._keyword) >= 0:
                    end = start+target[start:].find(self._keyword)
                    self._win.addstr(adjust_n_width(strings[i][start:end]))
                    self._win.addstr(adjust_n_width(strings[i][end:min(end+len(self._keyword),
                                                                       len(strings[i]))]),
                                     curses.A_REVERSE)
                    start = end+len(self._keyword)
            self._win.addstr(adjust_n_width(strings[i][start:]))
            if end+len(self._keyword) >= len(strings[i]):
                rem = end+len(self._keyword)-len(strings[i])
            else:
                rem = 0
            h += 1
            i += 1
        self._win.addstr(self.height-1, 0, adjust_n_width(info, self.width-1, fill=u''))