It turns out that specifying height and width explicitly
does not guarantee that the image protocols will actually fill
the specified space. Notably iterm will honor aspect ratio
(which is good), but leave the cursor where the image would
naturally leave it (which is difficult with relative positioning).
Previously, relative positioning was used as a workaround
for the fact that save/restore or any absolute positioning may
be fouled by incurring scroll.
To make cursor save/restore work, we determine the total rows and
print newlines enough to incur scroll and then move cursor back up.
This lets us use save/restore to ignore cursor movement by the image.
When parceling out the screen real estate, avoid either the height
or the width from getting way out of proportion.
Better to let screen be unused than abuse it to distort the
aspect ratio too much.
Only for kitty graphics protocol.
Also, attempt to use pillow to convert, if available. Kitty itself
needs this, Konsole can work either way.
It currently does not preserve aspect ratio, to do that
we pretty much need to do some work with pillow.
If we specify just the height, then ratio is preserved, but it won't
honor the designed bounding box on wide screenshots. Also
Konsole won't even honor just one scaling factor.
So the better thing would be to determine the aspect ratio, which
needs pillow.
This directs CLI with image output to use a preferred protocol.
This is retroactively applied to stats.
Currently we prefer kitty, as it seems to be the most widely supported.
Though some things only support iterm, so that's an option.
And some only support sixel, but the user has to be the one to
figure out adding pysixel dependency.
On exit, clear the terminal buffer and invalidate the session. This
avoids the web ui being very attached to a closed, dead session, and
leaking stale buffer to a reused sessionid.
For confetty, treat starting a shell session more like starting a
console session.
If an attempt to resize a dead session is attempted,
ignore failures.
If the power state stays the same between queries, take no action to clear screen and
draw redundant data.
In the case of misreporting devices, it mitigates the impact of incorrect reporting,
while generally preserving the output behavior when accurate.
The change to tolerate either a space or no space ended up
greedily consuming whitespace. Do best possible in two cases:
For log, use the first line as a clue, and consistently pad or not pad
according to first line. It won't catch different pad strategies, or
handle first line being indented but other lines not being indented.
For the textgroup variant, allow subsequent lines to revise the
pad downward, and accept any whitespace, not just space.
For one, when using confluent expressions, induce {} to be an error to
trigger an error for someone trying to xargs something.
Another is to add warnings when clear does something deliberately, but
is something that might surprise a user, steering them toward
what they possibly might want to do instead.