diff --git a/Makefile.am b/Makefile.am index 6439cf9..dade3ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,8 @@ seq2gif_CFLAGS = $(MAYBE_COVERAGE) test: all ./seq2gif -i tests/data/sl.tty -o /dev/null + ./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 diff --git a/Makefile.in b/Makefile.in index 85625a7..d14d616 100644 --- a/Makefile.in +++ b/Makefile.in @@ -906,6 +906,8 @@ uninstall-am: uninstall-binPROGRAMS test: all ./seq2gif -i tests/data/sl.tty -o /dev/null + ./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 diff --git a/README.md b/README.md index 766eec9..96fb5a2 100644 --- a/README.md +++ b/README.md @@ -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) ``` diff --git a/main.c b/main.c index 91474c0..54dba01 100644 --- a/main.c +++ b/main.c @@ -72,6 +72,7 @@ struct settings_t { char *output; int render_interval; double play_speed; + bool use_bright_instead_of_bold; }; enum cmap_bitfield { @@ -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; @@ -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 */ @@ -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; } @@ -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) { @@ -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); diff --git a/pseudo.c b/pseudo.c index 1fdf2fb..bcd72ec 100644 --- a/pseudo.c +++ b/pseudo.c @@ -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); diff --git a/terminal.c b/terminal.c index 03d7c6c..dc7ddaf 100644 --- a/terminal.c +++ b/terminal.c @@ -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; @@ -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); diff --git a/tests/data/SGR1.tty b/tests/data/SGR1.tty new file mode 100644 index 0000000..403598a Binary files /dev/null and b/tests/data/SGR1.tty differ diff --git a/yaft.h b/yaft.h index b24ddaf..ebc27c2 100644 --- a/yaft.h +++ b/yaft.h @@ -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() */