@@ -62,6 +62,10 @@ void RichString_rewind(RichString* this, int count) {
6262   RichString_setLen (this , this -> chlen  -  count );
6363}
6464
65+ void  RichString_setAttr_preserveWithStandout (RichString *  this , int  attrs ) {
66+    RichString_setAttrn_preserveWithStandout (this , attrs , 0 , this -> chlen  -  1 );
67+ }
68+ 
6569#ifdef  HAVE_LIBNCURSESW 
6670
6771static  size_t  mbstowcs_nonfatal (wchar_t *  restrict dest , const  char *  restrict src , size_t  n ) {
@@ -160,6 +164,41 @@ inline void RichString_setAttrn(RichString* this, int attrs, int start, int char
160164   }
161165}
162166
167+ void  RichString_setAttrn_preserveWithStandout (RichString *  this , int  attrs , int  start , int  finish ) {
168+    finish  =  CLAMP (finish , 0 , this -> chlen  -  1 );
169+ 
170+    // Extract the foreground and background color indexes from the passed attrs 
171+    short  passed_color_pair_number  =  (short )PAIR_NUMBER (attrs );
172+    short  passed_fg_color  =  -1 , passed_bg_color  =  -1 ;
173+    if  (passed_color_pair_number  !=  0 ) {
174+       pair_content (passed_color_pair_number , & passed_fg_color , & passed_bg_color );
175+    }
176+ 
177+    cchar_t *  ch  =  this -> chptr  +  start ;
178+    for  (int  i  =  start ; i  <= finish ; i ++ ) {
179+       // Extract foreground and background color indexes from the current char 
180+       short  currentCharPairNum  =  (short )PAIR_NUMBER (ch -> attr );
181+       short  before_fg_color  =  -1 , before_bg_color  =  -1 ;
182+       if  (currentCharPairNum  !=  0 ) {
183+          pair_content (currentCharPairNum , & before_fg_color , & before_bg_color );
184+       }
185+ 
186+       // TODO: When text color matches higlight, the resulting STANDOUT is the same as on default text, 
187+       //       so we at least set italics 
188+       chtype  attrToPass  =  A_STANDOUT ;
189+       if  (before_fg_color  ==  passed_bg_color ) {
190+          attrToPass  |= A_ITALIC ;
191+       }
192+       // If current char is not a space and its ColorPair Index is not the default 0, 
193+       //    apply our own attrToPass with STANDOUT + optionally ITALICS, 
194+       //    instead of the passed attrs, which has the BG highlight color 
195+       ch -> attr  =  (ch -> chars [0 ] !=  L' '  &&  currentCharPairNum  !=  0 )
196+                   ? (ch -> attr  | attrToPass )
197+                   : (unsigned int  )attrs ;
198+       ch ++ ;
199+    }
200+ }
201+ 
163202void  RichString_appendChr (RichString *  this , int  attrs , char  c , int  count ) {
164203   int  from  =  this -> chlen ;
165204   int  newLen  =  from  +  count ;
@@ -210,6 +249,41 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int charcount)
210249   }
211250}
212251
252+ void  RichString_setAttrn_preserveWithStandout (RichString *  this , int  attrs , int  start , int  finish ) {
253+    finish  =  CLAMP (finish , 0 , this -> chlen  -  1 );
254+ 
255+    // Extract the foreground and background color indexes from the passed attrs 
256+    short  passed_color_pair_number  =  (short )PAIR_NUMBER (attrs );
257+    short  passed_fg_color  =  -1 , passed_bg_color  =  -1 ;
258+    if  (passed_color_pair_number  !=  0 ) {
259+       pair_content (passed_color_pair_number , & passed_fg_color , & passed_bg_color );
260+    }
261+ 
262+    chtype *  ch  =  this -> chptr  +  start ;
263+    for  (int  i  =  start ; i  <= finish ; i ++ ) {
264+       // Extract foreground and background color indexes from the current char 
265+       short  currentCharPairNum  =  (short )PAIR_NUMBER (* ch );
266+       short  before_fg_color  =  -1 , before_bg_color  =  -1 ;
267+       if  (currentCharPairNum  !=  0 ) {
268+          pair_content (currentCharPairNum , & before_fg_color , & before_bg_color );
269+       }
270+ 
271+       // TODO: When text color matches higlight, the resulting STANDOUT is the same as on default text, 
272+       //       so we at least set italics 
273+       chtype  attrToPass  =  A_STANDOUT ;
274+       if  (before_fg_color  ==  passed_bg_color ) {
275+          attrToPass  |= A_ITALIC ;
276+       }
277+       // If current char is not a space and its ColorPair Index is not the default 0, 
278+       //    apply our own attrToPass with STANDOUT + optionally ITALICS, 
279+       //    instead of the passed attrs, which has the BG highlight color 
280+       * ch  =  ((* ch  &  A_CHARTEXT ) !=  L' '  &&  currentCharPairNum  !=  0 )
281+             ? * ch  | attrToPass 
282+             : (* ch  &  A_CHARTEXT ) | (unsigned int  )attrs ;
283+       ch ++ ;
284+    }
285+ }
286+ 
213287void  RichString_appendChr (RichString *  this , int  attrs , char  c , int  count ) {
214288   int  from  =  this -> chlen ;
215289   int  newLen  =  from  +  count ;
0 commit comments