Skip to content

Commit db78457

Browse files
authored
Remove color_filter module (Moving to Telix) (jquast#132)
This feature will be moved into https://github.com/jquast/telix
1 parent c0ef0ea commit db78457

16 files changed

Lines changed: 24 additions & 1491 deletions

docs/api/color_filter.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/history.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
History
22
=======
3+
4.0.0
4+
* removed: ``telnetlib3.color_filter``. ``ColorFilter``, ``ColorConfig``, ``PALETTES``,
5+
``PetsciiColorFilter``, and ``AtasciiControlFilter`` have all been moved to the downstream
6+
`Telix <https://github.com/jquast/Telix>`_ project, recommended for connecting to legacy `BBSs
7+
<https://bbs.modem.xyz/>`_ systems requiring color correction.
8+
9+
``telnetlib3-client`` CLI args ``--colormatch``, ``--color-brightness``, ``--color-contrast``,
10+
``--background-color``, ``--ice-colors`` removed.
11+
312
3.0.3
413
* bugfix: server and client now correctly complete LINEMODE negotiation when prompted to.
514
* new: ``--logfile-mode {append,rewrite}`` and ``--typescript-mode`` CLI flags
@@ -124,7 +133,7 @@ History
124133
art) as surrogates instead of replacing them with U+FFFD.
125134

126135
2.4.0
127-
* new: :mod:`telnetlib3.color_filter` module — translates 16-color ANSI SGR
136+
* new: ``telnetlib3.color_filter`` module — translates 16-color ANSI SGR
128137
codes to 24-bit RGB from hardware palettes (EGA, CGA, VGA, xterm).
129138
Enabled by default. New client CLI options: ``--colormatch``,
130139
``--color-brightness``, ``--color-contrast``, ``--background-color``,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "telnetlib3"
7-
version = "3.0.3" # Keep in sync with telnetlib3/accessories.py::get_version !
7+
version = "4.0.0" # Keep in sync with telnetlib3/accessories.py::get_version !
88
description = " Python Telnet server and client CLI and Protocol library"
99
readme = "README.rst"
1010
license = "ISC"

telnetlib3/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from . import stream_reader
1717
from . import client_base
1818
from . import client_shell
19-
from . import color_filter
2019
from . import client
2120
from . import telopt
2221
from . import mud

telnetlib3/_session_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def __init__(self) -> None:
3131
self.raw_mode: Optional[bool] = None
3232
self.ascii_eol: bool = False
3333
self.input_filter: Optional[Any] = None
34-
self.color_filter: Optional[Any] = None
3534
self.autoreply_engine: Optional[Any] = None
3635
self.autoreply_wait_fn: Optional[Callable[..., Awaitable[None]]] = None
3736
self.typescript_file: Optional[IO[str]] = None

telnetlib3/accessories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
def get_version() -> str:
4444
"""Return the current version of telnetlib3."""
45-
return "3.0.3" # keep in sync with pyproject.toml !
45+
return "4.0.0" # keep in sync with pyproject.toml !
4646

4747

4848
def encoding_from_lang(lang: str) -> Optional[str]:

telnetlib3/client.py

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -685,56 +685,7 @@ def _patched_connection_made(transport: asyncio.BaseTransport) -> None:
685685

686686
client_factory: Optional[Callable[..., client_base.BaseClient]] = _client_factory
687687

688-
# Wrap the shell callback to inject color filter when enabled
689-
colormatch: str = args["colormatch"]
690688
shell_callback = args["shell"]
691-
if colormatch.lower() != "none":
692-
from .color_filter import (
693-
PALETTES,
694-
ColorConfig,
695-
ColorFilter,
696-
PetsciiColorFilter,
697-
AtasciiControlFilter,
698-
)
699-
700-
# Auto-select encoding-specific filters
701-
encoding_name: str = args.get("encoding", "") or ""
702-
is_petscii = encoding_name.lower() in ("petscii", "cbm", "commodore", "c64", "c128")
703-
is_atascii = encoding_name.lower() in ("atascii", "atari8bit", "atari_8bit")
704-
if colormatch == "petscii":
705-
colormatch = "c64"
706-
if is_petscii and colormatch != "c64":
707-
colormatch = "c64"
708-
709-
if colormatch not in PALETTES:
710-
print(
711-
f"Unknown palette {colormatch!r}," f" available: {', '.join(sorted(PALETTES))}",
712-
file=sys.stderr,
713-
)
714-
sys.exit(1)
715-
color_config = ColorConfig(
716-
palette_name=colormatch,
717-
brightness=args["color_brightness"],
718-
contrast=args["color_contrast"],
719-
background_color=args["background_color"],
720-
ice_colors=args["ice_colors"],
721-
)
722-
if is_petscii or colormatch == "c64":
723-
color_filter_obj: object = PetsciiColorFilter(color_config)
724-
elif is_atascii:
725-
color_filter_obj = AtasciiControlFilter()
726-
else:
727-
color_filter_obj = ColorFilter(color_config)
728-
original_shell = shell_callback
729-
730-
async def _color_shell(
731-
reader: Union[TelnetReader, TelnetReaderUnicode],
732-
writer_arg: Union[TelnetWriter, TelnetWriterUnicode],
733-
) -> None:
734-
writer_arg.ctx.color_filter = color_filter_obj
735-
await original_shell(reader, writer_arg)
736-
737-
shell_callback = _color_shell
738689

739690
# Wrap shell to inject raw_mode flag and input translation for retro encodings
740691
raw_mode_val: Optional[bool] = args.get("raw_mode", False)
@@ -894,44 +845,6 @@ def _get_argument_parser() -> argparse.ArgumentParser:
894845
metavar="OPT",
895846
help="always send DO for this option (name like GMCP or number, repeatable)",
896847
)
897-
parser.add_argument(
898-
"--colormatch",
899-
default="vga",
900-
metavar="PALETTE",
901-
help=(
902-
"translate basic 16-color ANSI codes to exact 24-bit RGB values"
903-
" from a named hardware palette, bypassing the terminal's custom"
904-
" palette to preserve intended MUD/BBS artwork colors"
905-
" (vga, xterm, none)"
906-
),
907-
)
908-
parser.add_argument(
909-
"--color-brightness",
910-
default=1.0,
911-
type=float,
912-
metavar="FLOAT",
913-
help="color brightness scale [0.0..1.0], where 1.0 is original",
914-
)
915-
parser.add_argument(
916-
"--color-contrast",
917-
default=1.0,
918-
type=float,
919-
metavar="FLOAT",
920-
help="color contrast scale [0.0..1.0], where 1.0 is original",
921-
)
922-
parser.add_argument(
923-
"--background-color",
924-
default="#000000",
925-
metavar="#RRGGBB",
926-
help="forced background color as hex RGB (near-black by default)",
927-
)
928-
parser.add_argument(
929-
"--ice-colors",
930-
action=argparse.BooleanOptionalAction,
931-
default=True,
932-
help="treat SGR 5 (blink) as bright background (iCE colors)"
933-
" for BBS/ANSI art (default: enabled)",
934-
)
935848
parser.add_argument(
936849
"--ascii-eol",
937850
action="store_true",
@@ -1013,20 +926,6 @@ def _parse_option_arg(value: str) -> bytes:
1013926
return bytes([int(value)])
1014927

1015928

1016-
def _parse_background_color(value: str) -> Tuple[int, int, int]:
1017-
"""
1018-
Parse hex color string to RGB tuple.
1019-
1020-
:param value: Color string like ``"#RRGGBB"`` or ``"RRGGBB"``.
1021-
:returns: (R, G, B) tuple with values 0-255.
1022-
:raises ValueError: When *value* is not a valid hex color.
1023-
"""
1024-
h = value.lstrip("#")
1025-
if len(h) != 6:
1026-
raise ValueError(f"invalid hex color: {value!r}")
1027-
return (int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16))
1028-
1029-
1030929
def _transform_args(args: argparse.Namespace) -> Dict[str, Any]:
1031930
# Auto-enable force_binary for any non-ASCII encoding that uses high-bit bytes.
1032931
from .encodings import FORCE_BINARY_ENCODINGS
@@ -1075,11 +974,6 @@ def _transform_args(args: argparse.Namespace) -> Dict[str, Any]:
1075974
"send_environ": tuple(v.strip() for v in args.send_environ.split(",") if v.strip()),
1076975
"always_will": {_parse_option_arg(v) for v in args.always_will},
1077976
"always_do": {_parse_option_arg(v) for v in args.always_do},
1078-
"colormatch": args.colormatch,
1079-
"color_brightness": args.color_brightness,
1080-
"color_contrast": args.color_contrast,
1081-
"background_color": _parse_background_color(args.background_color),
1082-
"ice_colors": args.ice_colors,
1083977
"raw_mode": raw_mode,
1084978
"ascii_eol": args.ascii_eol,
1085979
"ansi_keys": args.ansi_keys,

telnetlib3/client_shell.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -568,17 +568,14 @@ def _transform_output(
568568
out: str, writer: Union[TelnetWriter, TelnetWriterUnicode], in_raw_mode: bool
569569
) -> str:
570570
r"""
571-
Apply color filter, ASCII EOL substitution, and CRLF normalization.
571+
Apply ASCII EOL substitution and CRLF normalization.
572572
573573
:param out: Server output text to transform.
574-
:param writer: Telnet writer (``ctx`` provides color filter and ascii_eol).
574+
:param writer: Telnet writer (``ctx`` provides ascii_eol).
575575
:param in_raw_mode: When ``True``, normalize line endings to ``\r\n``.
576576
:returns: Transformed output string.
577577
"""
578578
ctx: TelnetSessionContext = writer.ctx
579-
cf = ctx.color_filter
580-
if cf is not None:
581-
out = cf.filter(out)
582579
if ctx.ascii_eol:
583580
out = out.replace(_ATASCII_CR_CHAR, "\r").replace(_ATASCII_LF_CHAR, "\n")
584581
if in_raw_mode:
@@ -634,16 +631,6 @@ def _get_raw_mode(writer: Union[TelnetWriter, TelnetWriterUnicode]) -> "bool | N
634631
"""Return the writer's ``ctx.raw_mode`` (``None``, ``True``, or ``False``)."""
635632
return writer.ctx.raw_mode
636633

637-
def _flush_color_filter(
638-
writer: Union[TelnetWriter, TelnetWriterUnicode], stdout: asyncio.StreamWriter
639-
) -> None:
640-
"""Flush any pending color filter output to stdout."""
641-
cf = writer.ctx.color_filter
642-
if cf is not None:
643-
flush = cf.flush()
644-
if flush:
645-
stdout.write(flush.encode())
646-
647634
def _ensure_autoreply_engine(
648635
telnet_writer: Union[TelnetWriter, TelnetWriterUnicode],
649636
) -> "Optional[Any]":
@@ -856,7 +843,6 @@ async def _wait_for_prompt_raw() -> None:
856843
stdout.write(f"Escape character is '{escape_name}'.{banner_sep}".encode())
857844

858845
def _handle_close(msg: str) -> None:
859-
_flush_color_filter(telnet_writer, stdout)
860846
stdout.write(f"\033[m{linesep}{msg}{linesep}".encode())
861847
tty_shell.cleanup_winch()
862848

0 commit comments

Comments
 (0)