Description
Description of the new feature
This is a followup to #18732, which is locked. The request there is to have an option to preserve the current line in clearBuffer
.
I don't have VS installed, so I can't play with the code, but I think that adding something like the below case to ControlCore::ClearBuffer
should be very close to implementing this.
[It will fail in case of editing multi-line inputs, but as I described in the other issue, this is still hugely useful as a default over the current always-remove-everything option. The one thing that bothers me more about this is that it uses the beginning of the current physical line rather than the logical line. If there's a way to get that information, it would be much better.]
Proposed technical implementation details
Disclaimer: mostly made-up code based on what I see in the file. Also assumes that there's a .x
and .y
fields, and that they're 0-based.
case ClearBufferType::AllToCursor:
const til::point pos = _terminal->GetTextBuffer().GetCursor().GetPosition();
if (til.y == 0)
{
// cursor at the top of the screen: just remove the scrollback
command = L"\x1b[3J";
}
else
{
// otherwise: clear scrallback, move to top at the same column, delete rows up to cursor position
command = fmt::format(FMT_COMPILE(L"\x1b[3J\x1b[H\x1b[{}M\x1b[1;{}H"), pos.y, pos.x + 1);
}
break;
For reference, a bash version of this:
clearToCursor() {
# read cursor position
IFS='[;' read -s -d R -p $'\e[6n' -r -u 0 _ ROW COL
if [[ $ROW -eq 1 ]]; then
# on top row => just clear the scrollback
printf '\e[3J'
else
# clear scrollback, goto top, delete ROW-1 lines
printf '\e[3J\e[H\e[%dM\e[1;%dH' $((ROW-1)) $COL
fi
}