Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Remove enum
  • Loading branch information
ambv committed May 21, 2024
commit ca97bd55e74845cb2aa632468c1e40985b81b609
4 changes: 1 addition & 3 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from __future__ import annotations
import os

from .utils import CalcScreen

# Categories of actions:
# killing
# yanking
Expand Down Expand Up @@ -363,7 +361,7 @@ def do(self) -> None:
text = self.event * r.get_arg()
r.insert(text)
if len(text) == 1 and r.pos == len(r.buffer):
r.calc_screen_method = CalcScreen.CALC_APPEND_SCREEN
r.calc_screen = r.append_to_screen


class insert_nl(EditCommand):
Expand Down
16 changes: 8 additions & 8 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff 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()

def calc_screen(self) -> list[str]:
screen = super().calc_screen()
if self.cmpltn_menu_vis:
def calc_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
18 changes: 6 additions & 12 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@


from . import commands, console, input
from .utils import ANSI_ESCAPE_SEQUENCE, wlen, CalcScreen
from .utils import ANSI_ESCAPE_SEQUENCE, wlen
from .trace import trace


# 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 Down Expand Up @@ -233,7 +235,7 @@ class Reader:
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_method: CalcScreen = CalcScreen.CALC_COMPLETE_SCREEN
calc_screen: CalcScreen = field(init=False)

def __post_init__(self) -> None:
# Enable the use of `insert` without a `prepare` call - necessary to
Expand All @@ -246,6 +248,7 @@ def __post_init__(self) -> None:
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
Expand All @@ -268,7 +271,7 @@ def append_to_screen(self) -> list[str]:
self.cxy = self.pos2xy()

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

def calc_complete_screen(self) -> list[str]:
Expand Down Expand Up @@ -326,15 +329,6 @@ def calc_complete_screen(self) -> list[str]:
screeninfo.append((0, []))
return screen

def calc_screen(self) -> list[str]:
match self.calc_screen_method:
case CalcScreen.CALC_COMPLETE_SCREEN:
return self.calc_complete_screen()
case CalcScreen.CALC_APPEND_SCREEN:
return self.append_to_screen()
case _:
assert False, "No valid calc_screen"

def process_prompt(self, prompt: str) -> tuple[str, int]:
"""Process the prompt.

Expand Down
6 changes: 0 additions & 6 deletions Lib/_pyrepl/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import re
import unicodedata
from enum import Enum

ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[ -@]*[A-~]")


class CalcScreen(Enum):
CALC_COMPLETE_SCREEN = 1
CALC_APPEND_SCREEN = 2


def str_width(c: str) -> int:
w = unicodedata.east_asian_width(c)
if w in ('N', 'Na', 'H', 'A'):
Expand Down