Hopefully make pty more similar to tested console behavior.
This commit is contained in:
@@ -356,32 +356,37 @@ class ScreenManager:
|
||||
# Not typing - handle as line-by-line content change
|
||||
# This catches: incoming messages, screen updates,
|
||||
# application output, etc.
|
||||
appended_text = self._get_recent_cursor_line_append()
|
||||
if appended_text is not None:
|
||||
diff_list = ["+ " + appended_text]
|
||||
typing = True
|
||||
else:
|
||||
|
||||
# Pre-process screen text for comparison - collapse multiple spaces to single space
|
||||
# This normalization prevents spurious diffs from spacing
|
||||
# inconsistencies
|
||||
old_screen_text = self._space_normalize_regex.sub(
|
||||
" ",
|
||||
self.env["runtime"][
|
||||
"ScreenManager"
|
||||
].get_window_area_in_text(
|
||||
self.env["screen"]["old_content_text"]
|
||||
),
|
||||
)
|
||||
new_screen_text = self._space_normalize_regex.sub(
|
||||
" ",
|
||||
self.env["runtime"][
|
||||
"ScreenManager"
|
||||
].get_window_area_in_text(
|
||||
self.env["screen"]["new_content_text"]
|
||||
),
|
||||
)
|
||||
# Pre-process screen text for comparison - collapse multiple spaces to single space
|
||||
# This normalization prevents spurious diffs from spacing
|
||||
# inconsistencies
|
||||
old_screen_text = self._space_normalize_regex.sub(
|
||||
" ",
|
||||
self.env["runtime"][
|
||||
"ScreenManager"
|
||||
].get_window_area_in_text(
|
||||
self.env["screen"]["old_content_text"]
|
||||
),
|
||||
)
|
||||
new_screen_text = self._space_normalize_regex.sub(
|
||||
" ",
|
||||
self.env["runtime"][
|
||||
"ScreenManager"
|
||||
].get_window_area_in_text(
|
||||
self.env["screen"]["new_content_text"]
|
||||
),
|
||||
)
|
||||
|
||||
diff = self.differ.compare(
|
||||
old_screen_text.split("\n"),
|
||||
new_screen_text.split("\n"),
|
||||
)
|
||||
diff_list = list(diff)
|
||||
diff = self.differ.compare(
|
||||
old_screen_text.split("\n"),
|
||||
new_screen_text.split("\n"),
|
||||
)
|
||||
diff_list = list(diff)
|
||||
|
||||
# Extract added and removed content from diff results
|
||||
# Output format depends on whether this was detected as typing
|
||||
@@ -453,6 +458,44 @@ class ScreenManager:
|
||||
)
|
||||
return screen in ignore_screens
|
||||
|
||||
def _get_recent_cursor_line_append(self):
|
||||
try:
|
||||
if time.time() - self.env["runtime"][
|
||||
"InputManager"
|
||||
].get_last_input_time() > 0.3:
|
||||
return None
|
||||
|
||||
old_lines = self.env["screen"]["old_content_text"].split("\n")
|
||||
new_lines = self.env["screen"]["new_content_text"].split("\n")
|
||||
cursor_y = self.env["screen"]["new_cursor"]["y"]
|
||||
if (
|
||||
len(old_lines) != len(new_lines)
|
||||
or cursor_y < 0
|
||||
or cursor_y >= len(new_lines)
|
||||
):
|
||||
return None
|
||||
|
||||
changed_lines = [
|
||||
index
|
||||
for index, old_line in enumerate(old_lines)
|
||||
if index >= len(new_lines) or old_line != new_lines[index]
|
||||
]
|
||||
if changed_lines != [cursor_y]:
|
||||
return None
|
||||
|
||||
old_line = old_lines[cursor_y]
|
||||
new_line = new_lines[cursor_y]
|
||||
old_line = old_line.rstrip()
|
||||
if not new_line.startswith(old_line):
|
||||
return None
|
||||
|
||||
appended_text = new_line[len(old_line):].strip()
|
||||
if appended_text == "" or len(appended_text) > 4:
|
||||
return None
|
||||
return appended_text
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def is_screen_change(self):
|
||||
if not self.env["screen"]["oldTTY"]:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user