MCPcopy Index your code
hub / github.com/RustPython/RustPython / calc_screen

Method calc_screen

Lib/_pyrepl/reader.py:323–420  ·  view source on GitHub ↗

Translate changes in self.buffer into changes in self.console.screen.

(self)

Source from the content-addressed store, hash-verified

321 return default_keymap
322
323 def calc_screen(self) -> list[str]:
324 """Translate changes in self.buffer into changes in self.console.screen."""
325 # Since the last call to calc_screen:
326 # screen and screeninfo may differ due to a completion menu being shown
327 # pos and cxy may differ due to edits, cursor movements, or completion menus
328
329 # Lines that are above both the old and new cursor position can't have changed,
330 # unless the terminal has been resized (which might cause reflowing) or we've
331 # entered or left paste mode (which changes prompts, causing reflowing).
332 num_common_lines = 0
333 offset = 0
334 if self.last_refresh_cache.valid(self):
335 offset, num_common_lines = self.last_refresh_cache.get_cached_location(self)
336
337 screen = self.last_refresh_cache.screen
338 del screen[num_common_lines:]
339
340 screeninfo = self.last_refresh_cache.screeninfo
341 del screeninfo[num_common_lines:]
342
343 last_refresh_line_end_offsets = self.last_refresh_cache.line_end_offsets
344 del last_refresh_line_end_offsets[num_common_lines:]
345
346 pos = self.pos
347 pos -= offset
348
349 prompt_from_cache = (offset and self.buffer[offset - 1] != "\n")
350
351 lines = "".join(self.buffer[offset:]).split("\n")
352
353 cursor_found = False
354 lines_beyond_cursor = 0
355 for ln, line in enumerate(lines, num_common_lines):
356 ll = len(line)
357 if 0 <= pos <= ll:
358 self.lxy = pos, ln
359 cursor_found = True
360 elif cursor_found:
361 lines_beyond_cursor += 1
362 if lines_beyond_cursor > self.console.height:
363 # No need to keep formatting lines.
364 # The console can't show them.
365 break
366 if prompt_from_cache:
367 # Only the first line's prompt can come from the cache
368 prompt_from_cache = False
369 prompt = ""
370 else:
371 prompt = self.get_prompt(ln, ll >= pos >= 0)
372 while "\n" in prompt:
373 pre_prompt, _, prompt = prompt.partition("\n")
374 last_refresh_line_end_offsets.append(offset)
375 screen.append(pre_prompt)
376 screeninfo.append((0, []))
377 pos -= ll + 1
378 prompt, lp = self.process_prompt(prompt)
379 l, l2 = disp_str(line)
380 wrapcount = (wlen(l) + lp) // self.console.width

Callers 2

prepareMethod · 0.95
refreshMethod · 0.95

Calls 14

get_promptMethod · 0.95
process_promptMethod · 0.95
pos2xyMethod · 0.95
enumerateFunction · 0.85
lenFunction · 0.85
disp_strFunction · 0.85
wlenFunction · 0.85
get_cached_locationMethod · 0.80
update_cacheMethod · 0.80
validMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected