3333 is_kitty_keyboard_protocol_supported ,
3434)
3535from .remote_terminal import RemoteTerminal
36- from .telnet_app_session import (
37- telnet_to_terminal ,
38- )
36+ from .telnet_app_session import telnet_to_terminal
3937
4038
4139def _save_dir_name (username : str | None ) -> str :
@@ -53,7 +51,6 @@ def thread_target(
5351 terminal : RemoteTerminal ,
5452 console_callback : Callable [[], Console ],
5553 app_config : AppConfig ,
56- color_mode : ColorMode ,
5754 username : str | None ,
5855) -> int :
5956 """Run the emulator in a thread with the given RemoteTerminal."""
@@ -76,6 +73,14 @@ def thread_target(
7673 print (f"< User `{ username } ` did not support keyboard protocol" )
7774 return 1
7875
76+ # It is possible, here, to probe XTGETTCAP which helps correct terminal.number_of_colors using
77+ # 'RGB' and 'colors', and some special attributes like blink, underline et al., but since they
78+ # are not used by gambaterm, it is not called unless we find better reason otherwise.
79+ # terminal.probe_xtgettcap(timeout=1.0)
80+
81+ # In practice kitty keyboard protocol pretty well implies 24-bit color support already,
82+ color_mode = app_config .color_mode or ColorMode .HAS_24_BIT_COLOR
83+
7984 try :
8085 terminal .stream .write (
8186 terminal .enter_fullscreen + terminal .clear + terminal .hide_cursor
@@ -90,6 +95,7 @@ def thread_target(
9095 color_mode = color_mode ,
9196 break_after = app_config .break_after ,
9297 speed = app_config .speed ,
98+ use_cpr_sync = app_config .cpr_sync ,
9399 )
94100 except (KeyboardInterrupt , EOFError ):
95101 return 0
@@ -244,20 +250,13 @@ async def _telnet_shell(
244250 except (asyncio .TimeoutError , KeyError ):
245251 pass
246252
247- terminal_type = writer .get_extra_info ("TERM" ) or "unknown"
253+ terminal_type = writer .get_extra_info ("TERM" ) or None
248254 username = writer .get_extra_info ("USER" ) or None
249255 print (
250- f"> Telnet client connected ({ peer_host } :{ peer_port } )"
256+ f"> Telnet client connected ({ peer_host } :{ peer_port } term= { terminal_type } )"
251257 + (f" user={ username } " if username else "" )
252258 )
253259
254- if terminal_type == "unknown" :
255- print ("Warning: terminal type not negotiated, assuming xterm-256color." )
256- terminal_type = "xterm-256color"
257-
258- # Kitty keyboard protocol implies 24-bit color support
259- color_mode = app_config .color_mode or ColorMode .HAS_24_BIT_COLOR
260-
261260 if idle_timeout is not None :
262261 stats_task = asyncio .create_task (
263262 _log_connection_stats (reader , writer , peer_host , peer_port , idle_timeout )
@@ -267,10 +266,7 @@ async def _telnet_shell(
267266
268267 cols = writer .get_extra_info ("cols" ) or 80
269268 rows = writer .get_extra_info ("rows" ) or 24
270- print (
271- f"[Terminal Info] { peer_host } : { terminal_type } , "
272- f"{ color_mode .name } , { cols } x{ rows } "
273- )
269+ print (f"[Terminal Info] { peer_host } : ttype={ terminal_type } , { cols } x{ rows } " )
274270
275271 try :
276272 # Copy namespace and set telnet-specific save directory
@@ -289,13 +285,14 @@ async def _telnet_shell(
289285 config = AppConfig (** vars (namespace ))
290286
291287 def target (term : RemoteTerminal ) -> int :
292- return thread_target (term , console_callback , config , color_mode , username )
288+ return thread_target (term , console_callback , config , username )
293289
294290 return await telnet_to_terminal (
295291 reader ,
296292 writer ,
297293 executor ,
298294 target ,
295+ terminal_type = terminal_type ,
299296 )
300297 finally :
301298 if stats_task is not None :
0 commit comments