Avoid extra type checking import of re
This commit is contained in:
parent
e228f5105e
commit
0fcc446298
@ -53,6 +53,11 @@ def expandvars(val: str, env: Mapping[str, str] = {}, fallback_to_os_env: bool =
|
||||
return re.sub(r'\$(?:(\w+)|\{([^}]+)\})', sub, val.replace('$$', '\0')).replace('\0', '$')
|
||||
|
||||
|
||||
@run_once
|
||||
def sgr_sanitizer_pat() -> re.Pattern[str]:
|
||||
return re.compile('\033\\[.*?m')
|
||||
|
||||
|
||||
def platform_window_id(os_window_id: int) -> Optional[int]:
|
||||
if is_macos:
|
||||
from .fast_data_types import cocoa_window_id
|
||||
|
||||
@ -39,19 +39,18 @@ from .notify import NotificationCommand, handle_notification_cmd
|
||||
from .options.types import Options
|
||||
from .rgb import to_color
|
||||
from .terminfo import get_capabilities
|
||||
from .types import MouseEvent, WindowGeometry, ac, run_once
|
||||
from .types import MouseEvent, WindowGeometry, ac
|
||||
from .typing import BossType, ChildType, EdgeLiteral, TabType, TypedDict
|
||||
from .utils import (
|
||||
get_primary_selection, load_shaders, log_error, open_cmd, open_url,
|
||||
parse_color_set, resolve_custom_file, sanitize_title, set_primary_selection
|
||||
parse_color_set, resolve_custom_file, sanitize_title, set_primary_selection,
|
||||
sgr_sanitizer_pat
|
||||
)
|
||||
|
||||
MatchPatternType = Union[Pattern[str], Tuple[Pattern[str], Optional[Pattern[str]]]]
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import re
|
||||
|
||||
from .file_transmission import FileTransmission
|
||||
|
||||
|
||||
@ -266,14 +265,8 @@ def setup_colors(screen: Screen, opts: Options) -> None:
|
||||
)
|
||||
|
||||
|
||||
@run_once
|
||||
def text_sanitizer_pat() -> 're.Pattern[str]':
|
||||
import re
|
||||
return re.compile('\033\\[.*?m')
|
||||
|
||||
|
||||
def text_sanitizer(as_ansi: bool, add_wrap_markers: bool) -> Callable[[str], str]:
|
||||
pat = text_sanitizer_pat()
|
||||
pat = sgr_sanitizer_pat()
|
||||
ansi, wrap_markers = not as_ansi, not add_wrap_markers
|
||||
|
||||
def remove_wrap_markers(line: str) -> str:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user