Incremental parsing?
It would be nice if I could create some sort of instance of a parser that would incrementally parse input with ANSI escape sequences as I feed it (from an I/O stream)? This means that it would have to allow a possibility of an unfinished escape sequence being fed to the parser and the parser would not decode it until another feed call feeds it in full. Terminal output is continuous so for long-running programs, it's not necessarily easy to figure out when it's safe to parse the text and you sometimes may want to modify and then propagate this output further, without much delay.
I believe that the built-in codecs.IncrementalDecoder is one example of such parsing/decoding in case this helps.
That's a nice idea and it fits the overall goal of the package. Would you like to do a PR on that?
I don't really know how I would have to approach writing this if I'm being honest and I don't currently have time to dedicate to this. Maybe one day if this isn't picked by you or someone else first but for now I just wanted to make an issue to see if you agree that this could be a good idea.
That's fine. I believe the key to implementing this is to understand this method:
https://github.com/getcuia/stransi/blob/ea603eee473bdf521d1976fc88bcf4959f8a774f/src/stransi/ansi.py#L33-L42
The thing is that isescape(match) (line 39) should return false for incomplete or badly-formed escapes.
There could be some kind of AnsiStream object that would generalize this, delivering things in chunks as they come in, as suggested. Ansi could be reimplemented as a special case of this.