Fix escape key

This commit is contained in:
Will McGugan
2022-05-20 14:28:03 +01:00
parent edc1e54aed
commit cb1289ff97
6 changed files with 11 additions and 13 deletions

View File

@@ -148,6 +148,9 @@ class BasicApp(App):
def key_x(self):
self.panic(self.tree)
def key_escape(self):
self.app.bell()
def key_t(self):
# Pressing "t" toggles the content of the TweetBody widget, from a long "Lorem ipsum..." to a shorter one.
tweet_body = self.screen.query("TweetBody").first()

View File

@@ -94,12 +94,12 @@ class XTermParser(Parser[events.Event]):
peek_buffer = yield self.peek_buffer()
if not peek_buffer:
# An escape arrived without any following characters
on_token(events.Key(self.sender, key=ESC))
on_token(events.Key(self.sender, key="escape"))
continue
if peek_buffer and peek_buffer[0] == ESC:
# There is an escape in the buffer, so ESC ESC has arrived
yield read1()
on_token(events.Key(self.sender, key=ESC))
on_token(events.Key(self.sender, key="escape"))
# If there is no further data, it is not part of a sequence,
# So we don't need to go in to the loop
if len(peek_buffer) == 1 and not more_data():

View File

@@ -9,7 +9,7 @@ from . import log
from .geometry import Offset, Size
from .message import Message
from ._types import MessageTarget
from .keys import Keys, KEY_BINDINGS
from .keys import Keys, KEY_VALUES
MouseEventT = TypeVar("MouseEventT", bound="MouseEvent")
@@ -208,7 +208,7 @@ class Key(InputEvent):
Returns:
bool: True if the key is printable. False otherwise.
"""
return self.key not in KEY_BINDINGS
return self.key not in KEY_VALUES
@rich.repr.auto

View File

@@ -200,11 +200,4 @@ class Keys(str, Enum):
ShiftControlEnd = ControlShiftEnd
KEY_BINDINGS = Keys._value2member_map_.values()
@dataclass
class Binding:
action: str
description: str
show: bool = False
KEY_VALUES = frozenset(Keys._value2member_map_.values())

View File

@@ -814,6 +814,8 @@ class Widget(DOMNode):
if layout:
self._layout_required = True
if repaint:
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)
self.set_dirty()
self._repaint_required = True
self.check_idle()

View File

@@ -278,7 +278,7 @@ class TextAreaChild(TextWidgetBase, can_focus=True):
self._editor.insert_at_cursor("\n")
elif event.key == "tab":
self._editor.insert_at_cursor("\t")
elif event.key == "\x1b":
elif event.key == "escape":
self.app.focused = None
def on_focus(self, event: events.Focus) -> None: