1717from .input_getter import BaseInputGetter
1818from .colors import ColorMode
1919from .graphics_scaler import GraphicsScaler , AutoScale , AutoScaleConfig , _SCALE_CEILING
20- from .remote_terminal import GraphicsProtocol
20+ from .remote_terminal import GraphicsProtocol , _BAD_TEXT
21+
22+ # Terminals needing full frames every frame (no dirty-rect / overlay deltas).
23+ _FORCE_KITTY_BLITLESS = ("rio" , "ghostty" )
2124
2225
2326@contextlib .contextmanager
@@ -35,21 +38,6 @@ def get_ref(width: int, height: int, console: Console) -> tuple[int, int]:
3538 return refx , refy
3639
3740
38- # Terminals with corrupted unicode font rendering — always prefer graphics.
39- _BAD_TEXT = ("rio" , "mlterm" )
40- # Terminals needing full frames every frame (no dirty-rect / overlay deltas).
41- _FORCE_KITTY_BLITLESS = ("rio" , "ghostty" )
42-
43-
44- def _is_mlterm (term : Terminal ) -> bool :
45- """Return True if the terminal is mlterm (loses sixel on focus-out)."""
46- try :
47- sv = term .get_software_version (timeout = 0.25 )
48- return sv is not None and "mlterm" in sv .name .lower ()
49- except Exception :
50- return False
51-
52-
5341def write_frame (term : Terminal , frame_data : bytes ) -> None :
5442 # Fix code page issue on windows:
5543 # `sys.stdout.buffer.raw` is a `WindowsConsoleIO` that always support UTF-8
@@ -180,7 +168,7 @@ def run(
180168 cycle = [
181169 p
182170 for p in graphics_cycle
183- if p is not GraphicsProtocol .TEXT or terminal_name not in _BAD_TEXT
171+ if p is not GraphicsProtocol .TEXT or not terminal_name . startswith ( _BAD_TEXT )
184172 ]
185173 if cycle :
186174 idx = cycle .index (graphics_protocol )
@@ -192,7 +180,7 @@ def run(
192180 average_over = int (round (fps )) # frames
193181 audio_out .update_speed (console , speed )
194182 elif key .key_name in ("FOCUS_IN" , "FOCUS_OUT" ):
195- if graphics_protocol is GraphicsProtocol .SIXEL and _is_mlterm ( term ):
183+ if graphics_protocol is GraphicsProtocol .SIXEL and terminal_name . startswith ( "mlterm" ):
196184 if scaler is not None :
197185 scaler ._sixel_baseline = None
198186 elif key .key_name in ("KEY_GRAVE_ACCENT" , "KEY_TILDE" ) or key in ("`" , "~" ):
@@ -229,7 +217,7 @@ def run(
229217 if (
230218 new_width >= console .WIDTH
231219 and new_height >= console .HEIGHT // 2
232- and not terminal_name .startswith (( "rio" , "mlterm" ) )
220+ and not terminal_name .startswith (_BAD_TEXT )
233221 ):
234222 new_graphics_protocol = GraphicsProtocol .TEXT
235223 changed = True
@@ -242,7 +230,7 @@ def run(
242230 if (
243231 text_fits
244232 and graphics_protocol is not GraphicsProtocol .TEXT
245- and terminal_name not in _BAD_TEXT
233+ and not terminal_name . startswith ( _BAD_TEXT )
246234 ):
247235 new_graphics_protocol = GraphicsProtocol .TEXT
248236 elif (
@@ -285,6 +273,8 @@ def run(
285273 graphics_protocol = new_graphics_protocol
286274 term .number_of_colors = new_color_mode .number_of_colors
287275 last_frame .fill (0 )
276+ if scaler is not None :
277+ scaler .close ()
288278 scaler = None
289279 force_status_update = True
290280
@@ -329,9 +319,9 @@ def run(
329319 frame_data += scaler .blit_sixel_blitless (video , width , height )
330320 else :
331321 frame_data += scaler .blit_kitty (
332- video , last_frame , width , height , color_mode
322+ video , last_frame , width , height
333323 )
334- if terminal_name in _FORCE_KITTY_BLITLESS :
324+ if terminal_name . startswith ( _FORCE_KITTY_BLITLESS ) :
335325 scaler ._baseline = None
336326 if sync_end :
337327 frame_data += sync_end
@@ -351,6 +341,8 @@ def run(
351341 if data_length and auto_scale is not None and autoscale is not None :
352342 data_rate_kb_s = sum (data_length ) / len (data_length ) * fps / 1000
353343 if auto_scale .feed_bandwidth (data_rate_kb_s , autoscale .bandwidth_mbits ):
344+ if scaler is not None :
345+ scaler .close ()
354346 scaler = GraphicsScaler .recompute (
355347 term ,
356348 console ,
@@ -404,6 +396,8 @@ def run(
404396 and graphics_protocol is GraphicsProtocol .KITTY
405397 ):
406398 kitty_pending_delete = True
399+ if scaler is not None :
400+ scaler .close ()
407401 scaler = GraphicsScaler .recompute (
408402 term ,
409403 console ,
0 commit comments