#include "vterm.h"
#include "../src/vterm_internal.h" // We pull in some internal bits too
#include <assert.h>
#include <stdio.h>
#include <string.h>
#define streq(a,b) (!strcmp(a,b))
#define strstartswith(a,b) (!strncmp(a,b,strlen(b)))
static size_t inplace_hex2bytes(char *s)
{
char *inpos = s, *outpos = s;
while(*inpos) {
unsigned int ch;
if(sscanf(inpos, "%2x", &ch) < 1)
break;
*outpos = ch;
outpos += 1; inpos += 2;
}
return outpos - s;
}
static VTermModifier strpe_modifiers(char **strp)
{
VTermModifier state = 0;
while((*strp)[0]) {
switch(((*strp)++)[0]) {
case 'S': state |= VTERM_MOD_SHIFT; break;
case 'C': state |= VTERM_MOD_CTRL; break;
case 'A': state |= VTERM_MOD_ALT; break;
default: return state;
}
}
return state;
}
static VTermKey strp_key(char *str)
{
static struct {
char *name;
VTermKey key;
} keys[] = {
{ "Up", VTERM_KEY_UP },
{ "Tab", VTERM_KEY_TAB },
{ "Enter", VTERM_KEY_ENTER },
{ "KP0", VTERM_KEY_KP_0 },
{ "F1", VTERM_KEY_FUNCTION(1) },
{ NULL, VTERM_KEY_NONE },
};
int i;
for(i = 0; keys[i].name; i++) {
if(streq(str, keys[i].name))
return keys[i].key;
}
return VTERM_KEY_NONE;
}
static void print_color(const VTermColor *col)
{
if (VTERM_COLOR_IS_RGB(col)) {
printf("rgb(%d,%d,%d", col->red, col->green, col->blue);
}
else if (VTERM_COLOR_IS_INDEXED(col)) {
printf("idx(%d", col->index);
}
else {
printf("invalid(%d", col->type);
}
if (VTERM_COLOR_IS_DEFAULT_FG(col))