Esempio n. 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)
Esempio n. 2
0
    def draw_titlebar(self):
        self.titlebar.erase()
        self.titlebar.move(0, 0)
        length = sum([util.termwidth(w.title)+2 for w in self.workspaces])
        y, x = self.stdscr.getmaxyx()

        for i, ws in enumerate(self.workspaces):
            if self.cursor == i:
                self.titlebar.addstr(" {0} ".format(ws.title), look.colors["WorkspaceFocus"])
            else:
                self.titlebar.addstr(" {0} ".format(ws.title))
        self.titlebar.addstr(" | ", curses.A_BOLD)

        dirlen = len(self.workspace.dirs)
        width = (x-length-4) // dirlen
        odd = (x-length-4) % dirlen

        for i, path in enumerate([d.path for d in self.workspace.dirs]):
            num = "[{0}] ".format(i+1)
            numlen = len(num)
            path = util.replhome(path)
            if path.endswith(os.sep):
                path = util.path_omission(path, width-numlen-1)
            else:
                path = util.path_omission(path, width-numlen-1-len(os.sep)) + os.sep
            if i == 0:
                w = width-numlen+odd
            else:
                w = width-numlen
            string = num + util.mbs_rjust(path, w)
            if i == self.workspace.cursor:
                self.titlebar.addstr(string, look.colors["TitlebarFocus"])
            else:
                self.titlebar.addstr(string)
        self.titlebar.noutrefresh()
Esempio n. 3
0
 def draw_message(self, win):
     y, x = win.getmaxyx()
     mlen = util.termwidth(self.message)
     if mlen > x-2:
         win.addstr(0, 2, self.message, self.messageattr)
     else:
         win.addstr(0, (x-mlen)//2, self.message, self.messageattr)
Esempio n. 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()
Esempio n. 5
0
 def _get_maxrow(self, entries):
     maxlen = max(util.termwidth(entry.text) for entry in entries)
     y, x = self.stdscr.getmaxyx()
     maxrow = x // (maxlen+2)
     if maxrow:
         return maxrow
     else:
         return 1
Esempio n. 6
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
Esempio n. 7
0
 def _draw_titlebar(self, width):
     title = ""
     titlewidth = width
     if not self.path.endswith(os.sep):
         title += os.sep
         titlewidth -= len(os.sep)
     if self.maskreg:
         title += "{{{0}}}".format(self.maskreg.pattern)
         titlewidth -= util.termwidth(self.maskreg.pattern)
     path = util.replhome(self.path)
     path = util.path_omission(path, titlewidth)
     self.screen.win.addstr(0, 2, path+title, look.colors["DirectoryPath"])
Esempio n. 8
0
 def draw_options(self, win):
     y, x = win.getmaxyx()
     olen = util.termwidth(" ".join(self.options))
     if olen > x-2:
         win.move(y-2, 2)
     else:
         win.move(y-2, (x-olen)//2)
     for i, opt in enumerate(self.options):
         if self.cursor == i:
             win.addstr(opt, curses.A_REVERSE)
         else:
             win.addstr(opt)
         win.addstr(" ")
Esempio n. 9
0
    def get_window_size(self):
        if self.listbox.active:
            ilen = max(util.termwidth(entry.text) for entry in self.listbox.list) + 2
            height = len(self.listbox.list) + 5
        else:
            ilen = 0
            height = 3
        olen = util.termwidth(" ".join(self.options))
        mlen = util.termwidth(self.message)
        width = max(ilen, olen, mlen) + 4

        y, x = self.stdscr.getmaxyx()
        if height > y:
            height = y
        if width > x:
            width = x
        begy = y//2 - height//2
        begx = x//2 - width//2
        if begy < 0:
            begy = 0
        if begx < 0:
            begx = 0
        return (height, width, begy, begx)
Esempio n. 10
0
    def start(self):
        self.parser = Parser(self.cmdline.text, self.cmdline.cursor)
        CompletionFunction.parser = self.parser
        if self.cmdline.mode.__class__.__name__ == "Shell":
            self.parser.parse()
            compfunc = compfunctions.get(self.parser.prgname, ShellCompletionFunction)()
        else:
            self.parser.parse_nonshell()
            compfunc = CompletionFunction()

        candidates = []
        for item in self.cmdline.mode.complete(compfunc):
            if isinstance(item, Candidate):
                if item.match(self.parser.part[1]):
                    candidates.append(item)
            else:
                if item.startswith(self.parser.part[1]):
                    candidates.append(Candidate(item))

        if not candidates:
            return
        elif len(candidates) == 1:
            self.insert(candidates[0])
            self.hide()
        else:
            self.cmdline.history.hide()
            current = self.parser.part[1]
            names = [c.match(current) for c in candidates]
            common = os.path.commonprefix(names)
            if common:
                self.insert(Candidate(common))
                self.parser.part[1] = common
                for candidate in candidates:
                    candidate.histr = common
            if [c for c in candidates if c.doc]:
                self.maxrow = 1
                Candidate.maxwidth = max(util.termwidth(c.text) for c in candidates)
            else:
                self.maxrow = self._get_maxrow(candidates)
            self.show(candidates)
Esempio n. 11
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)