def locate_cursor(self, pos, top=None, middle=None, bottom=None, align_always=False): if top is middle is bottom is None: middle = self.CURSOR_TO_MIDDLE_ON_SCROLL bottom = not self.CURSOR_TO_MIDDLE_ON_SCROLL self.screen.apply_updates() self.screen.locate(pos, top=top, middle=middle, bottom=bottom, align_always=align_always) idx, x = self.screen.getrowcol(pos) y = idx - self.screen.portfrom retpos = self.screen.get_pos_under(idx, x) screenx = x if self.document.mode.SHOW_LINENO: screenx = x + screen.calc_lineno_width(self.screen) # if (y, screenx) != self._cwnd.getyx(): # h, w = self._cwnd.getmaxyx() # if y < h and screenx < w and y >= 0 and screenx >= 0: # self._cwnd.move(y, screenx) self.document.mode.on_cursor_located(self, retpos, y, x) if self.document.mode.HIGHLIGHT_CURSOR_ROW: self.screen.style_updated() return retpos, y, screenx
def _draw_screen(self, force=False): # don't draw is frame is not visible. frame = self.get_label('frame') if frame: if kaa.app.get_activeframe() is not frame: return self.screen.apply_updates() self.screen.row_drawn() # save cursor position # if kaa.app.focus: # if self.document.mode.is_cursor_visible(): # cury, curx = kaa.app.focus._cwnd.getyx() # h, w = self._cwnd.getmaxyx() rows = list(self.screen.get_visible_rows()) cur_sel = self.screen.selection.get_selrange() lineno_width = 0 lineno = self.document.buf.lineno.lineno(self.screen.pos) if self.document.mode.SHOW_LINENO: lineno_color = self.document.mode.theme.get_style( 'lineno').cui_colorattr lineno_width = screen.calc_lineno_width(self.screen) _, cursorrow = self.screen.getrow(self.cursor.pos) tol = rows[0].tol eol = self.document.geteol(tol) endpos = self.document.endpos() rectangular = self.screen.selection.is_rectangular() selfrom = selto = colfrom = colto = -1 if not rectangular: selrange = self.screen.selection.get_selrange() if selrange: selfrom, selto = selrange else: selrect = self.screen.selection.get_rect_range() if selrect: selfrom, selto, colfrom, colto = selrect theme = self.document.mode.theme defaultcolor = theme.get_style('default').cui_colorattr overlays = self.document.mode.get_line_overlays() overlays.update(self.line_overlays) for n, row in enumerate(rows): if n > h: break spos = 0 if tol != row.tol: tol = row.tol eol = self.document.geteol(tol) line_overlay = None if row is cursorrow and ( self.highlight_cursor_row or self.document.mode.HIGHLIGHT_CURSOR_ROW): line_overlay = self.OVERLAY_CURSORROW else: for pos in overlays.keys(): if (tol <= pos < eol) or (pos == tol == eol == endpos): line_overlay = overlays[pos] break # clear row self._cwnd.move(n, 0) self._cwnd.clrtoeol() if not line_overlay: erase_attr = defaultcolor else: style = theme.get_style('default') erase_attr = style.cui_overlays.get(line_overlay, defaultcolor) self._cwnd.chgat(n, 0, -1, erase_attr) if not self.visible: continue # draw line no if self.document.mode.SHOW_LINENO: self._cwnd.move(n, 0) if row.posfrom == row.tol: self.add_str(str(lineno).rjust(lineno_width - 1), lineno_color) else: self.add_str(' ' * (lineno_width - 1), lineno_color) self.add_str(' ', defaultcolor) # increment line no lineno += 1 # move cursor to top of row self._cwnd.move(n, row.wrapindent + lineno_width) rjust = False for (attr, attr_rjust), group in itertools.groupby( self._getcharattrs(row, rectangular, selfrom, selto, colfrom, colto, line_overlay)): if not rjust and attr_rjust: rjust = True rest = sum(row.cols[spos:]) cy, cx = self._cwnd.getyx() self._cwnd.move(cy, w - rest) slen = len(tuple(group)) letters = ''.join(row.chars[spos:spos + slen]).rstrip('\n') self.add_str(letters, attr) spos += slen if row.chars == '\n': if selfrom <= row.posfrom < selto: if not rectangular or (colfrom == 0): self.add_str(' ', curses.A_REVERSE) if len(rows) < h: self._cwnd.move(len(rows), 0) self._cwnd.clrtobot() if self.document.mode.SHOW_BLANK_LINE: attr = theme.get_style('blank-line-header').cui_colorattr for i in range(len(rows), h): self._cwnd.move(i, 0) self.add_str('~', attr) # if kaa.app.focus: # if self.document.mode.is_cursor_visible(): # kaa.app.focus._cwnd.move(cury, curx) return
def _draw_screen(self, force=False): frame = self.get_label('frame') if frame: if self.mainframe.activeframe is not frame: return self.screen.apply_updates() if kaa.app.focus: cury, curx = kaa.app.focus._cwnd.getyx() h, w = self._cwnd.getmaxyx() rows = list(self.screen.get_visible_rows()) cur_sel = self.screen.selection.get_range() theme = self.document.mode.theme defaultcolor = theme.get_style('default').cui_colorattr if force: drawn = {} updated = True else: updated = len(rows) != len(self._drawn_rows) drawn = self._drawn_rows self._drawn_rows = {} tol = rows[0].tol lineno_width = 0 if self.document.mode.SHOW_LINENO: lineno_color = self.document.mode.theme.get_style('lineno').cui_colorattr lineno_width = screen.calc_lineno_width(self.screen) lineno = self.document.buf.lineno.lineno(self.screen.pos) for n, row in enumerate(rows): if n > h: break if drawn.get(row) == (n, cur_sel): # The raw was already drawn. continue updated = True s = 0 # clear row self._cwnd.move(n, 0) self._cwnd.clrtoeol() self._cwnd.chgat(n, 0, -1, defaultcolor) # draw line no if self.document.mode.SHOW_LINENO: self._cwnd.move(n, 0) if tol != row.tol: lineno += 1 tol = row.tol if row.posfrom == row.tol: self.add_str(str(lineno).rjust(lineno_width-1), lineno_color) else: self.add_str(' ' * (lineno_width-1), lineno_color) self.add_str(' ', defaultcolor) # move cursor to top of row self._cwnd.move(n, row.wrapindent+lineno_width) rjust = False for (attr, attr_rjust), group in itertools.groupby(self._getcharattrs(row)): if not rjust and attr_rjust: rjust = True rest = sum(row.cols[s:]) cy, cx = self._cwnd.getyx() self._cwnd.move(cy, w-rest) slen = len(tuple(group)) letters = ''.join(row.chars[s:s+slen]).rstrip('\n') self.add_str(letters, attr) s += slen self._drawn_rows[row] = (n, cur_sel) if len(rows) < h: self._cwnd.move(len(rows), 0) self._cwnd.clrtobot() if kaa.app.focus: kaa.app.focus._cwnd.move(cury, curx) return updated
def _draw_screen(self, force=False): # don't draw is frame is not visible. frame = self.get_label('frame') if frame: if kaa.app.get_activeframe() is not frame: return self.screen.apply_updates() self.screen.row_drawn() # save cursor position # if kaa.app.focus: # if self.document.mode.is_cursor_visible(): # cury, curx = kaa.app.focus._cwnd.getyx() # h, w = self._cwnd.getmaxyx() rows = list(self.screen.get_visible_rows()) lineno_width = 0 lineno = self.document.buf.lineno.lineno(self.screen.pos) if self.document.mode.SHOW_LINENO: lineno_color = self.document.mode.theme.get_style( 'lineno').cui_colorattr lineno_width = screen.calc_lineno_width(self.screen) _, cursorrow = self.screen.getrow(self.cursor.pos) tol = rows[0].tol eol = self.document.geteol(tol) endpos = self.document.endpos() rectangular = self.screen.selection.is_rectangular() selfrom = selto = colfrom = colto = -1 if not rectangular: selrange = self.screen.selection.get_selrange() if selrange: selfrom, selto = selrange else: selrect = self.screen.selection.get_rect_range() if selrect: selfrom, selto, colfrom, colto = selrect theme = self.document.mode.theme defaultcolor = theme.get_style('default').cui_colorattr overlays = self.document.mode.get_line_overlays() overlays.update(self.line_overlays) for n, row in enumerate(rows): if n > h: break spos = 0 if tol != row.tol: tol = row.tol eol = self.document.geteol(tol) line_overlay = None if row is cursorrow and (self.highlight_cursor_row or self.document.mode.HIGHLIGHT_CURSOR_ROW): line_overlay = self.OVERLAY_CURSORROW else: for pos in overlays.keys(): if (tol <= pos < eol) or (pos == tol == eol == endpos): line_overlay = overlays[pos] break # clear row self._cwnd.move(n, 0) self._cwnd.clrtoeol() if not line_overlay: erase_attr = defaultcolor else: style = theme.get_style('default') erase_attr = style.cui_overlays.get(line_overlay, defaultcolor) self._cwnd.chgat(n, 0, -1, erase_attr) if not self.visible: continue # draw line no if self.document.mode.SHOW_LINENO: self._cwnd.move(n, 0) if row.posfrom == row.tol: self.add_str( str(lineno).rjust(lineno_width - 1), lineno_color) else: self.add_str(' ' * (lineno_width - 1), lineno_color) self.add_str(' ', defaultcolor) # increment line no lineno += 1 # move cursor to top of row self._cwnd.move(n, row.wrapindent + lineno_width) rjust = False for (attr, attr_rjust), group in itertools.groupby( self._getcharattrs(row, rectangular, selfrom, selto, colfrom, colto, line_overlay)): if not rjust and attr_rjust: rjust = True rest = sum(row.cols[spos:]) cy, cx = self._cwnd.getyx() self._cwnd.move(cy, w - rest) slen = len(tuple(group)) letters = ''.join(row.chars[spos:spos + slen]).rstrip('\n') self.add_str(letters, attr) spos += slen if row.chars == '\n': if selfrom <= row.posfrom < selto: if not rectangular or (colfrom == 0): self.add_str(' ', curses.A_REVERSE) if len(rows) < h: self._cwnd.move(len(rows), 0) self._cwnd.clrtobot() if self.document.mode.SHOW_BLANK_LINE: attr = theme.get_style('blank-line-header').cui_colorattr for i in range(len(rows), h): self._cwnd.move(i, 0) self.add_str('~', attr) # if kaa.app.focus: # if self.document.mode.is_cursor_visible(): # kaa.app.focus._cwnd.move(cury, curx) return
def _draw_screen(self, force=False): frame = self.get_label('frame') if frame: if kaa.app.get_activeframe() is not frame: return self.screen.apply_updates() if kaa.app.focus: if self.document.mode.is_cursor_visible(): cury, curx = kaa.app.focus._cwnd.getyx() h, w = self._cwnd.getmaxyx() rows = list(self.screen.get_visible_rows()) cur_sel = self.screen.selection.get_selrange() theme = self.document.mode.theme defaultcolor = theme.get_style('default').cui_colorattr if force or not self.visible: drawn = {} updated = True else: updated = len(rows) != len(self._drawn_rows) drawn = self._drawn_rows self._drawn_rows = {} tol = rows[0].tol lineno_width = 0 if self.document.mode.SHOW_LINENO: lineno_color = self.document.mode.theme.get_style('lineno').cui_colorattr lineno_width = screen.calc_lineno_width(self.screen) lineno = self.document.buf.lineno.lineno(self.screen.pos) _, cursorrow = self.screen.getrow(self.cursor.pos) rectangular = self.screen.selection.is_rectangular() selfrom = selto = colfrom = colto = -1 if not rectangular: selrange = self.screen.selection.get_selrange() if selrange: selfrom, selto = selrange else: selrect = self.screen.selection.get_rect_range() if selrect: selfrom, selto, colfrom, colto = selrect for n, row in enumerate(rows): if n > h: break if drawn.get(row) == (n, cur_sel): # The raw was already drawn. continue is_cursorline = row is cursorrow updated = True s = 0 # clear row self._cwnd.move(n, 0) self._cwnd.clrtoeol() self._cwnd.chgat(n, 0, -1, defaultcolor) if not self.visible: continue # draw line no if self.document.mode.SHOW_LINENO: self._cwnd.move(n, 0) if tol != row.tol: lineno += 1 tol = row.tol if row.posfrom == row.tol: self.add_str(str(lineno).rjust(lineno_width-1), lineno_color) else: self.add_str(' ' * (lineno_width-1), lineno_color) self.add_str(' ', defaultcolor) # move cursor to top of row self._cwnd.move(n, row.wrapindent+lineno_width) rjust = False for (attr, attr_rjust), group in itertools.groupby( self._getcharattrs(row, rectangular, selfrom, selto, colfrom, colto)): if is_cursorline and self.document.mode.HIGHLIGHT_CURSORLINE: attr |= curses.A_BOLD if not rjust and attr_rjust: rjust = True rest = sum(row.cols[s:]) cy, cx = self._cwnd.getyx() self._cwnd.move(cy, w-rest) slen = len(tuple(group)) letters = ''.join(row.chars[s:s+slen]).rstrip('\n') self.add_str(letters, attr) s += slen if row.chars == '\n': if selfrom <= row.posfrom < selto: if not rectangular or (colfrom == 0): self.add_str(' ', curses.A_REVERSE) self._drawn_rows[row] = (n, cur_sel) if len(rows) < h: self._cwnd.move(len(rows), 0) self._cwnd.clrtobot() if kaa.app.focus: if self.document.mode.is_cursor_visible(): kaa.app.focus._cwnd.move(cury, curx) return updated