def display_result(self, y, result, is_current=False, is_marked=False): line, find_info, abs_idx, filename, position = result if is_current: line_style = self.CANDIDATES_LINE_SELECTED elif is_marked: line_style = self.CANDIDATES_LINE_MARKED else: line_style = self.CANDIDATES_LINE_BASIC keyword_style = self.CANDIDATES_LINE_QUERY + line_style self.display_line(y, 0, line, style=line_style) if find_info is None: return for (subq, match_info) in find_info: for x_offset, subq_len in match_info: try: x_offset_real = display.screen_len( line, beg=0, end=x_offset) self.display.add_string(line[x_offset:x_offset + subq_len], pos_y=y, pos_x=x_offset_real, style=keyword_style) except curses.error as e: debug.log("addnstr", str(e) + " ({0})".format(y))
def display_prompt(self): self.caret_x = -1 self.caret_y = -1 self.do_display_prompt(self.RPROMPT, y_offset=self.PROMPT_OFFSET_V, x_align="right") self.do_display_prompt(self.PROMPT, y_offset=self.PROMPT_OFFSET_V) try: # move caret if self.caret_x >= 0 and self.caret_y >= 0: self.screen.move(self.caret_y, self.caret_x + display.screen_len(self.model.query, 0, self.model.caret)) except curses.error: pass
def do_display_prompt(self, format, y_offset=0, x_offset=0, y_align="top", x_align="left"): parsed = self.display.markup_parser.parse(format) offset = 0 tokens = [] self.last_query_position = -1 for s, attrs in parsed: formatted_string = self.format_prompt_string(s, offset) tokens.append((formatted_string, attrs)) offset += display.screen_len(formatted_string) y, x = self.display.add_aligned_string_tokens(tokens, y_offset=y_offset, x_offset=x_offset, y_align=y_align, x_align=x_align) # when %q is specified, record its position if self.last_query_position >= 0: self.caret_x = self.last_query_position + x self.caret_y = self.PROMPT_OFFSET_V