Module Name: src Committed By: blymn Date: Thu Jul 11 07:13:41 UTC 2024
Modified Files: src/lib/libcurses: color.c curses_private.h screen.c Log Message: PR lib/58282 This is a partial fix for the issues raised. This change will reduce the output by preventing the foreground and background colours being set on each cell. The current colour pair applied is tracked and requests to set the colour to the same pair is now a no-op. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/lib/libcurses/color.c cvs rdiff -u -r1.81 -r1.82 src/lib/libcurses/curses_private.h cvs rdiff -u -r1.39 -r1.40 src/lib/libcurses/screen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libcurses/color.c diff -u src/lib/libcurses/color.c:1.47 src/lib/libcurses/color.c:1.48 --- src/lib/libcurses/color.c:1.47 Wed Oct 19 06:09:27 2022 +++ src/lib/libcurses/color.c Thu Jul 11 07:13:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: color.c,v 1.47 2022/10/19 06:09:27 blymn Exp $ */ +/* $NetBSD: color.c,v 1.48 2024/07/11 07:13:41 blymn Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: color.c,v 1.47 2022/10/19 06:09:27 blymn Exp $"); +__RCSID("$NetBSD: color.c,v 1.48 2024/07/11 07:13:41 blymn Exp $"); #endif /* not lint */ #include "curses.h" @@ -123,6 +123,7 @@ start_color(void) _cursesi_screen->COLORS = COLORS; _cursesi_screen->COLOR_PAIRS = COLOR_PAIRS; + _cursesi_screen->curpair = -1; /* Reset terminal colour and colour pairs. */ if (orig_colors != NULL) @@ -540,6 +541,10 @@ __set_color( /*ARGSUSED*/ WINDOW *win, a return; pair = PAIR_NUMBER((uint32_t)attr); + + if (pair == _cursesi_screen->curpair) + return; + __CTRACE(__CTRACE_COLOR, "__set_color: %d, %d, %d\n", pair, _cursesi_screen->colour_pairs[pair].fore, _cursesi_screen->colour_pairs[pair].back); @@ -578,6 +583,8 @@ __set_color( /*ARGSUSED*/ WINDOW *win, a 0, __cputchar); break; } + + _cursesi_screen->curpair = pair; curscr->wattr &= ~__COLOR; curscr->wattr |= attr & __COLOR; } @@ -611,6 +618,8 @@ __unset_color(WINDOW *win) } break; } + + _cursesi_screen->curpair = -1; } /* @@ -620,6 +629,12 @@ __unset_color(WINDOW *win) void __restore_colors(void) { + /* + * forget foreground/background colour just in case it was + * changed. We will reset them if required. + */ + _cursesi_screen->curpair = -1; + if (can_change != 0) switch (_cursesi_screen->color_type) { case COLOR_HP: Index: src/lib/libcurses/curses_private.h diff -u src/lib/libcurses/curses_private.h:1.81 src/lib/libcurses/curses_private.h:1.82 --- src/lib/libcurses/curses_private.h:1.81 Fri May 17 23:32:50 2024 +++ src/lib/libcurses/curses_private.h Thu Jul 11 07:13:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: curses_private.h,v 1.81 2024/05/17 23:32:50 uwe Exp $ */ +/* $NetBSD: curses_private.h,v 1.82 2024/07/11 07:13:41 blymn Exp $ */ /*- * Copyright (c) 1998-2000 Brett Lymn @@ -226,6 +226,7 @@ struct __screen { #define TABSIZE_DEFAULT 8 /* spaces. */ int COLORS; /* Maximum colors on the screen */ int COLOR_PAIRS; /* Maximum color pairs on the screen */ + short curpair; /* current colour pair set on the terminal */ int My_term; /* Use Def_term regardless. */ char GT; /* Gtty indicates tabs. */ char NONL; /* Term can't hack LF doing a CR. */ Index: src/lib/libcurses/screen.c diff -u src/lib/libcurses/screen.c:1.39 src/lib/libcurses/screen.c:1.40 --- src/lib/libcurses/screen.c:1.39 Mon May 27 14:30:43 2024 +++ src/lib/libcurses/screen.c Thu Jul 11 07:13:41 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.39 2024/05/27 14:30:43 uwe Exp $ */ +/* $NetBSD: screen.c,v 1.40 2024/07/11 07:13:41 blymn Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001"; #else -__RCSID("$NetBSD: screen.c,v 1.39 2024/05/27 14:30:43 uwe Exp $"); +__RCSID("$NetBSD: screen.c,v 1.40 2024/07/11 07:13:41 blymn Exp $"); #endif #endif /* not lint */ @@ -156,6 +156,7 @@ newterm(const char *type, FILE *outfd, F new_screen->nca = A_NORMAL; new_screen->color_type = COLOR_NONE; new_screen->COLOR_PAIRS = 0; + new_screen->curpair = -1; new_screen->old_mode = 1; new_screen->stdbuf = NULL; new_screen->stdscr = NULL;