Skip to content

Commit afd5dd1

Browse files
committed
do not probe_xtgettcap()
1 parent 2d5ad2c commit afd5dd1

4 files changed

Lines changed: 26 additions & 22 deletions

File tree

gambaterm/keyboard_input.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def is_kitty_keyboard_protocol_supported(
152152
return False
153153
with term.enable_kitty_keyboard(report_events=True, timeout=timeout):
154154
active = term.get_kitty_keyboard_state(timeout=timeout)
155-
if active is not None:
156-
if active.report_events:
157-
return True
158155
return active is not None and active.report_events
159156

160157

gambaterm/remote_terminal.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,23 @@ def __init__(
4545
self._keyboard_decoder = codecs.getincrementaldecoder("UTF-8")()
4646

4747
def probe_xtgettcap(self, timeout: float = 1.0) -> None:
48-
"""Probe terminal capabilities via XTGETTCAP and apply results.
48+
"""
49+
Probe terminal capabilities via XTGETTCAP and apply results.
50+
51+
This allows to improved 'number_of_colors' detection, and, to "overlay" capabilities not
52+
found in jinxed terminfo database but detected by XTGETTCAP: 'blink', 'sitm', 'ritm',
53+
'cvvis', 'Smulx', 'Setulc', 'Ms', the same way that blessed.Terminal() would have but we
54+
is_a_tty was detected False when we initialized it.
4955
50-
Must be called after the remote connection is established and after kitty keyboard detection
51-
to prevent interference. Uses ``force=True`` because blessed thought we were not a terminal
52-
when first initialized.
56+
This method is not called or used by gambaterm-ssh or gambaterm-telnet, because the above
57+
capabilities are not used and kitty keyboard support pretty reliably suggests 24-bit color
58+
support. It is just here as a suggestion, and can be safely deleted.
5359
"""
5460
self._xtgettcap_cache = self._Terminal__init__xtgettcap() # type: ignore[assignment]
5561
self.number_of_colors = self._Terminal__init__color_capabilities() # type: ignore[assignment]
62+
if self._xtgettcap_cache.supported and self.does_styling:
63+
self._jinxed_term.overlay_capabilities(
64+
**self._xtgettcap_cache.make_jinxed_capabilities())
5665

5766
@contextlib.contextmanager
5867
def raw(self) -> Generator[None, None, None]:

gambaterm/ssh.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ def ssh_terminal_handler(
208208
else:
209209
assert False
210210

211-
# Probe XTGETTCAP which helps correct terminal.number_of_colors using 'RGB' and 'colors'
212-
terminal.probe_xtgettcap(timeout=1.0)
211+
# It is possible, here, to probe XTGETTCAP which helps correct terminal.number_of_colors using
212+
# 'RGB' and 'colors', and some special attributes like blink, underline et al., but since they
213+
# are not used by gambaterm, it is not called unless we find better reason otherwise.
214+
#terminal.probe_xtgettcap(timeout=1.0)
213215

214-
color_mode = app_config.color_mode or detect_local_color_mode(terminal)
215-
if color_mode == ColorMode.COULD_NOT_DETECT:
216-
color_mode = ColorMode.HAS_8_BIT_COLOR
216+
# In practice kitty keyboard protocol pretty well implies 24-bit color support already,
217+
color_mode = app_config.color_mode or ColorMode.HAS_24_BIT_COLOR
217218

218219
print(
219220
f"[Terminal Info] {username}: {terminal_type}, {input_source}, {terminal.width}x{terminal.height}"

gambaterm/telnet.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,13 @@ def thread_target(
7575
print(f"< User `{username}` did not support keyboard protocol")
7676
return 1
7777

78-
# Probe XTGETTCAP which helps correct terminal.number_of_colors using 'RGB' and 'colors', though
79-
# gnu and bsd telnet clients are pretty good about forwarding TERM and COLORTERM, this provides
80-
# some small forward compatibility when they decide to withdraw forward of either of them as ssh
81-
# does, gnu telnet dangerously forwards **any** environment variable requested by server (!)
82-
terminal.probe_xtgettcap(timeout=1.0)
83-
84-
# Detect terminal color capabilities (augmented by XTGETTCAP probe)
85-
color_mode = app_config.color_mode or detect_local_color_mode(terminal)
86-
if color_mode == ColorMode.COULD_NOT_DETECT:
87-
color_mode = ColorMode.HAS_8_BIT_COLOR
78+
# It is possible, here, to probe XTGETTCAP which helps correct terminal.number_of_colors using
79+
# 'RGB' and 'colors', and some special attributes like blink, underline et al., but since they
80+
# are not used by gambaterm, it is not called unless we find better reason otherwise.
81+
#terminal.probe_xtgettcap(timeout=1.0)
82+
83+
# In practice kitty keyboard protocol pretty well implies 24-bit color support already,
84+
color_mode = app_config.color_mode or ColorMode.HAS_24_BIT_COLOR
8885

8986
try:
9087
terminal.stream.write(

0 commit comments

Comments
 (0)