nushell/crates/nu-command/src/platform
Douglas eedf833b6f
Send both 2J and 3J on clear (#14181)
Fixes #14176

# Description

Since the Linux `/usr/bin/clear` binary doesn't exhibit the issue in
#14176, I checked to see what ANSI escapes it is emitting:

```nu
nu -c '^clear; "111\n222\n333"' | less
# or
bash -c 'clear -x; echo -e "111\n222\n333"' | less
```

Both show the same thing:

```
ESC[HESC[2JESC[3J111
222
333
(END)
```

This is the equivalent of:

```nu
$"(ansi home)(ansi clear_entire_screen)(ansi clear_entire_screen_plus_buffer)111\n222\n333"
```

However, our internal `clear` is sending only the Home and 3J. While
this *should*, in theory, work, it's (a) clear that it doesn't, and (b)
`/usr/bin/clear` seemingly knows this and already has the solution (or
at least workaround). From looking at the `ncurses` source, it appears
it is getting this information from the terminal capabilities. That
said, support for `2J` and `3J` is fairly universal, and it's what we
send in `clear` and `clear --keep-scrollback` anyway, so there's no harm
AFAICT in sending both like `/usr/bin/clear` does.

Also tested and fixes the issue on Windows. Note that PowerShell
`Clear-Host` also did not have the issue.

Side-note: It's interesting that on Tmux, which doesn't support 2J and
3J, that `/usr/bin/clear` knows this and doesn't send those codes,
sending just an escape-[J instead. However, Nushell's `clear`, of
course, isn't checking terminal capabilities, and is continuing to send
the unsupported codes. Fortunately this doesn't appear to cause any
issues on Tmux.

# User-Facing Changes

None, AFAICT - Bugfix only.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2024-10-28 06:42:18 -05:00
..
ansi Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
input Respect $env.config.use_kitty_protocol in input listen (#13892) 2024-09-25 08:57:00 -05:00
clear.rs Send both 2J and 3J on clear (#14181) 2024-10-28 06:42:18 -05:00
dir_info.rs Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
is_terminal.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
kill.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
mod.rs refactor: move du from platform to filesystem (#11852) 2024-02-15 06:55:21 +08:00
sleep.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
term_size.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
ulimit.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
whoami.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00