Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] gh-111201: Add append to screen method to avoid recalculation (GH-119274)#119405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletionLib/_pyrepl/commands.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -358,7 +358,10 @@ def do(self) -> None:
class self_insert(EditCommand):
def do(self) -> None:
r = self.reader
r.insert(self.event * r.get_arg())
text = self.event * r.get_arg()
r.insert(text)
if len(text) == 1 and r.pos == len(r.buffer):
r.calc_screen = r.append_to_screen


class insert_nl(EditCommand):
Expand Down
16 changes: 8 additions & 8 deletionsLib/_pyrepl/completing_reader.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -187,8 +187,8 @@ def do(self) -> None:
if p:
r.insert(p)
if last_is_completer:
if not r.cmpltn_menu_vis:
r.cmpltn_menu_vis =1
if not r.cmpltn_menu_visible:
r.cmpltn_menu_visible =True
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
r.console, completions, r.cmpltn_menu_end,
r.use_brackets, r.sort_in_column)
Expand All@@ -208,7 +208,7 @@ def do(self) -> None:

commands.self_insert.do(self)

if r.cmpltn_menu_vis:
if r.cmpltn_menu_visible:
stem = r.get_stem()
if len(stem) < 1:
r.cmpltn_reset()
Expand All@@ -235,7 +235,7 @@ class CompletingReader(Reader):

### Instance variables
cmpltn_menu: list[str] = field(init=False)
cmpltn_menu_vis: int = field(init=False)
cmpltn_menu_visible: bool = field(init=False)
cmpltn_menu_end: int = field(init=False)
cmpltn_menu_choices: list[str] = field(init=False)

Expand All@@ -255,9 +255,9 @@ def after_command(self, cmd: Command) -> None:
if not isinstance(cmd, (complete, self_insert)):
self.cmpltn_reset()

defcalc_screen(self) -> list[str]:
screen = super().calc_screen()
if self.cmpltn_menu_vis:
defcalc_complete_screen(self) -> list[str]:
screen = super().calc_complete_screen()
if self.cmpltn_menu_visible:
ly = self.lxy[1]
screen[ly:ly] = self.cmpltn_menu
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
Expand All@@ -270,7 +270,7 @@ def finish(self) -> None:

def cmpltn_reset(self) -> None:
self.cmpltn_menu = []
self.cmpltn_menu_vis =0
self.cmpltn_menu_visible =False
self.cmpltn_menu_end = 0
self.cmpltn_menu_choices = []

Expand Down
34 changes: 30 additions & 4 deletionsLib/_pyrepl/reader.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,9 @@
# types
Command = commands.Command
if False:
from typing import Callable
from .types import Callback, SimpleContextManager, KeySpec, CommandName
CalcScreen = Callable[[], list[str]]


def disp_str(buffer: str) -> tuple[str, list[int]]:
Expand DownExpand Up@@ -231,9 +233,11 @@ class Reader:
keymap: tuple[tuple[str, str], ...] = ()
input_trans: input.KeymapTranslator = field(init=False)
input_trans_stack: list[input.KeymapTranslator] = field(default_factory=list)
screen: list[str] = field(default_factory=list)
screeninfo: list[tuple[int, list[int]]] = field(init=False)
cxy: tuple[int, int] = field(init=False)
lxy: tuple[int, int] = field(init=False)
calc_screen: CalcScreen = field(init=False)

def __post_init__(self) -> None:
# Enable the use of `insert` without a `prepare` call - necessary to
Expand All@@ -243,14 +247,36 @@ def __post_init__(self) -> None:
self.input_trans = input.KeymapTranslator(
self.keymap, invalid_cls="invalid-key", character_cls="self-insert"
)
self.screeninfo = [(0, [0])]
self.screeninfo = [(0, [])]
self.cxy = self.pos2xy()
self.lxy = (self.pos, 0)
self.calc_screen = self.calc_complete_screen

def collect_keymap(self) -> tuple[tuple[KeySpec, CommandName], ...]:
return default_keymap

def calc_screen(self) -> list[str]:
def append_to_screen(self) -> list[str]:
new_screen = self.screen.copy() or ['']

new_character = self.buffer[-1]
new_character_len = wlen(new_character)

last_line_len = wlen(new_screen[-1])
if last_line_len + new_character_len >= self.console.width: # We need to wrap here
new_screen[-1] += '\\'
self.screeninfo[-1][1].append(1)
new_screen.append(self.buffer[-1])
self.screeninfo.append((0, [new_character_len]))
else:
new_screen[-1] += self.buffer[-1]
self.screeninfo[-1][1].append(new_character_len)
self.cxy = self.pos2xy()

# Reset the function that is used for completing the screen
self.calc_screen = self.calc_complete_screen
return new_screen

def calc_complete_screen(self) -> list[str]:
"""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
Expand DownExpand Up@@ -563,8 +589,8 @@ def update_screen(self) -> None:
def refresh(self) -> None:
"""Recalculate and refresh the screen."""
# this call sets up self.cxy, so call it first.
screen = self.calc_screen()
self.console.refresh(screen, self.cxy)
self.screen = self.calc_screen()
self.console.refresh(self.screen, self.cxy)
self.dirty = False

def do_cmd(self, cmd: tuple[str, list[str]]) -> None:
Expand Down
2 changes: 1 addition & 1 deletionLib/_pyrepl/unix_console.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -283,7 +283,7 @@ def refresh(self, screen, c_xy):

self.__show_cursor()

self.screen = screen
self.screen = screen.copy()
self.move_cursor(cx, cy)
self.flushoutput()

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp