Exemple #1
0
def inputbox(text, x, y, w, h):
    """
    It creates a surface for an inline editor.   
    """
    from plasma.lib.ui.inlineed import InlineEd
    ed = InlineEd(h, w, 0, 0, 0, text, 0, [])
    screen = curses.newwin(h, w, y, x)
    ret = ed.start_view(screen)
    if not ret:
        return ""
    return ed.text
Exemple #2
0
def inputbox(text, x, y, w, h):
    """
    It creates a surface for an inline editor.   
    """
    from plasma.lib.ui.inlineed import InlineEd
    ed = InlineEd(0, 0, 0, text, 0, [])
    ed.screen = curses.newwin(h, w, y, x)
    ret = ed.start_view(ed.screen)
    if not ret:
        return ""
    return ed.text
Exemple #3
0
    def open_textbox(self, screen, text):
        from plasma.lib.ui.inlineed import InlineEd
        (h, w) = screen.getmaxyx()

        ed = InlineEd(self, h, w, 0, 0, 0, text, 0, [])

        # TODO: fix self.cursor_x >= w
        self.cursor_x = len(text)
        if self.cursor_x >= w:
            self.cursor_x = w - 1

        ed.print_curr_line = False
        ret = ed.start_view(screen)
        if not ret:
            return ""
        return ed.text
Exemple #4
0
    def view_inline_comment_editor(self, h, w):
        line = self.win_y + self.cursor_y
        if line not in self.output.line_addr:
            return True

        addr = self.output.line_addr[line]

        # The same address can be repeated on multiple lines
        # With this we are sure to everytime on the same line
        # example for mips:
        #   # 0x4002bc: lui $gp, 0x19
        #   # 0x4002c0: addiu $gp, $gp, -0x63dc
        #   0x4002bc: li $gp, 0x189c24
        new_line = self.output.addr_line[addr]

        if new_line != line:
            self.goto_line(new_line, h)
            line = new_line
            (h, w) = self.screen.getmaxyx()
            self.view_main_redraw(h, w)

        tok_line = list(self.output.token_lines[line])
        str_line = str(self.output.lines[line])

        # A user comment should always be at the end of the line

        # Get coords of the user comment
        if addr in self.db.user_inline_comments:
            xbegin = self.output.idx_tok_inline_comm[line]
            str_line = str_line[:xbegin]
            tok_line.pop(-1)
            text = self.db.user_inline_comments[addr]
            is_new_token = False
        else:
            tok_line.append(
                (" ; ", COLOR_USER_COMMENT.val, COLOR_USER_COMMENT.bold))
            str_line += " ; "
            xbegin = len(self.output.lines[line]) + 3
            text = ""
            is_new_token = True

        self.status_bar_message("-- INLINE COMMENT --", h)

        idx_token = len(tok_line)
        ed = InlineEd(h, w, line, xbegin, idx_token, text,
                      COLOR_USER_COMMENT.val, tok_line)
        ed.cursor_x = self.cursor_x
        ed.cursor_y = self.cursor_y

        ret = ed.start_view(self.screen)

        if ret:
            self.db.modified = True
            if ed.text:
                self.db.user_inline_comments[addr] = ed.text
                o = (ed.text, COLOR_USER_COMMENT.val, COLOR_USER_COMMENT.bold)
                ed.tok_line.append(o)
                str_line += ed.text

                self.output.lines[line] = str_line
                self.output.token_lines[line] = ed.tok_line
                self.output.idx_tok_inline_comm[line] = xbegin

            else:
                ed.tok_line.pop(-1)  # remove the " ; "
                str_line = str_line[:-3]

                self.output.token_lines[line] = ed.tok_line
                self.output.lines[line] = str_line

                if not is_new_token:
                    del self.db.user_inline_comments[addr]

        return True
Exemple #5
0
    def view_inline_comment_editor(self, h, w):
        line = self.win_y + self.cursor_y
        if line not in self.output.line_addr:
            return True

        addr = self.output.line_addr[line]

        # The same address can be repeated on multiple lines
        # With this we are sure to everytime on the same line
        # example for mips:
        #   # 0x4002bc: lui $gp, 0x19
        #   # 0x4002c0: addiu $gp, $gp, -0x63dc
        #   0x4002bc: li $gp, 0x189c24
        new_line = self.output.addr_line[addr]

        if new_line != line:
            self.goto_line(new_line, h)
            line = new_line
            (h, w) = self.screen.getmaxyx()
            self.view_main_redraw(h, w)

        tok_line = list(self.output.token_lines[line])
        str_line = str(self.output.lines[line])

        # A user comment should always be at the end of the line

        # Get coords of the user comment
        if addr in self.db.user_inline_comments:
            xbegin = self.output.idx_tok_inline_comm[line]
            str_line = str_line[:xbegin]
            tok_line.pop(-1)
            text = self.db.user_inline_comments[addr]
            is_new_token = False
        else:
            tok_line.append((" ; ", COLOR_USER_COMMENT.val,
                    COLOR_USER_COMMENT.bold))
            str_line += " ; "
            xbegin = len(self.output.lines[line]) + 3
            text = ""
            is_new_token = True

        self.status_bar("-- INLINE COMMENT --", h)

        idx_token = len(tok_line)
        ed = InlineEd(self, h, w, line, xbegin, idx_token, text,
                      COLOR_USER_COMMENT.val, tok_line)

        ret = ed.start_view(self.screen)

        if ret:
            self.db.modified = True
            if ed.text:
                self.db.user_inline_comments[addr] = ed.text
                o = (ed.text, COLOR_USER_COMMENT.val, COLOR_USER_COMMENT.bold)
                ed.tok_line.append(o)
                str_line += ed.text

                self.output.lines[line] = str_line
                self.output.token_lines[line] = ed.tok_line
                self.output.idx_tok_inline_comm[line] = xbegin

            else:
                ed.tok_line.pop(-1) # remove the " ; "
                str_line = str_line[:-3]

                self.output.token_lines[line] = ed.tok_line
                self.output.lines[line] = str_line

                if not is_new_token:
                    del self.db.user_inline_comments[addr]

        return True
Exemple #6
0
    def view_inline_comment_editor(self):
        line = self.win_y + self.cursor_y
        if line not in self.output.line_addr:
            return True

        addr = self.output.line_addr[line]

        # The same address can be repeated on multiple lines
        # With this we are sure to be everytime on the same line
        new_line = self.output.addr_line[addr]

        if new_line != line:
            self.goto_line(new_line)
            line = new_line
            self.draw()

        tok_line = list(self.output.token_lines[line])
        str_line = str(self.output.lines[line])

        # A user comment should always be at the end of the line

        # Get coords of the user comment
        if addr in self.db.user_inline_comments:
            xbegin = self.output.idx_tok_inline_comm[line]
            str_line = str_line[:xbegin]
            tok_line.pop(-1)
            text = self.db.user_inline_comments[addr]
            is_new_token = False
        else:
            tok_line.append((" ; ", COLOR_USER_COMMENT.val,
                    COLOR_USER_COMMENT.bold))
            str_line += " ; "
            xbegin = len(self.output.lines[line]) + 3
            text = ""
            is_new_token = True

        self.status_bar_message("-- INLINE COMMENT --")

        idx_token = len(tok_line)
        ed = InlineEd(line, xbegin, idx_token, text,
                      COLOR_USER_COMMENT.val, tok_line)
        ed.cursor_x = self.cursor_x
        ed.cursor_y = self.cursor_y

        ret = ed.start_view(self.screen)

        if ret:
            self.db.modified = True
            if ed.text:
                self.db.user_inline_comments[addr] = ed.text
                o = (ed.text, COLOR_USER_COMMENT.val, COLOR_USER_COMMENT.bold)
                ed.tok_line.append(o)
                str_line += ed.text

                self.output.lines[line] = str_line
                self.output.token_lines[line] = ed.tok_line
                self.output.idx_tok_inline_comm[line] = xbegin

            else:
                ed.tok_line.pop(-1) # remove the " ; "
                str_line = str_line[:-3]

                self.output.token_lines[line] = ed.tok_line
                self.output.lines[line] = str_line

                if not is_new_token:
                    del self.db.user_inline_comments[addr]

        return True