Skip to content

Commit 993bb78

Browse files
committed
inline improvements
1 parent 6008c6d commit 993bb78

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/textual/_compositor.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ def __rich_repr__(self) -> rich.repr.Result:
148148
class InlineUpdate(CompositorUpdate):
149149
"""A renderable to write an inline update."""
150150

151-
def __init__(self, strips: list[Strip]) -> None:
151+
def __init__(self, strips: list[Strip], clear: bool = False) -> None:
152152
self.strips = strips
153+
self.clear = clear
153154

154155
def __rich_console__(
155156
self, console: Console, options: ConsoleOptions
@@ -175,14 +176,15 @@ def render_segments(self, console: Console) -> str:
175176
append(strip.render(console))
176177
if not last:
177178
append("\n")
178-
append("\n\x1b[J") # Clear down
179+
if self.clear:
180+
append("\n\x1b[J") # Clear down
179181
if len(self.strips) > 1:
180-
append(
181-
f"\x1b[{len(self.strips)}A\r"
182-
) # Move cursor back to original position
182+
back_lines = len(self.strips) if self.clear else len(self.strips) - 1
183+
append(f"\x1b[{back_lines}A\r") # Move cursor back to original position
183184
else:
184185
append("\r")
185186
append("\x1b[6n") # Query new cursor position
187+
186188
return "".join(sequences)
187189

188190

@@ -336,6 +338,9 @@ def __init__(self) -> None:
336338
# Mapping of line numbers on to lists of widget and regions
337339
self._layers_visible: list[list[tuple[Widget, Region, Region]]] | None = None
338340

341+
# Size of previous inline update
342+
self._previous_inline_height: int | None = None
343+
339344
@classmethod
340345
def _regions_to_spans(
341346
cls, regions: Iterable[Region]
@@ -1030,7 +1035,15 @@ def render_inline(
10301035
A renderable.
10311036
"""
10321037
visible_screen_stack.set([] if screen_stack is None else screen_stack)
1033-
return InlineUpdate(self.render_strips(size))
1038+
strips = self.render_strips(size)
1039+
clear = (
1040+
self._previous_inline_height is not None
1041+
and len(strips) < self._previous_inline_height
1042+
)
1043+
try:
1044+
return InlineUpdate(strips, clear=clear)
1045+
finally:
1046+
self._previous_inline_height = len(strips)
10341047

10351048
def render_full_update(self) -> LayoutUpdate:
10361049
"""Render a full update.

src/textual/drivers/linux_inline_driver.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ def on_terminal_resize(signum, stack) -> None:
207207
self._key_thread = Thread(target=self._run_input_thread)
208208
send_size_event()
209209
self._key_thread.start()
210+
self._request_terminal_sync_mode_support()
211+
self._enable_bracketed_paste()
212+
213+
def _request_terminal_sync_mode_support(self) -> None:
214+
"""Writes an escape sequence to query the terminal support for the sync protocol."""
215+
# Terminals should ignore this sequence if not supported.
216+
# Apple terminal doesn't, and writes a single 'p' in to the terminal,
217+
# so we will make a special case for Apple terminal (which doesn't support sync anyway).
218+
if os.environ.get("TERM_PROGRAM", "") != "Apple_Terminal":
219+
self.write("\033[?2026$p")
220+
self.flush()
210221

211222
@classmethod
212223
def _patch_lflag(cls, attrs: int) -> int:

src/textual/screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def _get_inline_height(self, size: Size) -> int:
893893
inline_height = max(inline_height, int(min_height.resolve(size, size)))
894894
if max_height is not None:
895895
inline_height = min(inline_height, int(max_height.resolve(size, size)))
896-
inline_height = min(self.app.size.height - 1, inline_height)
896+
inline_height = min(self.app.size.height, inline_height)
897897
return inline_height
898898

899899
def _screen_resized(self, size: Size):

0 commit comments

Comments
 (0)