@@ -227,6 +227,7 @@ public int missing_cap = 0; /* Some capability is missing */
227
227
public char * kent = NULL ; /* Keypad ENTER sequence */
228
228
229
229
static int attrmode = AT_NORMAL ;
230
+ static int attrcolor = -1 ;
230
231
static int termcap_debug = -1 ;
231
232
extern int binattr ;
232
233
extern int one_screen ;
@@ -831,21 +832,21 @@ scrsize(VOID_PARAM)
831
832
#endif
832
833
#endif
833
834
834
- if (sys_height > 0 )
835
- sc_height = sys_height ;
836
- else if ((s = lgetenv ("LINES" )) != NULL )
835
+ if ((s = lgetenv ("LINES" )) != NULL )
837
836
sc_height = atoi (s );
837
+ else if (sys_height > 0 )
838
+ sc_height = sys_height ;
838
839
#if !MSDOS_COMPILER
839
840
else if ((n = ltgetnum ("li" )) > 0 )
840
841
sc_height = n ;
841
842
#endif
842
843
if (sc_height <= 0 )
843
844
sc_height = DEF_SC_HEIGHT ;
844
845
845
- if (sys_width > 0 )
846
- sc_width = sys_width ;
847
- else if ((s = lgetenv ("COLUMNS" )) != NULL )
846
+ if ((s = lgetenv ("COLUMNS" )) != NULL )
848
847
sc_width = atoi (s );
848
+ else if (sys_width > 0 )
849
+ sc_width = sys_width ;
849
850
#if !MSDOS_COMPILER
850
851
else if ((n = ltgetnum ("co" )) > 0 )
851
852
sc_width = n ;
@@ -1593,6 +1594,19 @@ win32_deinit_term(VOID_PARAM)
1593
1594
#endif
1594
1595
1595
1596
#if !MSDOS_COMPILER
1597
+ static void
1598
+ do_tputs (str , affcnt , f_putc )
1599
+ char * str ;
1600
+ int affcnt ;
1601
+ int (* f_putc )(int );
1602
+ {
1603
+ #if LESSTEST
1604
+ putstr (str );
1605
+ #else
1606
+ tputs (str , affcnt , f_putc );
1607
+ #endif
1608
+ }
1609
+
1596
1610
/*
1597
1611
* Like tputs but we handle $<...> delay strings here because
1598
1612
* some implementations of tputs don't perform delays correctly.
@@ -1617,7 +1631,7 @@ ltputs(str, affcnt, f_putc)
1617
1631
/* Output first part of string (before "$<"). */
1618
1632
memcpy (str2 , str , slen );
1619
1633
str2 [slen ] = '\0' ;
1620
- tputs (str2 , affcnt , f_putc );
1634
+ do_tputs (str2 , affcnt , f_putc );
1621
1635
str += slen + 2 ;
1622
1636
/* Perform the delay. */
1623
1637
delay = lstrtoi (str , & str );
@@ -1634,7 +1648,7 @@ ltputs(str, affcnt, f_putc)
1634
1648
}
1635
1649
#endif
1636
1650
/* Pass the rest of the string to tputs and we're done. */
1637
- tputs (str , affcnt , f_putc );
1651
+ do_tputs (str , affcnt , f_putc );
1638
1652
break ;
1639
1653
}
1640
1654
}
@@ -2494,82 +2508,96 @@ sgr_color(color)
2494
2508
}
2495
2509
}
2496
2510
2497
- static int
2498
- tput_fmt (fmt , val , f_putc )
2511
+ static void
2512
+ tput_fmt (fmt , color , f_putc )
2499
2513
char * fmt ;
2500
- int val ;
2514
+ int color ;
2501
2515
int (* f_putc )(int );
2502
2516
{
2503
2517
char buf [16 ];
2504
- SNPRINTF1 (buf , sizeof (buf ), fmt , val );
2518
+ if (color == attrcolor )
2519
+ return ;
2520
+ SNPRINTF1 (buf , sizeof (buf ), fmt , color );
2505
2521
ltputs (buf , 1 , f_putc );
2506
- return TRUE ;
2522
+ attrcolor = color ;
2507
2523
}
2508
2524
2509
- public int
2525
+ static void
2510
2526
tput_color (str , f_putc )
2511
2527
char * str ;
2512
2528
int (* f_putc )(int );
2513
2529
{
2514
2530
char buf [16 ];
2515
2531
int fg ;
2516
2532
int bg ;
2517
- int out = FALSE;
2518
2533
2519
2534
if (str != NULL && strcmp (str , "*" ) == 0 )
2520
2535
{
2521
2536
/* Special case: reset to normal */
2522
- ltputs (ESCS "[m" , 1 , f_putc );
2523
- return TRUE ;
2537
+ tput_fmt (ESCS "[m" , - 1 , f_putc );
2538
+ return ;
2524
2539
}
2525
2540
switch (parse_color (str , & fg , & bg ))
2526
2541
{
2527
2542
case CT_4BIT :
2528
2543
if (fg >= 0 )
2529
- out = tput_fmt (ESCS "[%dm" , sgr_color (fg ), f_putc );
2544
+ tput_fmt (ESCS "[%dm" , sgr_color (fg ), f_putc );
2530
2545
if (bg >= 0 )
2531
- out = tput_fmt (ESCS "[%dm" , sgr_color (bg )+ 10 , f_putc );
2546
+ tput_fmt (ESCS "[%dm" , sgr_color (bg )+ 10 , f_putc );
2532
2547
break ;
2533
2548
case CT_6BIT :
2534
2549
if (fg >= 0 )
2535
- out = tput_fmt (ESCS "[38;5;%dm" , fg , f_putc );
2550
+ tput_fmt (ESCS "[38;5;%dm" , fg , f_putc );
2536
2551
if (bg >= 0 )
2537
- out = tput_fmt (ESCS "[48;5;%dm" , bg , f_putc );
2552
+ tput_fmt (ESCS "[48;5;%dm" , bg , f_putc );
2538
2553
break ;
2539
2554
default :
2540
2555
break ;
2541
2556
}
2542
- return out ;
2543
2557
}
2544
2558
2545
- static int
2546
- tput_mode (mode_str , str , f_putc )
2559
+ static void
2560
+ tput_inmode (mode_str , attr , attr_bit , f_putc )
2547
2561
char * mode_str ;
2548
- char * str ;
2562
+ int attr ;
2563
+ int attr_bit ;
2549
2564
int (* f_putc )(int );
2550
2565
{
2551
- if (str == NULL || * str == '\0' || * str == '+' )
2566
+ char * color_str ;
2567
+ if ((attr & attr_bit ) == 0 )
2568
+ return ;
2569
+ color_str = get_color_map (attr_bit );
2570
+ if (color_str == NULL || * color_str == '\0' || * color_str == '+' )
2552
2571
{
2553
2572
ltputs (mode_str , 1 , f_putc );
2554
- if (* str != '+' )
2555
- return TRUE;
2556
- str ++ ;
2573
+ if (color_str == NULL || * color_str ++ != '+' )
2574
+ return ;
2557
2575
}
2558
2576
/* Color overrides mode string */
2559
- return tput_color (str , f_putc );
2577
+ tput_color (color_str , f_putc );
2560
2578
}
2561
2579
2580
+ static void
2581
+ tput_outmode (mode_str , attr_bit , f_putc )
2582
+ char * mode_str ;
2583
+ int attr_bit ;
2584
+ int (* f_putc )(int );
2585
+ {
2586
+ if ((attrmode & attr_bit ) == 0 )
2587
+ return ;
2588
+ ltputs (mode_str , 1 , f_putc );
2589
+ }
2562
2590
2563
2591
#else /* MSDOS_COMPILER */
2564
2592
2565
2593
#if MSDOS_COMPILER == WIN32C
2566
2594
static int
2567
- WIN32put_fmt (fmt , val )
2595
+ WIN32put_fmt (fmt , color )
2568
2596
char * fmt ;
2569
- int val ;
2597
+ int color ;
2570
2598
{
2571
2599
char buf [16 ];
2572
- int len = SNPRINTF1 (buf , sizeof (buf ), fmt , val );
2600
+ int len = SNPRINTF1 (buf , sizeof (buf ), fmt , color );
2573
2601
WIN32textout (buf , len );
2574
2602
return TRUE;
2575
2603
}
@@ -2626,67 +2654,54 @@ at_enter(attr)
2626
2654
int attr ;
2627
2655
{
2628
2656
attr = apply_at_specials (attr );
2629
-
2630
2657
#if !MSDOS_COMPILER
2631
2658
/* The one with the most priority is last. */
2632
- if ((attr & AT_UNDERLINE ) && tput_mode (sc_u_in , get_color_map (AT_UNDERLINE ), putchr ))
2633
- attrmode |= AT_UNDERLINE ;
2634
- if ((attr & AT_BOLD ) && tput_mode (sc_b_in , get_color_map (AT_BOLD ), putchr ))
2635
- attrmode |= AT_BOLD ;
2636
- if ((attr & AT_BLINK ) && tput_mode (sc_bl_in , get_color_map (AT_BLINK ), putchr ))
2637
- attrmode |= AT_BLINK ;
2659
+ tput_inmode (sc_u_in , attr , AT_UNDERLINE , putchr );
2660
+ tput_inmode (sc_b_in , attr , AT_BOLD , putchr );
2661
+ tput_inmode (sc_bl_in , attr , AT_BLINK , putchr );
2638
2662
/* Don't use standout and color at the same time. */
2639
- if (( attr & AT_COLOR ) && use_color && tput_color ( get_color_map ( attr ), putchr ))
2640
- attrmode |= ( attr & AT_COLOR );
2641
- else if (( attr & AT_STANDOUT ) && tput_mode ( sc_s_in , get_color_map ( AT_STANDOUT ), putchr ))
2642
- attrmode |= AT_STANDOUT ;
2663
+ if (use_color && ( attr & AT_COLOR ))
2664
+ tput_color ( get_color_map ( attr ), putchr );
2665
+ else
2666
+ tput_inmode ( sc_s_in , attr , AT_STANDOUT , putchr ) ;
2643
2667
#else
2644
2668
flush ();
2645
2669
/* The one with the most priority is first. */
2646
2670
if ((attr & AT_COLOR ) && use_color )
2647
2671
{
2648
2672
win_set_color (attr );
2649
- attrmode = AT_COLOR ;
2650
2673
} else if (attr & AT_STANDOUT )
2651
2674
{
2652
2675
SETCOLORS (so_fg_color , so_bg_color );
2653
- attrmode = AT_STANDOUT ;
2654
2676
} else if (attr & AT_BLINK )
2655
2677
{
2656
2678
SETCOLORS (bl_fg_color , bl_bg_color );
2657
- attrmode = AT_BLINK ;
2658
2679
} else if (attr & AT_BOLD )
2659
2680
{
2660
2681
SETCOLORS (bo_fg_color , bo_bg_color );
2661
- attrmode = AT_BOLD ;
2662
2682
} else if (attr & AT_UNDERLINE )
2663
2683
{
2664
2684
SETCOLORS (ul_fg_color , ul_bg_color );
2665
- attrmode = AT_UNDERLINE ;
2666
2685
}
2667
2686
#endif
2687
+ attrmode = attr ;
2668
2688
}
2669
2689
2670
2690
public void
2671
2691
at_exit (VOID_PARAM )
2672
2692
{
2673
2693
#if !MSDOS_COMPILER
2674
2694
/* Undo things in the reverse order we did them. */
2675
- if ((attrmode & AT_COLOR ) && tput_color ("*" , putchr ))
2676
- attrmode &= ~AT_COLOR ;
2677
- if ((attrmode & AT_STANDOUT ) && tput_mode (sc_s_out , "*" , putchr ))
2678
- attrmode &= ~AT_STANDOUT ;
2679
- if ((attrmode & AT_BLINK ) && tput_mode (sc_bl_out , "*" , putchr ))
2680
- attrmode &= ~AT_BLINK ;
2681
- if ((attrmode & AT_BOLD ) && tput_mode (sc_b_out , "*" , putchr ))
2682
- attrmode &= ~AT_BOLD ;
2683
- if ((attrmode & AT_UNDERLINE ) && tput_mode (sc_u_out , "*" , putchr ))
2684
- attrmode &= ~AT_UNDERLINE ;
2695
+ tput_color ("*" , putchr );
2696
+ tput_outmode (sc_s_out , AT_STANDOUT , putchr );
2697
+ tput_outmode (sc_bl_out , AT_BLINK , putchr );
2698
+ tput_outmode (sc_b_out , AT_BOLD , putchr );
2699
+ tput_outmode (sc_u_out , AT_UNDERLINE , putchr );
2685
2700
#else
2686
2701
flush ();
2687
2702
SETCOLORS (nm_fg_color , nm_bg_color );
2688
- attrmode = AT_NORMAL ;
2689
2703
#endif
2704
+ attrmode = AT_NORMAL ;
2690
2705
}
2691
2706
2692
2707
public void
0 commit comments