示例#1
0
 def rewrite_text(s, i):
     (os, oe) = self.startend
     
     self.win.move(sety, setx)
     self.win.clrtoeol()
     
     if os <= i <= oe:
         self.win.addstr(s[os:i].encode(CENCODING))
         (y, x) = self.win.getyx()
         exstr = ctools.exstr_width(s[i:], self.mx - self.x)
         self.win.addstr(exstr.encode(CENCODING))
         self.win.move(y, x)
         self.startend = (os, i + len(exstr))
     else:
         if i < os:
             exstr = ctools.exstr_width(s[i:], self.mx - self.x)
             self.startend = (i, i + len(exstr))
             self.win.addstr(exstr.encode(CENCODING))
             self.win.move(self.y, self.x)
         else:
             exstr = ctools.exstr_width(
                 s[i - 1::-1], ctools.cw_count(s[os:oe]) + 3)
             exstr = ctools.exstr_width(exstr, self.mx - self.x)
             exstr = exstr[::-1]
             self.startend = (i - len(exstr), i)
             self.win.addstr(exstr.encode(CENCODING))
示例#2
0
    def refresh(self):
        syx = curses.getsyx()
        self.wname.clear()
        self.wtext.clear()
        
        (my, mx) = self.wtext.getmaxyx()
        my -= 1
        
        y = 0
        for i, s in enumerate(self.timeline[self.offset:]):
            # escape illegal character
            text = ctools.delete_notprintable(s.text)
            
            cnt = ctools.cw_count(text)
            row = int(math.ceil(float(cnt) / float(mx)))
            rem = my - y
            xmod = cnt % mx
            
            if row > rem:
                s = copy.copy(s)
                text = ctools.split_text(text, (rem * mx) - 1)[0]
            
            attr = ctools.attr_select(s, self.twitter.my_name)
            
            if self.selected == i:
                attr |= curses.A_STANDOUT
                if xmod != 0:
                    text += " " * (mx - xmod)
            
            try:
                self.wname.addstr(y, 0, s.user.screen_name[:9], attr)
                self.wtext.addstr(y, 0, text.encode(self.CENCODING), attr)
            except:
                curses.endwin()
                print s.user.screen_name, text
                print ["%x %s" % (ord(c), c)
                       for c in text]

            y += row
            if y >= my: 
                self.last = i
                break
        
        self.wname.refresh()
        self.wtext.refresh(*self.wtext_refp)
        
        curses.setsyx(*syx)
        self.on_refresh()