mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Formatting, tidying up, add extra mouse event parsing test
This commit is contained in:
committed by
Will McGugan
parent
129d5a57ea
commit
60262d2617
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from collections import deque
|
|
||||||
from typing import Any, Callable, Generator, Iterable
|
from typing import Any, Callable, Generator, Iterable
|
||||||
|
|
||||||
from . import messages
|
from . import messages
|
||||||
@@ -36,11 +35,11 @@ class XTermParser(Parser[events.Event]):
|
|||||||
self.last_x = 0
|
self.last_x = 0
|
||||||
self.last_y = 0
|
self.last_y = 0
|
||||||
|
|
||||||
self._debug_log_file = open("keys.log", "wt")
|
self._debug_log_file = open("keys.log", "wt") if debug else None
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def debug_log(self, *args: Any) -> None:
|
def debug_log(self, *args: Any) -> None: # pragma: no cover
|
||||||
if self._debug_log_file is not None:
|
if self._debug_log_file is not None:
|
||||||
self._debug_log_file.write(" ".join(args) + "\n")
|
self._debug_log_file.write(" ".join(args) + "\n")
|
||||||
self._debug_log_file.flush()
|
self._debug_log_file.flush()
|
||||||
@@ -187,12 +186,13 @@ class XTermParser(Parser[events.Event]):
|
|||||||
mouse_match = _re_mouse_event.match(sequence)
|
mouse_match = _re_mouse_event.match(sequence)
|
||||||
if mouse_match is not None:
|
if mouse_match is not None:
|
||||||
mouse_code = mouse_match.group(0)
|
mouse_code = mouse_match.group(0)
|
||||||
print(mouse_code)
|
|
||||||
event = self.parse_mouse_code(mouse_code, self.sender)
|
event = self.parse_mouse_code(mouse_code, self.sender)
|
||||||
if event:
|
if event:
|
||||||
on_token(event)
|
on_token(event)
|
||||||
break
|
break
|
||||||
# Or a mode report? (i.e. the terminal telling us if it supports a mode we requested)
|
|
||||||
|
# Or a mode report?
|
||||||
|
# (i.e. the terminal saying it supports a mode we requested)
|
||||||
mode_report_match = _re_terminal_mode_response.match(sequence)
|
mode_report_match = _re_terminal_mode_response.match(sequence)
|
||||||
if mode_report_match is not None:
|
if mode_report_match is not None:
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -3,8 +3,15 @@ from unittest import mock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from textual._xterm_parser import XTermParser
|
from textual._xterm_parser import XTermParser
|
||||||
from textual.events import Paste, Key, MouseDown, MouseUp, MouseMove, MouseScrollDown, \
|
from textual.events import (
|
||||||
MouseScrollUp
|
Paste,
|
||||||
|
Key,
|
||||||
|
MouseDown,
|
||||||
|
MouseUp,
|
||||||
|
MouseMove,
|
||||||
|
MouseScrollDown,
|
||||||
|
MouseScrollUp,
|
||||||
|
)
|
||||||
from textual.messages import TerminalSupportsSynchronizedOutput
|
from textual.messages import TerminalSupportsSynchronizedOutput
|
||||||
|
|
||||||
|
|
||||||
@@ -207,6 +214,13 @@ def test_mouse_scroll_up(parser, sequence, shift, meta):
|
|||||||
assert event.y == 24
|
assert event.y == 24
|
||||||
|
|
||||||
|
|
||||||
|
def test_mouse_event_detected_but_info_not_parsed(parser):
|
||||||
|
# I don't know if this can actually happen in reality, but
|
||||||
|
# there's a branch in the code that allows for the possibility.
|
||||||
|
events = list(parser.feed("\x1b[<65;18;20;25M"))
|
||||||
|
assert len(events) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_escape_sequence_resulting_in_multiple_keypresses(parser):
|
def test_escape_sequence_resulting_in_multiple_keypresses(parser):
|
||||||
"""Some sequences are interpreted as more than 1 keypress"""
|
"""Some sequences are interpreted as more than 1 keypress"""
|
||||||
events = list(parser.feed("\x1b[2;4~"))
|
events = list(parser.feed("\x1b[2;4~"))
|
||||||
|
|||||||
Reference in New Issue
Block a user