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.
The fe80:: is hopeless, try to send ipv4 just in case.
Technically speaking, the user may be using a different address
or real ipv6 and the ipv4 guess might fail, but it probably won't.
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.
RedHat makes grub redundantly handle serial output that firmware
already handles. If we detect EFI firmware and SPCR ACPI table and
connected serial port, that suggests that firmware will handle.
Ubuntu hates serial console by default, amend it so it can actually
work for serial users.