|
| 1 | +import sys |
1 | 2 | from typing import TYPE_CHECKING, FrozenSet
|
2 | 3 |
|
3 | 4 | from prompt_toolkit.data_structures import Point
|
|
9 | 10 | MouseEventType,
|
10 | 11 | MouseModifier,
|
11 | 12 | )
|
12 |
| -from prompt_toolkit.utils import is_windows |
13 | 13 |
|
14 | 14 | from ..key_bindings import KeyBindings
|
15 | 15 |
|
@@ -303,41 +303,42 @@ def _mouse(event: E) -> "NotImplementedOrNone":
|
303 | 303 | """
|
304 | 304 | Handling of mouse events for Windows.
|
305 | 305 | """
|
306 |
| - assert is_windows() # This key binding should only exist for Windows. |
307 |
| - |
308 |
| - # Parse data. |
309 |
| - pieces = event.data.split(";") |
310 |
| - |
311 |
| - button = MouseButton(pieces[0]) |
312 |
| - event_type = MouseEventType(pieces[1]) |
313 |
| - x = int(pieces[2]) |
314 |
| - y = int(pieces[3]) |
315 |
| - |
316 |
| - # Make coordinates absolute to the visible part of the terminal. |
317 |
| - output = event.app.renderer.output |
318 |
| - |
319 |
| - from prompt_toolkit.output.win32 import Win32Output |
320 |
| - from prompt_toolkit.output.windows10 import Windows10_Output |
321 |
| - |
322 |
| - if isinstance(output, (Win32Output, Windows10_Output)): |
323 |
| - screen_buffer_info = output.get_win32_screen_buffer_info() |
324 |
| - rows_above_cursor = ( |
325 |
| - screen_buffer_info.dwCursorPosition.Y - event.app.renderer._cursor_pos.y |
326 |
| - ) |
327 |
| - y -= rows_above_cursor |
328 |
| - |
329 |
| - # Call the mouse event handler. |
330 |
| - # (Can return `NotImplemented`.) |
331 |
| - handler = event.app.renderer.mouse_handlers.mouse_handlers[y][x] |
332 |
| - |
333 |
| - return handler( |
334 |
| - MouseEvent( |
335 |
| - position=Point(x=x, y=y), |
336 |
| - event_type=event_type, |
337 |
| - button=button, |
338 |
| - modifiers=UNKNOWN_MODIFIER, |
| 306 | + # This key binding should only exist for Windows. |
| 307 | + if sys.platform == "win32": |
| 308 | + # Parse data. |
| 309 | + pieces = event.data.split(";") |
| 310 | + |
| 311 | + button = MouseButton(pieces[0]) |
| 312 | + event_type = MouseEventType(pieces[1]) |
| 313 | + x = int(pieces[2]) |
| 314 | + y = int(pieces[3]) |
| 315 | + |
| 316 | + # Make coordinates absolute to the visible part of the terminal. |
| 317 | + output = event.app.renderer.output |
| 318 | + |
| 319 | + from prompt_toolkit.output.win32 import Win32Output |
| 320 | + from prompt_toolkit.output.windows10 import Windows10_Output |
| 321 | + |
| 322 | + if isinstance(output, (Win32Output, Windows10_Output)): |
| 323 | + screen_buffer_info = output.get_win32_screen_buffer_info() |
| 324 | + rows_above_cursor = ( |
| 325 | + screen_buffer_info.dwCursorPosition.Y |
| 326 | + - event.app.renderer._cursor_pos.y |
| 327 | + ) |
| 328 | + y -= rows_above_cursor |
| 329 | + |
| 330 | + # Call the mouse event handler. |
| 331 | + # (Can return `NotImplemented`.) |
| 332 | + handler = event.app.renderer.mouse_handlers.mouse_handlers[y][x] |
| 333 | + |
| 334 | + return handler( |
| 335 | + MouseEvent( |
| 336 | + position=Point(x=x, y=y), |
| 337 | + event_type=event_type, |
| 338 | + button=button, |
| 339 | + modifiers=UNKNOWN_MODIFIER, |
| 340 | + ) |
339 | 341 | )
|
340 |
| - ) |
341 | 342 |
|
342 | 343 | # No mouse handler found. Return `NotImplemented` so that we don't
|
343 | 344 | # invalidate the UI.
|
|
0 commit comments