return (int) l;
}
-static int insert_newline_color_erase(PTYForward *f, size_t offset) {
+static int insert_background_color(PTYForward *f, size_t offset) {
_cleanup_free_ char *s = NULL;
assert(f);
if (!f->background_color)
return 0;
- /* When we see a newline (ASCII 10) then this sets the background color to the desired one, and erase the rest
- * of the line with it */
-
- s = background_color_sequence(f);
- if (!s)
- return -ENOMEM;
-
- if (!strextend(&s, ANSI_ERASE_TO_END_OF_LINE))
- return -ENOMEM;
-
- return insert_string(f, offset, s);
-}
-
-static int insert_carriage_return_color(PTYForward *f, size_t offset) {
- _cleanup_free_ char *s = NULL;
-
- assert(f);
-
- if (!f->background_color)
- return 0;
-
- /* When we see a carriage return (ASCII 13) then this sets only the background */
-
s = background_color_sequence(f);
if (!s)
return -ENOMEM;
case ANSI_COLOR_STATE_TEXT:
break;
- case ANSI_COLOR_STATE_NEWLINE: {
- /* Immediately after a newline insert an ANSI sequence to erase the line with a background color */
+ case ANSI_COLOR_STATE_NEWLINE:
+ case ANSI_COLOR_STATE_CARRIAGE_RETURN:
+ /* Immediately after a newline (ASCII 10) or carriage return (ASCII 13) insert an
+ * ANSI sequence set the background color back. */
- r = insert_newline_color_erase(f, i);
+ r = insert_background_color(f, i);
if (r < 0)
return r;
i += r;
break;
- }
-
- case ANSI_COLOR_STATE_CARRIAGE_RETURN: {
- /* Immediately after a carriage return insert an ANSI sequence set the background color back */
-
- r = insert_carriage_return_color(f, i);
- if (r < 0)
- return r;
-
- i += r;
- break;
- }
case ANSI_COLOR_STATE_ESC: {