Move function used only in one place to that place

This commit is contained in:
Kovid Goyal 2024-07-22 13:42:59 +05:30
parent b6ca501111
commit d31c48092a
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 22 deletions

View file

@ -44,7 +44,6 @@
)
from .fast_data_types import WINDOW_FULLSCREEN, WINDOW_MAXIMIZED, WINDOW_MINIMIZED, WINDOW_NORMAL, Color, Shlex, get_options, monotonic, open_tty
from .fast_data_types import timed_debug_print as _timed_debug_print
from .rgb import to_color
from .types import run_once
from .typing import AddressFamily, PopenType, Socket, StartupCtx
@ -164,26 +163,6 @@ def color_from_int(val: int) -> Color:
return Color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
def parse_color_set(raw: str) -> Generator[Tuple[int, Optional[int]], None, None]:
parts = raw.split(';')
lp = len(parts)
if lp % 2 != 0:
return
for c_, spec in [parts[i:i + 2] for i in range(0, len(parts), 2)]:
try:
c = int(c_)
if c < 0 or c > 255:
continue
if spec == '?':
yield c, None
else:
q = to_color(spec)
if q is not None:
yield c, int(q) & 0xffffff
except Exception:
continue
class ScreenSize(NamedTuple):
rows: int
cols: int

View file

@ -111,7 +111,6 @@
log_error,
open_cmd,
open_url,
parse_color_set,
path_from_osc7_url,
resolve_custom_file,
resolved_shell,
@ -1293,6 +1292,26 @@ def change(which: DynamicColor, val: str) -> None:
def set_color_table_color(self, code: int, bvalue: Optional[memoryview] = None) -> None:
value = str(bvalue or b'', 'utf-8', 'replace')
cp = self.screen.color_profile
def parse_color_set(raw: str) -> Generator[Tuple[int, Optional[int]], None, None]:
parts = raw.split(';')
lp = len(parts)
if lp % 2 != 0:
return
for c_, spec in [parts[i:i + 2] for i in range(0, len(parts), 2)]:
try:
c = int(c_)
if c < 0 or c > 255:
continue
if spec == '?':
yield c, None
else:
q = to_color(spec)
if q is not None:
yield c, color_as_int(q)
except Exception:
continue
if code == 4:
changed = False
for c, val in parse_color_set(value):