The sequence "1049" in set mode is an alias for "1048" and "1047" and
should be clear the alt buffer when going to the normal buffer on that
scenario. This was causing "junk" to remain on the alt-buffer because
it was not being cleared for certain TERM definitions (on the iOS
client I was setting TERM to xterm-256color, while on the Mac I was
using xterm-color, so it looked like an iOS bug, but it was a general
emulation bug).
The second problem is that I missunderstood how "OptionSet.remove" works,
the operation itself is mutating, so
style.remove (.underline)
Would be enough to remove the .underline from the optionset, but instead,
I was doing:
style = style.remove (.underline)
And this operation instead return the intersection of the existing value
and the passed value, meaning that I was never clearing the state when
precise commands were used, only when a full reset was issued (which was
the case with xterm-color)
The source of truth is now Terminal.foregroundColor and
Terminal.backgroundColor, which are in turn initialized from the
defaults in Colors.
Setting these will trigger an event that the UIs can catch and can
adjust their own colors.
But it is possible that someone wants a high-fidelity color, tied to a
particular color space, so to surface this, both the AppKit and UIKit
views surface a `nativeForegroundColor` and `nativeBackgroundColor`
that can take the native UIColor/NSColor and will set the underlying
terminal color in turn.