@@ -33,8 +33,22 @@ static struct {
33
33
int pfx_end ; /* Number of chars in pfx */
34
34
} linebuf ;
35
35
36
+ /*
37
+ * Buffer of ansi sequences which have been shifted off the left edge
38
+ * of the screen.
39
+ */
36
40
struct xbuffer shifted_ansi ;
37
- struct xbuffer last_ansi ;
41
+
42
+ /*
43
+ * Ring buffer of last ansi sequences sent.
44
+ * While sending a line, these will be resent at the end
45
+ * of any hilighted string, to restore text modes.
46
+ * {{ Not ideal, since we don't really know how many to resend. }}
47
+ */
48
+ #define NUM_LAST_ANSIS 3
49
+ static struct xbuffer last_ansi ;
50
+ static struct xbuffer last_ansis [NUM_LAST_ANSIS ];
51
+ static int curr_last_ansi ;
38
52
39
53
public int size_linebuf = 0 ; /* Size of line buffer (and attr buffer) */
40
54
static struct ansi_state * line_ansi = NULL ;
@@ -123,6 +137,8 @@ struct ansi_state {
123
137
public void
124
138
init_line (VOID_PARAM )
125
139
{
140
+ int ax ;
141
+
126
142
end_ansi_chars = lgetenv ("LESSANSIENDCHARS" );
127
143
if (isnullenv (end_ansi_chars ))
128
144
end_ansi_chars = "m" ;
@@ -136,6 +152,9 @@ init_line(VOID_PARAM)
136
152
size_linebuf = LINEBUF_SIZE ;
137
153
xbuf_init (& shifted_ansi );
138
154
xbuf_init (& last_ansi );
155
+ for (ax = 0 ; ax < NUM_LAST_ANSIS ; ax ++ )
156
+ xbuf_init (& last_ansis [ax ]);
157
+ curr_last_ansi = 0 ;
139
158
}
140
159
141
160
/*
@@ -208,6 +227,8 @@ inc_end_column(w)
208
227
public void
209
228
prewind (VOID_PARAM )
210
229
{
230
+ int ax ;
231
+
211
232
linebuf .print = 6 ; /* big enough for longest UTF-8 sequence */
212
233
linebuf .pfx_end = 0 ;
213
234
for (linebuf .end = 0 ; linebuf .end < linebuf .print ; linebuf .end ++ )
@@ -231,6 +252,9 @@ prewind(VOID_PARAM)
231
252
line_mark_attr = 0 ;
232
253
xbuf_reset (& shifted_ansi );
233
254
xbuf_reset (& last_ansi );
255
+ for (ax = 0 ; ax < NUM_LAST_ANSIS ; ax ++ )
256
+ xbuf_reset (& last_ansis [ax ]);
257
+ curr_last_ansi = 0 ;
234
258
}
235
259
236
260
/*
@@ -735,8 +759,13 @@ store_char(ch, a, rep, pos)
735
759
}
736
760
if (resend_last )
737
761
{
738
- for (i = 0 ; i < last_ansi .end ; i ++ )
739
- STORE_CHAR (last_ansi .data [i ], AT_ANSI , NULL , pos );
762
+ int ai ;
763
+ for (ai = 0 ; ai < NUM_LAST_ANSIS ; ai ++ )
764
+ {
765
+ int ax = (curr_last_ansi + ai ) % NUM_LAST_ANSIS ;
766
+ for (i = 0 ; i < last_ansis [ax ].end ; i ++ )
767
+ STORE_CHAR (last_ansis [ax ].data [i ], AT_ANSI , NULL , pos );
768
+ }
740
769
}
741
770
}
742
771
#endif
@@ -1019,12 +1048,17 @@ store_ansi(ch, rep, pos)
1019
1048
STORE_CHAR (ch , AT_ANSI , rep , pos );
1020
1049
if (line_ansi -> hlink )
1021
1050
hlink_in_line = 1 ;
1051
+ xbuf_add (& last_ansi , ch );
1022
1052
break ;
1023
1053
case ANSI_END :
1024
1054
if (!in_hilite )
1025
1055
STORE_CHAR (ch , AT_ANSI , rep , pos );
1026
1056
ansi_done (line_ansi );
1027
1057
line_ansi = NULL ;
1058
+ xbuf_add (& last_ansi , ch );
1059
+ xbuf_set (& last_ansis [curr_last_ansi ], & last_ansi );
1060
+ xbuf_reset (& last_ansi );
1061
+ curr_last_ansi = (curr_last_ansi + 1 ) % NUM_LAST_ANSIS ;
1028
1062
break ;
1029
1063
case ANSI_ERR :
1030
1064
if (!in_hilite )
@@ -1039,6 +1073,7 @@ store_ansi(ch, rep, pos)
1039
1073
} while (p > start && !IS_CSI_START (bch ));
1040
1074
* end = (int ) (p - start );
1041
1075
}
1076
+ xbuf_reset (& last_ansi );
1042
1077
ansi_done (line_ansi );
1043
1078
line_ansi = NULL ;
1044
1079
break ;
@@ -1077,17 +1112,11 @@ do_append(ch, rep, pos)
1077
1112
{
1078
1113
line_ansi = ansi_start (ch );
1079
1114
if (line_ansi != NULL )
1080
- {
1081
- xbuf_reset (& last_ansi );
1082
1115
ansi_in_line = 1 ;
1083
- }
1084
1116
}
1085
1117
1086
1118
if (line_ansi != NULL )
1087
- {
1088
- xbuf_add (& last_ansi , ch );
1089
1119
return store_ansi (ch , rep , pos );
1090
- }
1091
1120
1092
1121
if (ch == '\b' )
1093
1122
return store_bs (ch , rep , pos );
0 commit comments