def calc_screen(self): """The purpose of this method is to translate changes in self.buffer into changes in self.screen. Currently it rips everything down and starts from scratch, which whilst not especially efficient is certainly simple(r). """ lines = self.get_unicode().split("\n") screen = [] screeninfo = [] def put_line(text): screen.append(text) screeninfo.append((0, [])) def put_line_wrapped(text): i = 0 while len(text) - i > w: put_line(text[i:i+w] + self.wrap_marker) i += w put_line(text[i:]) def put_lines_wrapped(text): for logical_line in text.split("\n"): put_line_wrapped(logical_line) w = self.console.width - len(self.wrap_marker) p = self.pos for ln, line in enumerate(lines): ll = len(line) line_contains_cursor = 0 <= p <= ll if line_contains_cursor: if self.msg and not self.msg_at_bottom: put_lines_wrapped(self.msg) self.lxy = p, ln prompt = self.get_prompt(ln, line_contains_cursor) p -= ll + 1 while len(prompt) >= w: put_line(prompt[:w] + self.wrap_marker) prompt = prompt[w:] lp = len(prompt) l, l2 = disp_str(line) wrapcount = (len(l) + lp) / w if wrapcount == 0: screen.append(prompt + l) screeninfo.append((lp, l2+[1])) else: screen.append(prompt + l[:w-lp] + self.wrap_marker) screeninfo.append((lp, l2[:w-lp])) for i in range(-lp + w, -lp + wrapcount*w, w): screen.append(l[i:i+w] + self.wrap_marker) screeninfo.append((0, l2[i:i + w])) screen.append(l[wrapcount*w - lp:]) screeninfo.append((0, l2[wrapcount*w - lp:]+[1])) self.screeninfo = screeninfo self.cxy = self.pos2xy(self.pos) if self.msg and self.msg_at_bottom: put_lines_wrapped(self.msg) return screen
def calc_screen(self): """The purpose of this method is to translate changes in self.buffer into changes in self.screen. Currently it rips everything down and starts from scratch, which whilst not especially efficient is certainly simple(r). """ lines = self.get_unicode().split("\n") screen = [] screeninfo = [] def put_line(text): screen.append(text) screeninfo.append((0, [])) def put_line_wrapped(text): i = 0 while len(text) - i > w: put_line(text[i:i + w] + self.wrap_marker) i += w put_line(text[i:]) def put_lines_wrapped(text): for logical_line in text.split("\n"): put_line_wrapped(logical_line) w = self.console.width - len(self.wrap_marker) p = self.pos for ln, line in enumerate(lines): ll = len(line) line_contains_cursor = 0 <= p <= ll if line_contains_cursor: if self.msg and not self.msg_at_bottom: put_lines_wrapped(self.msg) self.lxy = p, ln prompt = self.get_prompt(ln, line_contains_cursor) p -= ll + 1 while len(prompt) >= w: put_line(prompt[:w] + self.wrap_marker) prompt = prompt[w:] lp = len(prompt) l, l2 = disp_str(line) wrapcount = (len(l) + lp) / w if wrapcount == 0: screen.append(prompt + l) screeninfo.append((lp, l2 + [1])) else: screen.append(prompt + l[:w - lp] + self.wrap_marker) screeninfo.append((lp, l2[:w - lp])) for i in range(-lp + w, -lp + wrapcount * w, w): screen.append(l[i:i + w] + self.wrap_marker) screeninfo.append((0, l2[i:i + w])) screen.append(l[wrapcount * w - lp:]) screeninfo.append((0, l2[wrapcount * w - lp:] + [1])) self.screeninfo = screeninfo self.cxy = self.pos2xy(self.pos) if self.msg and self.msg_at_bottom: put_lines_wrapped(self.msg) return screen
def calc_screen(self): """The purpose of this method is to translate changes in self.buffer into changes in self.screen. Currently it rips everything down and starts from scratch, which whilst not especially efficient is certainly simple(r). """ lines = self.get_unicode().split("\n") screen = [] screeninfo = [] w = self.console.width - 1 p = self.pos for ln, line in zip(range(len(lines)), lines): ll = len(line) if 0 <= p <= ll: if self.msg and not self.msg_at_bottom: for mline in self.msg.split("\n"): screen.append(mline) screeninfo.append((0, [])) self.lxy = p, ln prompt = self.get_prompt(ln, ll >= p >= 0) while '\n' in prompt: pre_prompt, _, prompt = prompt.partition('\n') screen.append(pre_prompt) screeninfo.append((0, [])) p -= ll + 1 prompt, lp = self.process_prompt(prompt) l, l2 = disp_str(line) wrapcount = (len(l) + lp) / w if wrapcount == 0: screen.append(prompt + l) screeninfo.append((lp, l2+[1])) else: screen.append(prompt + l[:w-lp] + "\\") screeninfo.append((lp, l2[:w-lp])) for i in range(-lp + w, -lp + wrapcount*w, w): screen.append(l[i:i+w] + "\\") screeninfo.append((0, l2[i:i + w])) screen.append(l[wrapcount*w - lp:]) screeninfo.append((0, l2[wrapcount*w - lp:]+[1])) self.screeninfo = screeninfo self.cxy = self.pos2xy(self.pos) if self.msg and self.msg_at_bottom: for mline in self.msg.split("\n"): screen.append(mline) screeninfo.append((0, [])) return screen
def calc_screen(self): """The purpose of this method is to translate changes in self.buffer into changes in self.screen. Currently it rips everything down and starts from scratch, which whilst not especially efficient is certainly simple(r). """ lines = self.get_unicode().split("\n") screen = [] screeninfo = [] w = self.console.width - 1 p = self.pos for ln, line in zip(range(len(lines)), lines): ll = len(line) if 0 <= p <= ll: if self.msg and not self.msg_at_bottom: for mline in self.msg.split("\n"): screen.append(mline) screeninfo.append((0, [])) self.lxy = p, ln prompt = self.get_prompt(ln, ll >= p >= 0) while '\n' in prompt: pre_prompt, _, prompt = prompt.partition('\n') screen.append(pre_prompt) screeninfo.append((0, [])) p -= ll + 1 prompt, lp = self.process_prompt(prompt) l, l2 = disp_str(line) wrapcount = (len(l) + lp) / w if wrapcount == 0: screen.append(prompt + l) screeninfo.append((lp, l2 + [1])) else: screen.append(prompt + l[:w - lp] + "\\") screeninfo.append((lp, l2[:w - lp])) for i in range(-lp + w, -lp + wrapcount * w, w): screen.append(l[i:i + w] + "\\") screeninfo.append((0, l2[i:i + w])) screen.append(l[wrapcount * w - lp:]) screeninfo.append((0, l2[wrapcount * w - lp:] + [1])) self.screeninfo = screeninfo self.cxy = self.pos2xy(self.pos) if self.msg and self.msg_at_bottom: for mline in self.msg.split("\n"): screen.append(mline) screeninfo.append((0, [])) return screen