diff --git a/cecli/tui/app.py b/cecli/tui/app.py index 464726a61c1..fc87bd7211b 100644 --- a/cecli/tui/app.py +++ b/cecli/tui/app.py @@ -2,6 +2,7 @@ import concurrent.futures import json +import platform import queue import time from functools import lru_cache @@ -359,6 +360,11 @@ def on_mouse_up(self, event: events.MouseUp) -> None: self._mouse_hold_timer = None self.update_key_hints(generating=self._currently_generating) + def on_mouse_move(self, event: events.MouseMove) -> None: + """Handle mouse move events to prevent strange characters on Windows.""" + if platform.system() == "Windows": + event.stop() + def _show_select_hint(self) -> None: """Show the shift+drag to select hint.""" try: diff --git a/tests/tui/test_app.py b/tests/tui/test_app.py new file mode 100644 index 00000000000..e6244d87cf2 --- /dev/null +++ b/tests/tui/test_app.py @@ -0,0 +1,37 @@ +from unittest.mock import MagicMock, patch + +import pytest +from textual import events + +# Assuming TUI is in cecli.tui.app +from cecli.tui.app import TUI + + +@pytest.fixture +def tui_instance(monkeypatch): + """A pytest fixture to create a mocked TUI instance.""" + monkeypatch.setattr("cecli.tui.app.TUI.__init__", lambda *args, **kwargs: None) + tui = TUI(coder_worker=None, output_queue=None, input_queue=None, args=None) + tui._mouse_hold_timer = None + tui._currently_generating = False + return tui + + +def test_on_mouse_move_windows(tui_instance): + """ + Test that on_mouse_move stops the event on Windows. + """ + with patch("platform.system", return_value="Windows"): + mock_event = MagicMock(spec=events.MouseMove) + tui_instance.on_mouse_move(mock_event) + mock_event.stop.assert_called_once() + + +def test_on_mouse_move_linux(tui_instance): + """ + Test that on_mouse_move does not stop the event on Linux. + """ + with patch("platform.system", return_value="Linux"): + mock_event = MagicMock(spec=events.MouseMove) + tui_instance.on_mouse_move(mock_event) + mock_event.stop.assert_not_called()