From: Thomas Weißschuh Date: Wed, 15 Feb 2023 17:23:16 +0000 (+0000) Subject: cal: use escape codes from color-names.h X-Git-Tag: v2.39-rc1~73^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f31049f99ecaac77097acdc4d019f99b9fcf731c;p=thirdparty%2Futil-linux.git cal: use escape codes from color-names.h Signed-off-by: Thomas Weißschuh --- diff --git a/misc-utils/cal.c b/misc-utils/cal.c index eb2cfed92f..77782867cd 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -81,51 +81,8 @@ #define DOY_MONTH_WIDTH 27 /* -j month width */ #define DOM_MONTH_WIDTH 20 /* month width */ -static int has_term = 0; static const char *Senter = "", *Sexit = ""; /* enter and exit standout mode */ -#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) -# if defined(HAVE_NCURSESW_TERM_H) -# include -# elif defined(HAVE_NCURSES_TERM_H) -# include -# elif defined(HAVE_TERM_H) -# include -# endif -#endif - -static int setup_terminal(char *term -#if !defined(HAVE_LIBNCURSES) && !defined(HAVE_LIBNCURSESW) - __attribute__((__unused__)) -#endif - ) -{ -#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) - int ret; - - if (setupterm(term, STDOUT_FILENO, &ret) != 0 || ret != 1) - return -1; -#endif - return 0; -} - -static const char *my_tgetstr(char *ss -#if !defined(HAVE_LIBNCURSES) && !defined(HAVE_LIBNCURSESW) - __attribute__((__unused__)) -#endif - ) -{ - const char *ret = NULL; - -#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) - if (has_term) - ret = tigetstr(ss); -#endif - if (!ret || ret == (char *)-1) - return ""; - return ret; -} - #include "widechar.h" enum { @@ -284,7 +241,6 @@ static time_t cal_time(time_t *t) int main(int argc, char **argv) { struct tm local_time; - char *term; time_t now; int ch = 0, yflag = 0, Yflag = 0, cols = COLUMNS_MAX_THREE; @@ -338,15 +294,6 @@ int main(int argc, char **argv) textdomain(PACKAGE); close_stdout_atexit(); - term = getenv("TERM"); - if (term) { - has_term = setup_terminal(term) == 0; - if (has_term) { - Senter = my_tgetstr("smso"); - Sexit = my_tgetstr("rmso"); - } - } - /* * The traditional Unix cal utility starts the week at Sunday, * while ISO 8601 starts at Monday. We read the start day from @@ -568,21 +515,13 @@ int main(int argc, char **argv) weekdays_init(&ctl); headers_init(&ctl); - if (colors_init(ctl.colormode, "cal") == 0) { - /* - * If standout mode available (Senter and Sexit are set) and - * user or terminal-colors.d do not disable colors than - * ignore colors_init(). - */ - if (*Senter && *Sexit && colors_mode() != UL_COLORMODE_NEVER) { - /* let use standout mode */ - ; - } else { - /* disable */ - Senter = ""; Sexit = ""; - ctl.req.day = 0; - ctl.weektype &= ~WEEK_NUM_MASK; - } + if (colors_init(ctl.colormode, "cal") > 0) { + Senter = UL_COLOR_REVERSE; + Sexit = UL_COLOR_RESET; + } else { + /* disable */ + ctl.req.day = 0; + ctl.weektype &= ~WEEK_NUM_MASK; } if (yflag || Yflag) { diff --git a/tests/expected/cal/color-first-day b/tests/expected/cal/color-first-day index ca3c63d845..446f4fd93e 100644 --- a/tests/expected/cal/color-first-day +++ b/tests/expected/cal/color-first-day @@ -1,6 +1,6 @@ January 0001 Su Mo Tu We Th Fr Sa -  1 +  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 diff --git a/tests/expected/cal/color-last-day b/tests/expected/cal/color-last-day index 2f058dabd0..ec7793c6b5 100644 --- a/tests/expected/cal/color-last-day +++ b/tests/expected/cal/color-last-day @@ -4,5 +4,5 @@ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 -28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 +28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 30 31 diff --git a/tests/expected/cal/color-reformation-corner-cases-1 b/tests/expected/cal/color-reformation-corner-cases-1 index 75bf906b63..4b26465bbe 100644 --- a/tests/expected/cal/color-reformation-corner-cases-1 +++ b/tests/expected/cal/color-reformation-corner-cases-1 @@ -1,6 +1,6 @@ September 1752 Su Mo Tu We Th Fr Sa - 1  2 14 15 16 + 1  2 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-reformation-corner-cases-4 b/tests/expected/cal/color-reformation-corner-cases-4 index 5a7b85dab1..6c5571458e 100644 --- a/tests/expected/cal/color-reformation-corner-cases-4 +++ b/tests/expected/cal/color-reformation-corner-cases-4 @@ -1,6 +1,6 @@ September 1752 Su Mo Tu We Th Fr Sa - 1 2 14 15 16 + 1 2 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-vertical b/tests/expected/cal/color-vertical index dc6ce6caa0..bf5c609413 100644 --- a/tests/expected/cal/color-vertical +++ b/tests/expected/cal/color-vertical @@ -2,7 +2,7 @@ Su 5 12 19 26 Mo 6 13 20 27 Tu 7 14 21 28 -We 1 8 15 22 +We 1 8 15 22 Th 2 9 16 23 Fr 3 10 17 24 Sa 4 11 18 25 diff --git a/tests/expected/cal/color-vertical-week b/tests/expected/cal/color-vertical-week index d0ccdc127a..d69866e1f1 100644 --- a/tests/expected/cal/color-vertical-week +++ b/tests/expected/cal/color-vertical-week @@ -2,7 +2,7 @@ Su 5 12 19 26 Mo 6 13 20 27 Tu 7 14 21 28 -We 1 8 15 22 +We 1 8 15 22 Th 2 9 16 23 Fr 3 10 17 24 Sa 4 11 18 25 diff --git a/tests/expected/cal/colorw-first-day-week-numbers b/tests/expected/cal/colorw-first-day-week-numbers index 78e1e81da6..e14aaf3a39 100644 --- a/tests/expected/cal/colorw-first-day-week-numbers +++ b/tests/expected/cal/colorw-first-day-week-numbers @@ -1,6 +1,6 @@ January 0001 Su Mo Tu We Th Fr Sa - 1  1 + 1  1 2 2 3 4 5 6 7 8 3 9 10 11 12 13 14 15 4 16 17 18 19 20 21 22 diff --git a/tests/expected/cal/colorw-last-day-week-numbers b/tests/expected/cal/colorw-last-day-week-numbers index e1c1f04c73..d0d49cc292 100644 --- a/tests/expected/cal/colorw-last-day-week-numbers +++ b/tests/expected/cal/colorw-last-day-week-numbers @@ -4,5 +4,5 @@ 46 7 8 9 10 11 12 13 50 5 6 7 8 9 10 11 2 2 3 4 5 6 7 8 47 14 15 16 17 18 19 20 51 12 13 14 15 16 17 18 3 9 10 11 12 13 14 15 48 21 22 23 24 25 26 27 52 19 20 21 22 23 24 25 4 16 17 18 19 20 21 22 -49 28 29 30 53 26 27 28 29 30 31 5 23 24 25 26 27 28 29 +49 28 29 30 53 26 27 28 29 30 31 5 23 24 25 26 27 28 29 6 30 31 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers index 5c7232eedc..98fa041f68 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers @@ -1,6 +1,6 @@ September 1752 Su Mo Tu We Th Fr Sa -36 1  2 14 15 16 +36 1  2 14 15 16 37 17 18 19 20 21 22 23 38 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers index dd081512b1..307b5398e5 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers @@ -1,6 +1,6 @@ September 1752 Su Mo Tu We Th Fr Sa -36 1 2 14 15 16 +36 1 2 14 15 16 37 17 18 19 20 21 22 23 38 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/weekarg-1m-week53-color b/tests/expected/cal/weekarg-1m-week53-color index 0e9edfb2a6..84a5e68862 100644 --- a/tests/expected/cal/weekarg-1m-week53-color +++ b/tests/expected/cal/weekarg-1m-week53-color @@ -1,7 +1,7 @@ Gregorian - Monday-based, week 53, 1 month January 2010 Mo Tu We Th Fr Sa Su -53 1 2 3 +53 1 2 3 1 4 5 6 7 8 9 10 2 11 12 13 14 15 16 17 3 18 19 20 21 22 23 24 diff --git a/tests/expected/cal/weekarg-1mj-week53-color b/tests/expected/cal/weekarg-1mj-week53-color index 8f73100d20..9a055ae064 100644 --- a/tests/expected/cal/weekarg-1mj-week53-color +++ b/tests/expected/cal/weekarg-1mj-week53-color @@ -1,7 +1,7 @@ Julian - Monday-based, week 53, 1 month January 2010 Mon Tue Wed Thu Fri Sat Sun -53 1 2 3 +53 1 2 3 1 4 5 6 7 8 9 10 2 11 12 13 14 15 16 17 3 18 19 20 21 22 23 24 diff --git a/tests/expected/cal/weekarg-3m-week40-color b/tests/expected/cal/weekarg-3m-week40-color index 8039f4498d..2ffa04ecde 100644 --- a/tests/expected/cal/weekarg-3m-week40-color +++ b/tests/expected/cal/weekarg-3m-week40-color @@ -1,9 +1,9 @@ Gregorian - Monday-based, week 40, 3 month September 2013 October 2013 November 2013 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su -35 1 40 1 2 3 4 5 6 44 1 2 3 -36 2 3 4 5 6 7 8 41  7 8 9 10 11 12 13 45 4 5 6 7 8 9 10 +35 1 40 1 2 3 4 5 6 44 1 2 3 +36 2 3 4 5 6 7 8 41  7 8 9 10 11 12 13 45 4 5 6 7 8 9 10 37 9 10 11 12 13 14 15 42 14 15 16 17 18 19 20 46 11 12 13 14 15 16 17 38 16 17 18 19 20 21 22 43 21 22 23 24 25 26 27 47 18 19 20 21 22 23 24 39 23 24 25 26 27 28 29 44 28 29 30 31 48 25 26 27 28 29 30 -40 30 +40 30 diff --git a/tests/expected/cal/weekarg-3m-week52-color b/tests/expected/cal/weekarg-3m-week52-color index f15faf1d2a..1b0b6c38f1 100644 --- a/tests/expected/cal/weekarg-3m-week52-color +++ b/tests/expected/cal/weekarg-3m-week52-color @@ -5,5 +5,5 @@ Gregorian - Monday-based, week 52, 3 month 45 6 7 8 9 10 11 12 49 4 5 6 7 8 9 10 2 8 9 10 11 12 13 14 46 13 14 15 16 17 18 19 50 11 12 13 14 15 16 17 3 15 16 17 18 19 20 21 47 20 21 22 23 24 25 26 51 18 19 20 21 22 23 24 4 22 23 24 25 26 27 28 -48 27 28 29 30 52 25 26 27 28 29 30 31 5 29 30 31 +48 27 28 29 30 52 25 26 27 28 29 30 31 5 29 30 31 diff --git a/tests/expected/cal/weekarg-3m-week53-color b/tests/expected/cal/weekarg-3m-week53-color index b8c7abf7a1..b46d330544 100644 --- a/tests/expected/cal/weekarg-3m-week53-color +++ b/tests/expected/cal/weekarg-3m-week53-color @@ -1,9 +1,9 @@ Gregorian - Monday-based, week 53, 3 month December 2009 January 2010 February 2010 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su -49 1 2 3 4 5 6 53 1 2 3 5 1 2 3 4 5 6 7 +49 1 2 3 4 5 6 53 1 2 3 5 1 2 3 4 5 6 7 50 7 8 9 10 11 12 13 1 4 5 6 7 8 9 10 6 8 9 10 11 12 13 14 51 14 15 16 17 18 19 20 2 11 12 13 14 15 16 17 7 15 16 17 18 19 20 21 52 21 22 23 24 25 26 27 3 18 19 20 21 22 23 24 8 22 23 24 25 26 27 28 -53 28 29 30 31 4 25 26 27 28 29 30 31 +53 28 29 30 31 4 25 26 27 28 29 30 31 diff --git a/tests/expected/cal/weekarg-3mj-week40-color b/tests/expected/cal/weekarg-3mj-week40-color index d377259b20..ef246ade14 100644 --- a/tests/expected/cal/weekarg-3mj-week40-color +++ b/tests/expected/cal/weekarg-3mj-week40-color @@ -1,9 +1,9 @@ Julian - Monday-based, week 40, 3 month September 2013 October 2013 November 2013 Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun -35 244 40 274 275 276 277 278 279 44 305 306 307 -36 245 246 247 248 249 250 251 41 280 281 282 283 284 285 286 45 308 309 310 311 312 313 314 +35 244 40 274 275 276 277 278 279 44 305 306 307 +36 245 246 247 248 249 250 251 41 280 281 282 283 284 285 286 45 308 309 310 311 312 313 314 37 252 253 254 255 256 257 258 42 287 288 289 290 291 292 293 46 315 316 317 318 319 320 321 38 259 260 261 262 263 264 265 43 294 295 296 297 298 299 300 47 322 323 324 325 326 327 328 39 266 267 268 269 270 271 272 44 301 302 303 304 48 329 330 331 332 333 334 -40 273 +40 273 diff --git a/tests/expected/cal/weekarg-3s-week54-color b/tests/expected/cal/weekarg-3s-week54-color index 8ecca4be3e..5b19cddfbe 100644 --- a/tests/expected/cal/weekarg-3s-week54-color +++ b/tests/expected/cal/weekarg-3s-week54-color @@ -6,4 +6,4 @@ Gregorian - Sunday-based, week 54, 3 month 47 12 13 14 15 16 17 18 51 10 11 12 13 14 15 16 3 14 15 16 17 18 19 20 48 19 20 21 22 23 24 25 52 17 18 19 20 21 22 23 4 21 22 23 24 25 26 27 49 26 27 28 29 30 53 24 25 26 27 28 29 30 5 28 29 30 31 - 54 31 + 54 31