Example #1
0
 def _get_current_line(self, win):
     y, x = win.getmaxyx()
     prompt = self.prompt
     promptlen = util.termwidth(prompt)
     if promptlen > x:
         prompt = util.mbs_ljust(prompt, x - 4)
         promptlen = util.termwidth(prompt)
     realpos = sum(self.textmap[: self.cursor])
     if x - promptlen <= sum(self.textmap):
         if x - promptlen <= realpos + 1:
             width = start = 0
             for i, count in enumerate(self.textmap):
                 width += count
                 if x - promptlen <= width:
                     if self.cursor < i:
                         pos = realpos - sum(self.textmap[:start]) + promptlen
                         return (prompt, self.text[start:i], pos)
                     start = i
                     width = count
                     prompt = "..."
                     promptlen = len(prompt)
             pos = realpos - sum(self.textmap[:start]) + promptlen
             return (prompt, self.text[start:], pos)
         else:
             text = util.mbs_ljust(self.text, x - promptlen)
             pos = realpos + promptlen
             return (prompt, text, pos)
     else:
         return (prompt, self.text, realpos + promptlen)
Example #2
0
 def get_drawn_text(self, path, width):
     if self.drawn_text is None:
         fname = self.get_file_name(path)
         fstat = self.get_file_stat()
         namewidth = width - util.termwidth(fstat)
         if namewidth <= 0:
             namewidth = 0
             fstat = util.mbs_ljust(fstat, width)
         fname = util.mbs_ljust(fname, namewidth)
         self.drawn_text = fname + fstat
     return self.drawn_text
Example #3
0
 def addstr(self, win, width):
     if self.doc:
         if self.maxwidth:
             textwidth = self.maxwidth + 2
             if textwidth >= width:
                 textwidth = width // 2
             docwidth = width - textwidth
         else:
             textwidth = docwidth = width // 2
         text = util.mbs_ljust(self.text, textwidth)
         self.addtext(win, text)
         doc = util.mbs_ljust(self.doc, docwidth)
         win.addstr(doc)
     else:
         text = util.mbs_ljust(self.text, width)
         self.addtext(win, text)
Example #4
0
    def draw(self):
        self.listbox.draw()

        self.panel.create_window()
        win = self.panel.win
        self.fix_position()

        win.erase()
        y, x = win.getmaxyx()
        y_offset = 0
        x_offset = 1
        msg = self.message + " "
        try:
            win.addstr(y_offset, x_offset, msg, self.messageattr)
        except curses.error:
            win.erase()
            maxwidth = x - 2 - util.termwidth(" ".join(self.options))
            fixed = util.mbs_ljust(msg, maxwidth)
            win.addstr(y_offset, x_offset, fixed, self.messageattr)

        for i, opt in enumerate(self.options):
            if self.cursor == i:
                win.addstr(opt, curses.A_REVERSE)
            else:
                win.addstr(opt)
            win.addstr(" ")
        win.noutrefresh()
Example #5
0
 def addstr(self, win, width):
     text = util.mbs_ljust(self.text, width-len(self.indent))
     symbol = self.symbol
     win.addstr(self.indent, self.attr)
     for s in self.rematch.split(text):
         if s.startswith(symbol) and s.endswith(symbol):
             s = s.replace("\{0}".format(symbol), symbol)
             win.addstr(s.strip(symbol), self.attr | self.hiattr)
         else:
             win.addstr(s, self.attr)
Example #6
0
    def _draw_statusbar(self, size, height):
        try:
            p = float(self.scrolltop)/float(size-height)*100
        except ZeroDivisionError:
            p = float(self.scrolltop)/float(size)*100
        if p == 0:
            p = "Top"
        elif p >= 100:
            p = "Bot"
        else:
            p = str(int(p)) + "%"
        status = self.statusbar_format.format(
            MARK=len(self.mark_files), FILE=size-1,
            MARKSIZE=self.mark_size, SCROLL=p,
            CURSOR=self.cursor, SORT=self.sort_kind)
        if self.list_title is not None:
            status += self.list_title

        y, x = self.screen.win.getmaxyx()
        if util.termwidth(status) > x-2:
            status = util.mbs_ljust(status, x-2)
        self.screen.win.addstr(y-1, 1, status)
Example #7
0
 def addstr(self, win, width):
     text = util.mbs_ljust(self.text, width)
     self.addtext(win, text)