Skip to content

Commit

Permalink
term: adjust logical line wrapping behavior
Browse files Browse the repository at this point in the history
Really, this is adjusting the logical line breaking behavior, or the
lack thereof.

The situation is this: conpty can decided to reinterpret and flush
large sections of its buffer as a continuous stream of unbroken
characters with no breaks when it repaints the full screen.

When we receive such an update, we see it as one long logical line,
and when we subsequently select multiple lines we can run into the
maximum logical line length and insert invalid synthetic line breaks
into the data that we send to the clipboard.

This commit adjusts the wrapping logic at the time that we receive
the text so that we don't tag the line as a logical line continuation
if:

* The alt screen is active. Full screen apps will re-render on resize
  anyway, and we don't reflow long lines on resize either for the same
  reasons

* If we are talking to ConPTY:
     * If the last character in the line is not alphanumeric or
       punctuation (in other words: it doesn't look plausibly like
       text that should be a line continuation).

refs: #3278
refs: #3177
  • Loading branch information
wez committed Mar 23, 2023
1 parent 1a32908 commit dc36fe1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ As features stabilize some brief notes about them will accumulate here.
* Using `RESIZE|MACOS_FORCE_DISABLE_SHADOW` or
`RESIZE|MACOS_FORCE_ENABLE_SHADOW` would cause a spooky titlebar to appear.
Thanks to @noefroidevaux! #3330
* ConPTY: logical line wrapping falsely joining long runs of output from classic
windows console subsystem programs. The behavior now is to only mark long lines
as wrapped if the last character on the prior line is alphanumeric or ascii
punctuation. Other characters will cause the logical line to break.
#3278 #3177

### 20230320-124340-559cb7b0

Expand Down
25 changes: 24 additions & 1 deletion term/src/terminalstate/performer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,32 @@ impl<'a> Performer<'a> {
// resized.
{
let y = self.cursor.y;
let is_conpty = self.state.enable_conpty_quirks;
let is_alt = self.state.screen.alt_screen_is_active;
let screen = self.screen_mut();
let y = screen.phys_row(y);
screen.line_mut(y).set_last_cell_was_wrapped(true, seqno);

fn makes_sense_to_wrap(s: &str) -> bool {
let len = s.len();
match (len, s.chars().next()) {
(1, Some(c)) => {
c.is_alphanumeric() || c.is_ascii_punctuation()
}
_ => true
}
}

let should_mark_wrapped = !is_alt
&& (!is_conpty
|| screen
.line_mut(y)
.visible_cells()
.last()
.map(|cell| makes_sense_to_wrap(cell.str()))
.unwrap_or(false));
if should_mark_wrapped {
screen.line_mut(y).set_last_cell_was_wrapped(true, seqno);
}
}
self.new_line(true);
}
Expand Down

0 comments on commit dc36fe1

Please sign in to comment.