groundwork for 256 color parsing, added conceal

http-comm
Ondřej Hruška 7 years ago
parent bd43c4d9c3
commit 74c7628474
  1. 33
      user/apars_csi.c
  2. 30
      user/screen.c
  3. 6
      user/screen.h
  4. 3
      user/sgr.h

@ -542,8 +542,36 @@ do_csi_sgr(CSI_Data *opts)
// -- set color --
else if (n >= SGR_FG_START && n <= SGR_FG_END) screen_set_fg((Color) (n - SGR_FG_START)); // ANSI normal fg
else if (n >= SGR_BG_START && n <= SGR_BG_END) screen_set_bg((Color) (n - SGR_BG_START)); // ANSI normal bg
// AIX bright colors --
else if (n >= SGR_FG_BRT_START && n <= SGR_FG_BRT_END) screen_set_fg((Color) ((n - SGR_FG_BRT_START) + 8)); // AIX bright fg
else if (n >= SGR_BG_BRT_START && n <= SGR_BG_BRT_END) screen_set_bg((Color) ((n - SGR_BG_BRT_START) + 8)); // AIX bright bg
// reset color
else if (n == SGR_FG_DEFAULT) screen_set_fg(termconf_scratch.default_fg); // default fg
else if (n == SGR_BG_DEFAULT) screen_set_bg(termconf_scratch.default_bg); // default bg
// 256 colors
else if (n == SGR_FG_256 || n == SGR_BG_256) {
if (i < count-2) {
if (opts->n[i + 1] == 5) {
int color = opts->n[i + 2];
bool fg = n == SGR_FG_256;
if (fg) {
screen_set_fg_ext(color);
} else {
screen_set_bg_ext(color);
}
}
else {
ansi_warn("SGR syntax err");
apars_show_context();
break; // abandon further
}
i += 2;
} else {
ansi_warn("SGR syntax err");
apars_show_context();
break; // abandon further
}
}
// -- set attr --
else if (n == SGR_BOLD) screen_set_sgr(ATTR_BOLD, 1);
else if (n == SGR_FAINT) screen_set_sgr(ATTR_FAINT, 1);
@ -553,6 +581,7 @@ do_csi_sgr(CSI_Data *opts)
else if (n == SGR_STRIKE) screen_set_sgr(ATTR_STRIKE, 1);
else if (n == SGR_FRAKTUR) screen_set_sgr(ATTR_FRAKTUR, 1);
else if (n == SGR_INVERSE) screen_set_sgr_inverse(1);
else if (n == SGR_CONCEAL) screen_set_sgr_conceal(1);
// -- clear attr --
else if (n == SGR_OFF(SGR_BOLD)) screen_set_sgr(ATTR_BOLD, 0); // can also mean "Double Underline"
else if (n == SGR_OFF(SGR_FAINT)) screen_set_sgr(ATTR_FAINT | ATTR_BOLD, 0); // "normal"
@ -561,9 +590,7 @@ do_csi_sgr(CSI_Data *opts)
else if (n == SGR_OFF(SGR_BLINK)) screen_set_sgr(ATTR_BLINK, 0);
else if (n == SGR_OFF(SGR_STRIKE)) screen_set_sgr(ATTR_STRIKE, 0);
else if (n == SGR_OFF(SGR_INVERSE)) screen_set_sgr_inverse(0);
// -- AIX bright colors --
else if (n >= SGR_FG_BRT_START && n <= SGR_FG_BRT_END) screen_set_fg((Color) ((n - SGR_FG_BRT_START) + 8)); // AIX bright fg
else if (n >= SGR_BG_BRT_START && n <= SGR_BG_BRT_END) screen_set_bg((Color) ((n - SGR_BG_BRT_START) + 8)); // AIX bright bg
else if (n == SGR_OFF(SGR_CONCEAL)) screen_set_sgr_conceal(0);
else {
ansi_noimpl("SGR %d", n);
}

@ -76,6 +76,7 @@ typedef struct {
/* SGR */
bool inverse; //!< not in attrs bc it's applied server-side (not sent to browser)
bool conceal; //!< similar to inverse, causes all to be replaced by SP
u8 attrs;
Color fg; //!< Foreground color for writing
Color bg; //!< Background color for writing
@ -310,6 +311,7 @@ screen_reset_sgr(void)
cursor.bg = termconf->default_bg;
cursor.attrs = 0;
cursor.inverse = false;
cursor.conceal = false;
}
/**
@ -1118,6 +1120,24 @@ screen_set_bg(Color color)
cursor.bg = color;
}
/**
* Set cursor foreground color, extended
*/
void ICACHE_FLASH_ATTR
screen_set_fg_ext(u16 color)
{
// TODO validate and set
}
/**
* Set cursor background color, extended
*/
void ICACHE_FLASH_ATTR
screen_set_bg_ext(u16 color)
{
// TODO validate and set
}
void ICACHE_FLASH_ATTR
screen_set_sgr(u8 attrs, bool ena)
{
@ -1135,6 +1155,12 @@ screen_set_sgr_inverse(bool ena)
cursor.inverse = ena;
}
void ICACHE_FLASH_ATTR
screen_set_sgr_conceal(bool ena)
{
cursor.conceal = ena;
}
void ICACHE_FLASH_ATTR
screen_set_charset_n(int Gx)
{
@ -1225,6 +1251,10 @@ screen_putchar(const char *ch)
// clear "hanging" flag if not possible
clear_invalid_hanging();
if (cursor.conceal) {
ch = " ";
}
// Special treatment for CRLF
switch (ch[0]) {
case CR:

@ -235,10 +235,16 @@ typedef uint8_t Color; // 0-16
void screen_set_fg(Color color);
/** Set cursor background coloor */
void screen_set_bg(Color color);
/** Set cursor foreground color, extended */
void screen_set_fg_ext(u16 color);
/** Set cursor background coloor, extended */
void screen_set_bg_ext(u16 color);
/** Enable/disable attrs by bitmask */
void screen_set_sgr(u8 attrs, bool ena);
/** Set the inverse attribute */
void screen_set_sgr_inverse(bool ena);
/** Conceal style */
void screen_set_sgr_conceal(bool ena);
/** Reset cursor attribs */
void screen_reset_sgr(void);

@ -14,15 +14,18 @@ enum SGR_CODES {
SGR_BLINK = 5,
SGR_BLINK_FAST = 6,
SGR_INVERSE = 7,
SGR_CONCEAL = 8,
SGR_STRIKE = 9,
SGR_FRAKTUR = 20,
SGR_FG_START = 30,
SGR_FG_END = 37,
SGR_FG_DEFAULT = 39,
SGR_FG_256 = 38,
SGR_BG_START = 40,
SGR_BG_END = 47,
SGR_BG_256 = 48,
SGR_BG_DEFAULT = 49,
SGR_FG_BRT_START = 90,

Loading…
Cancel
Save