Skip to content

Commit

Permalink
Optionally emit NUL/CAN/SUB/DEL from the parser rather than just igno…
Browse files Browse the repository at this point in the history
…ring them
  • Loading branch information
leonerd committed Jan 15, 2023
1 parent b47ce71 commit b891076
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/vterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ typedef struct {
void vterm_parser_set_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user);
void *vterm_parser_get_cbdata(VTerm *vt);

/* Normally NUL, CAN, SUB and DEL are ignored. Setting this true causes them
* to be emitted by the 'control' callback
*/
void vterm_parser_set_emit_nul(VTerm *vt, bool emit);

// -----------
// State layer
// -----------
Expand Down
9 changes: 9 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len)
string_fragment(vt, string_start, bytes + pos - string_start, false);
string_start = bytes + pos + 1;
}
if(vt->parser.emit_nul)
do_control(vt, c);
continue;
}
if(c == 0x18 || c == 0x1a) { // CAN, SUB
vt->parser.in_esc = false;
ENTER_NORMAL_STATE();
if(vt->parser.emit_nul)
do_control(vt, c);
continue;
}
else if(c == 0x1b) { // ESC
Expand Down Expand Up @@ -391,3 +395,8 @@ void *vterm_parser_get_cbdata(VTerm *vt)
{
return vt->parser.cbdata;
}

void vterm_parser_set_emit_nul(VTerm *vt, bool emit)
{
vt->parser.emit_nul = emit;
}
2 changes: 2 additions & 0 deletions src/vterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ VTerm *vterm_build(const struct VTermBuilder *builder)
vt->parser.callbacks = NULL;
vt->parser.cbdata = NULL;

vt->parser.emit_nul = false;

vt->outfunc = NULL;
vt->outdata = NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/vterm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ struct VTerm
void *cbdata;

bool string_initial;

bool emit_nul;
} parser;

/* len == malloc()ed size; cur == number of valid bytes */
Expand Down

0 comments on commit b891076

Please sign in to comment.