diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-04-06 18:18:01 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-04-06 18:18:01 +0300 |
commit | 01fbacb386809436dfa331780875aed72cb76118 (patch) | |
tree | 04c911ad96ff0523bd4d3e7a45c23cf2f2d7607d /contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py | |
parent | 48fb997d7f820a474b9094a72d9798a95ec612b7 (diff) | |
download | ydb-01fbacb386809436dfa331780875aed72cb76118.tar.gz |
intermediate changes
ref:b4f892f3c2b06a356c155f73c27efc5661a7fb89
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py')
-rw-r--r-- | contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py index 949c33f72c2..916cd41132f 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py @@ -1,3 +1,4 @@ +import sys from typing import TYPE_CHECKING, FrozenSet from prompt_toolkit.data_structures import Point @@ -9,7 +10,6 @@ from prompt_toolkit.mouse_events import ( MouseEventType, MouseModifier, ) -from prompt_toolkit.utils import is_windows from ..key_bindings import KeyBindings @@ -202,7 +202,7 @@ def load_mouse_bindings() -> KeyBindings: mouse_event, x, y = map(ord, event.data[3:]) # TODO: Is it possible to add modifiers here? - mouse_button, mouse_event_type, mouse_modifier = typical_mouse_events[ + mouse_button, mouse_event_type, mouse_modifiers = typical_mouse_events[ mouse_event ] @@ -303,41 +303,42 @@ def load_mouse_bindings() -> KeyBindings: """ Handling of mouse events for Windows. """ - assert is_windows() # This key binding should only exist for Windows. - - # Parse data. - pieces = event.data.split(";") - - button = MouseButton(pieces[0]) - event_type = MouseEventType(pieces[1]) - x = int(pieces[2]) - y = int(pieces[3]) - - # Make coordinates absolute to the visible part of the terminal. - output = event.app.renderer.output - - from prompt_toolkit.output.win32 import Win32Output - from prompt_toolkit.output.windows10 import Windows10_Output - - if isinstance(output, (Win32Output, Windows10_Output)): - screen_buffer_info = output.get_win32_screen_buffer_info() - rows_above_cursor = ( - screen_buffer_info.dwCursorPosition.Y - event.app.renderer._cursor_pos.y - ) - y -= rows_above_cursor - - # Call the mouse event handler. - # (Can return `NotImplemented`.) - handler = event.app.renderer.mouse_handlers.mouse_handlers[y][x] - - return handler( - MouseEvent( - position=Point(x=x, y=y), - event_type=event_type, - button=button, - modifiers=UNKNOWN_MODIFIER, + # This key binding should only exist for Windows. + if sys.platform == "win32": + # Parse data. + pieces = event.data.split(";") + + button = MouseButton(pieces[0]) + event_type = MouseEventType(pieces[1]) + x = int(pieces[2]) + y = int(pieces[3]) + + # Make coordinates absolute to the visible part of the terminal. + output = event.app.renderer.output + + from prompt_toolkit.output.win32 import Win32Output + from prompt_toolkit.output.windows10 import Windows10_Output + + if isinstance(output, (Win32Output, Windows10_Output)): + screen_buffer_info = output.get_win32_screen_buffer_info() + rows_above_cursor = ( + screen_buffer_info.dwCursorPosition.Y + - event.app.renderer._cursor_pos.y + ) + y -= rows_above_cursor + + # Call the mouse event handler. + # (Can return `NotImplemented`.) + handler = event.app.renderer.mouse_handlers.mouse_handlers[y][x] + + return handler( + MouseEvent( + position=Point(x=x, y=y), + event_type=event_type, + button=button, + modifiers=UNKNOWN_MODIFIER, + ) ) - ) # No mouse handler found. Return `NotImplemented` so that we don't # invalidate the UI. |