On 5/5/25 9:57 AM, Stéphane Zermatten wrote: > A state machine is indeed the right way of handling terminal escape sequences, and it would be a great idea to refactor term.el to do it that way. I don’t really want to use pattern matching. I’m using it here because it integrates with the current code. > > The current implementation does indeed recognize incomplete escape sequence, See term-control-seq-prefix-regexp and its use in term-emulate-terminal. It’s a bit, well, funny, but it seems to work. It keeps incomplete sequences in term-terminal-undecoded-bytes for the next call. > > In the patch attached to this e-mail, you’ll notice that I had to add some code that detects whether a sequence is terminated and buffers it for next time, in term-terminal-undecoded-bytes to be consistent with the current implementation. This is covered by the tests. > > If you guys think it’s time to refactor term.el to use a state machine and have time to spend on it, I’d be happy to help as much as I can. It’s a bit scary, because, unless I missed something, test coverage of the existing code isn’t very high, so adding more tests would be, I think, a good first step before engaging in larger changes. I don't feel stronly about state machines - I think it would be more robust, but I don't know if that justifies the effort. In principle using the term-terminal-undecoded-bytes logic is fine; however I'm not sure how "complete" the logic is in terms of unusual unhandled escape sequences or garbled inputs. If somebody does re-write term to use a state machine, it might save a little time and thought to re-use the code from my original term.el (attached). -- --Per Bothner per@bothner.com http://per.bothner.com/