Skip to content

Commit

Permalink
Support bold rendition for SGR 1
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 3, 2020
1 parent 886138e commit 585d2d5
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Expand Up @@ -16,9 +16,10 @@ seq2gif_CFLAGS = $(MAYBE_COVERAGE)

test: all
for ttyfile in tests/data/*.tty; do ./seq2gif -i "$$ttyfile" -o /dev/null; done
./seq2gif -i tests/data/sl.tty -o /dev/null
! ./seq2gif -i /non-existent-file.tty -o /dev/null
! ./seq2gif -i tests/data/sl.tty -o /non-existent-file.out
./seq2gif -i tests/data/SGR1.tty -o /dev/null
./seq2gif -i tests/data/SGR1.tty -o /dev/null -B

coveralls: test
coveralls -E '.*\.h' -e tests -e glyph -e m4
Expand Down
3 changes: 2 additions & 1 deletion Makefile.in
Expand Up @@ -952,9 +952,10 @@ uninstall-am: uninstall-binPROGRAMS

test: all
for ttyfile in tests/data/*.tty; do ./seq2gif -i "$$ttyfile" -o /dev/null; done
./seq2gif -i tests/data/sl.tty -o /dev/null
! ./seq2gif -i /non-existent-file.tty -o /dev/null
! ./seq2gif -i tests/data/sl.tty -o /non-existent-file.out
./seq2gif -i tests/data/SGR1.tty -o /dev/null
./seq2gif -i tests/data/SGR1.tty -o /dev/null -B

coveralls: test
coveralls -E '.*\.h' -e tests -e glyph -e m4
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -97,6 +97,9 @@ Options:
-s NUM, --play-speed=NUM specify the factor of the play speed.
A larger value means faster play.
(default: 1.0)
-B, --use-bright-for-bold use bright colors to render the
characters with bold attribute instead
of using bold fonts. (default: 0)
```


Expand Down
12 changes: 11 additions & 1 deletion main.c
Expand Up @@ -72,6 +72,7 @@ struct settings_t {
char *output;
int render_interval;
double play_speed;
bool use_bright_instead_of_bold;
};

enum cmap_bitfield {
Expand Down Expand Up @@ -246,13 +247,16 @@ static void show_help()
"-s NUM, --play-speed=NUM specify the factor of the play speed.\n"
" A larger value means faster play.\n"
" (default: 1.0)\n"
"-B, --use-bright-for-bold use bright colors to render the\n"
" characters with bold attribute instead\n"
" of using bold fonts. (default: 0)\n"
);
}

static int parse_args(int argc, char *argv[], struct settings_t *psettings)
{
int n;
char const *optstring = "w:h:HVl:f:b:c:t:jr:i:o:I:s:";
char const *optstring = "w:h:HVl:f:b:c:t:jr:i:o:I:s:B";
#ifdef HAVE_GETOPT_LONG
int long_opt;
int option_index;
Expand All @@ -272,6 +276,7 @@ static int parse_args(int argc, char *argv[], struct settings_t *psettings)
{"version", no_argument, &long_opt, 'V'},
{"render-interval", required_argument, &long_opt, 'I'},
{"play-speed", required_argument, &long_opt, 's'},
{"use-bright-for-bold", no_argument, &long_opt, 'B'},
{0, 0, 0, 0}
};
#endif /* HAVE_GETOPT_LONG */
Expand Down Expand Up @@ -383,6 +388,9 @@ static int parse_args(int argc, char *argv[], struct settings_t *psettings)
goto argerr;
}
break;
case 'B':
psettings->use_bright_instead_of_bold = true;
break;
default:
goto argerr;
}
Expand Down Expand Up @@ -525,6 +533,7 @@ int main(int argc, char *argv[])
NULL, /* output */
20, /* render_interval */
1.0, /* play_speed */
false, /* use_bright_instead_of_bold */
};

if (parse_args(argc, argv, &settings) != 0) {
Expand All @@ -549,6 +558,7 @@ int main(int argc, char *argv[])
settings.cursor_color,
settings.tabwidth,
settings.cjkwidth);
term.use_bright_instead_of_bold = settings.use_bright_instead_of_bold;

/* init gif */
img = (unsigned char *) ecalloc(pb.width * pb.height, 1);
Expand Down
11 changes: 7 additions & 4 deletions pseudo.c
Expand Up @@ -91,14 +91,17 @@ static void draw_line(struct pseudobuffer *pb, struct terminal *term, int line)
color_pair.bg = color_pair.fg;

for (w = 0; w < CELL_WIDTH; w++) {
int isfg = 0;
pos = (term->width - 1 - margin_right - w) * pb->bytes_per_pixel
+ (line * CELL_HEIGHT + h) * pb->line_length;

/* set color palette */
if (cellp->glyphp->bitmap[h] & (0x01 << (bdf_padding + w)))
pixel = color_list[color_pair.fg];
if (cellp->attribute & attr_mask[ATTR_BOLD] && !term->use_bright_instead_of_bold)
isfg = cellp->glyphp->bitmap[h] & (0x03 << (bdf_padding + w));
else
pixel = color_list[color_pair.bg];
isfg = cellp->glyphp->bitmap[h] & (0x01 << (bdf_padding + w));

/* set color palette */
pixel = color_list[isfg ? color_pair.fg : color_pair.bg];

/* update copy buffer only */
memcpy(pb->buf + pos, &pixel, pb->bytes_per_pixel);
Expand Down
14 changes: 10 additions & 4 deletions terminal.c
Expand Up @@ -77,10 +77,14 @@ int set_cell(struct terminal *term, int y, int x, const struct glyph_t *glyphp)

cell.glyphp = glyphp;

cell.color_pair.fg = (term->attribute & attr_mask[ATTR_BOLD] && term->color_pair.fg <= 7) ?
term->color_pair.fg + BRIGHT_INC: term->color_pair.fg;
cell.color_pair.bg = (term->attribute & attr_mask[ATTR_BLINK] && term->color_pair.bg <= 7) ?
term->color_pair.bg + BRIGHT_INC: term->color_pair.bg;
cell.color_pair.fg = term->color_pair.fg;
cell.color_pair.bg = term->color_pair.bg;
if(term->use_bright_instead_of_bold){
if(term->attribute & attr_mask[ATTR_BOLD] && term->color_pair.fg <= 7)
cell.color_pair.fg += BRIGHT_INC;
}
if(term->attribute & attr_mask[ATTR_BLINK] && term->color_pair.bg <= 7)
cell.color_pair.bg += BRIGHT_INC;

if (term->attribute & attr_mask[ATTR_REVERSE]) {
color_tmp = cell.color_pair.fg;
Expand Down Expand Up @@ -387,6 +391,8 @@ void term_init(struct terminal *term, int width, int height,
term->fn_wcwidth = mk_wcwidth;
}

term->use_bright_instead_of_bold = false;

if (DEBUG)
fprintf(stderr, "width:%d height:%d cols:%d lines:%d\n",
width, height, term->cols, term->lines);
Expand Down
Binary file added tests/data/SGR1.tty
Binary file not shown.
1 change: 1 addition & 0 deletions yaft.h
Expand Up @@ -184,6 +184,7 @@ struct terminal {
int cursor_color; /* corsor color */
int tabwidth; /* hardware tabstop */
wcwidth_func_t fn_wcwidth; /* wcwidth strategy */
bool use_bright_instead_of_bold; /* interpretation of bold attributes */
};

struct parm_t { /* for parse_arg() */
Expand Down

0 comments on commit 585d2d5

Please sign in to comment.