From: Bruno Haible Date: Tue, 12 Mar 2019 18:28:25 +0000 (+0100) Subject: libtextstyle: New function styled_ostream_flush_to_current_style. X-Git-Tag: v0.20~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9444f3d2eaa7d05ba2325b40a1a552ad3be82760;p=thirdparty%2Fgettext.git libtextstyle: New function styled_ostream_flush_to_current_style. * gnulib-local/lib/styled-ostream.oo.h (struct styled_ostream): Add method flush_to_current_style. * gnulib-local/lib/fd-styled-ostream.oo.c (fd_styled_ostream::flush_to_current_style): New method. * gnulib-local/lib/term-styled-ostream.oo.c (term_styled_ostream::flush_to_current_style): New method. * gnulib-local/lib/html-styled-ostream.oo.c (html_styled_ostream::flush_to_current_style): New method. * libtextstyle/lib/textstyle.h (styled_ostream_flush_to_current_style): New declaration. * libtextstyle/doc/libtextstyle.texi (The styled_ostream class): Document styled_ostream_flush_to_current_style. * libtextstyle/NEWS: Mention the change. --- diff --git a/gnulib-local/lib/fd-styled-ostream.oo.c b/gnulib-local/lib/fd-styled-ostream.oo.c index d3bb1e96e..8cf64621a 100644 --- a/gnulib-local/lib/fd-styled-ostream.oo.c +++ b/gnulib-local/lib/fd-styled-ostream.oo.c @@ -68,6 +68,12 @@ fd_styled_ostream::end_use_class (fd_styled_ostream_t stream, { } +static void +fd_styled_ostream::flush_to_current_style (fd_styled_ostream_t stream) +{ + fd_ostream_flush (stream->destination, FLUSH_THIS_STREAM); +} + /* Constructor. */ fd_styled_ostream_t diff --git a/gnulib-local/lib/html-styled-ostream.oo.c b/gnulib-local/lib/html-styled-ostream.oo.c index 77201e171..41aa170e1 100644 --- a/gnulib-local/lib/html-styled-ostream.oo.c +++ b/gnulib-local/lib/html-styled-ostream.oo.c @@ -89,6 +89,12 @@ html_styled_ostream::end_use_class (html_styled_ostream_t stream, html_ostream_end_span (stream->html_destination, classname); } +static void +html_styled_ostream::flush_to_current_style (html_styled_ostream_t stream) +{ + html_ostream_flush_to_current_style (stream->html_destination); +} + /* Constructor. */ html_styled_ostream_t diff --git a/gnulib-local/lib/styled-ostream.oo.h b/gnulib-local/lib/styled-ostream.oo.h index b612d9ef8..2daa87c28 100644 --- a/gnulib-local/lib/styled-ostream.oo.h +++ b/gnulib-local/lib/styled-ostream.oo.h @@ -38,6 +38,14 @@ methods: /* End a run of text belonging to CLASSNAME. The begin_use_class / end_use_class calls must match properly. */ void end_use_class (styled_ostream_t stream, const char *classname); + + /* Like styled_ostream_flush (first_arg, FLUSH_THIS_STREAM), except that it + leaves the destination with the current text style enabled, instead + of with the default text style. + After calling this function, you can output strings without newlines(!) + to the underlying stream, and they will be rendered like strings passed + to 'ostream_write_mem' or 'ostream_write_str'. */ + void flush_to_current_style (styled_ostream_t stream); }; diff --git a/gnulib-local/lib/term-styled-ostream.oo.c b/gnulib-local/lib/term-styled-ostream.oo.c index 9ab96d702..2cfd4a854 100644 --- a/gnulib-local/lib/term-styled-ostream.oo.c +++ b/gnulib-local/lib/term-styled-ostream.oo.c @@ -595,6 +595,18 @@ term_styled_ostream::end_use_class (term_styled_ostream_t stream, stream->curr_attr = (attributes_t *) found; } +static void +term_styled_ostream::flush_to_current_style (term_styled_ostream_t stream) +{ + term_ostream_set_color (stream->destination, stream->curr_attr->color); + term_ostream_set_bgcolor (stream->destination, stream->curr_attr->bgcolor); + term_ostream_set_weight (stream->destination, stream->curr_attr->weight); + term_ostream_set_posture (stream->destination, stream->curr_attr->posture); + term_ostream_set_underline (stream->destination, stream->curr_attr->underline); + + term_ostream_flush_to_current_style (stream->destination); +} + /* Constructor. */ term_styled_ostream_t diff --git a/libtextstyle/NEWS b/libtextstyle/NEWS index 1ecb72c37..b22a1c408 100644 --- a/libtextstyle/NEWS +++ b/libtextstyle/NEWS @@ -1,10 +1,11 @@ New in 0.6: * The ostream_t operation 'flush' now takes an additional argument, of type ostream_flush_scope_t. -* The term_ostream_t type supports a new function - term_ostream_flush_to_current_style. -* The html_ostream_t type supports a new function - html_ostream_flush_to_current_style. +* New functions: + TYPE FUNCTION + styled_ostream_t styled_ostream_flush_to_current_style + term_ostream_t term_ostream_flush_to_current_style + html_ostream_t html_ostream_flush_to_current_style New in 0.5: diff --git a/libtextstyle/doc/libtextstyle.texi b/libtextstyle/doc/libtextstyle.texi index fd4beb239..91c685854 100644 --- a/libtextstyle/doc/libtextstyle.texi +++ b/libtextstyle/doc/libtextstyle.texi @@ -707,6 +707,16 @@ Ends a run of text belonging to @code{@var{classname}}. The @code{styled_ostream_end_use_class} calls must match properly. @end deftypefn +@deftypefn Function void styled_ostream_flush_to_current_style (styled_ostream_t@tie{}@var{stream}) +This function acts like @code{ostream_flush (@var{stream}, FLUSH_THIS_STREAM)}, +except that it leaves the destination with the current text style enabled, +instead of with the default text style. + +After calling this function, you can output strings without newlines(!) to the +underlying stream, and they will be rendered like strings passed to +@code{ostream_write_mem} or @code{ostream_write_str}. +@end deftypefn + @node ostream subclasses without styling @subsection Concrete ostream subclasses without styling diff --git a/libtextstyle/lib/textstyle.h b/libtextstyle/lib/textstyle.h index 7450fbbb1..f905fe6cc 100644 --- a/libtextstyle/lib/textstyle.h +++ b/libtextstyle/lib/textstyle.h @@ -93,6 +93,13 @@ extern void styled_ostream_flush (styled_ostream_t first_arg, ostream_flush_scop extern void styled_ostream_free (styled_ostream_t first_arg); extern void styled_ostream_begin_use_class (styled_ostream_t first_arg, const char *classname); extern void styled_ostream_end_use_class (styled_ostream_t first_arg, const char *classname); +/* Like styled_ostream_flush (first_arg, FLUSH_THIS_STREAM), except that it + leaves the destination with the current text style enabled, instead + of with the default text style. + After calling this function, you can output strings without newlines(!) + to the underlying stream, and they will be rendered like strings passed + to 'ostream_write_mem' or 'ostream_write_str'. */ +extern void styled_ostream_flush_to_current_style (styled_ostream_t stream); #ifdef __cplusplus } #endif