This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 90486faf47d797ba28ca4776b36c039d63547b09 Author: raiden00pl <[email protected]> AuthorDate: Thu Aug 20 10:13:25 2026 +0200 graphics/nxterm: consume SGR escape sequences Recognize variable-length ANSI SGR sequences and consume them without changing attributes so unsupported color controls are not rendered as terminal text. Signed-off-by: raiden00pl <[email protected]> --- graphics/nxterm/nxterm.h | 2 +- graphics/nxterm/nxterm_vt100.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/graphics/nxterm/nxterm.h b/graphics/nxterm/nxterm.h index 5b77f94829d..9cae216459e 100644 --- a/graphics/nxterm/nxterm.h +++ b/graphics/nxterm/nxterm.h @@ -61,7 +61,7 @@ /* VT100 escape sequence processing */ -#define VT100_MAX_SEQUENCE 3 +#define VT100_MAX_SEQUENCE 32 /**************************************************************************** * Public Types diff --git a/graphics/nxterm/nxterm_vt100.c b/graphics/nxterm/nxterm_vt100.c index 7e67a39c4f4..e421af785ab 100644 --- a/graphics/nxterm/nxterm_vt100.c +++ b/graphics/nxterm/nxterm_vt100.c @@ -53,6 +53,8 @@ struct vt100_sequence_s static int nxterm_erasetoeol(FAR struct nxterm_state_s *priv); static int nxterm_cursorleft(FAR struct nxterm_state_s *priv); static int nxterm_cursorright(FAR struct nxterm_state_s *priv); +static enum nxterm_vt100state_e + nxterm_sgr(FAR struct nxterm_state_s *priv, int seqsize); /**************************************************************************** * Private Data @@ -193,6 +195,45 @@ static int nxterm_cursorright(FAR struct nxterm_state_s *priv) return OK; } +/**************************************************************************** + * Name: nxterm_sgr + * + * Description: + * Consume an ANSI Select Graphic Rendition sequence. NxTerm does not + * currently support changing text attributes, but consuming the sequence + * prevents unsupported color controls from being rendered as text. + * + ****************************************************************************/ + +static enum nxterm_vt100state_e +nxterm_sgr(FAR struct nxterm_state_s *priv, int seqsize) +{ + int i; + + if (seqsize < 2 || priv->seq[0] != ASCII_ESC || priv->seq[1] != '[') + { + return VT100_ABORT; + } + + for (i = 2; i < seqsize; i++) + { + char ch = priv->seq[i]; + + if (ch == 'm') + { + priv->nseq = 0; + return VT100_PROCESSED; + } + + if ((ch < '0' || ch > '9') && ch != ';' && ch != ':') + { + return VT100_ABORT; + } + } + + return seqsize < VT100_MAX_SEQUENCE ? VT100_CONSUMED : VT100_ABORT; +} + /**************************************************************************** * Name: nxterm_vt100part * @@ -289,6 +330,16 @@ static enum nxterm_vt100state_e nxterm_vt100seq( return VT100_CONSUMED; } + /* SGR parameters are variable-length. Consume these sequences even + * though NxTerm does not yet implement their visual attributes. + */ + + ret = nxterm_sgr(priv, seqsize); + if (ret != VT100_ABORT) + { + return ret; + } + /* We get here on a failure. The buffer sequence is not part of any * supported VT100 escape sequence. If seqsize > 1 then we need to * return a special value because we have to re-process the buffered
