bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New feature - menu item formatting


From: Thomas Dickey
Subject: Re: New feature - menu item formatting
Date: Mon, 5 Oct 2015 20:40:28 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Oct 03, 2015 at 01:20:16AM +0200, address@hidden wrote:
> Hello,
> 
> Im new on this ML, so sorry for any mistakes...
> 
> Long story short:
> I was wandering if menu items can be formatted autonomously, but sadly there 
> is no set_item* API for this purpose. So I went and made terrible hack in 
> /ncurses/base/MKunctrl.awk to allow passing ANSI control sequences in menu 
> strings. That actually was partially successful, but unstable and not 
> portable.
> 
> Another try goes directly to menu library, it works for my purposes, so I 
> would like to present you with the result (and possibly get merged?)
> 
> Quick description:
> 
> 1) new field in menu.h:
>   tagITEM - unsigned int attr; /* Item attributes */
> 
> 2) New functions introduced:
>   set_item_attr() /* Set attribute as attron() does */
>   item_attr() /* Return current attributes of the item */
> 
> 3) Patched _nc_Post_Item() to actually format the item
> 
> Diff files are attached.
> Any comments welcomed.
> 
> Best regards,
> Martin Sacha

> 84a85
> >     unsigned int   attr;        /* Item attributes via attron()             
> >  */

I see (thanks).

> 250a252,254
> > 
> > extern NCURSES_EXPORT(int)  set_item_attr(ITEM *,unsigned int);
> > extern NCURSES_EXPORT(int)  item_attr(ITEM *);

> 158a159,193
> > /*-------------------------------------------------------------------------
> > |   Facility      :  libnmenu
> > |   Function      :  int set_item_attr(ITEM *item,unsigned int attr)
> > |
> > |   Description   :  Set item attributes via attron().
> > |
> > |   Return values :  E_OK            - success
> > |                 :  E_BAD_ARGUMENT  - invalid ITEM
> > +-------------------------------------------------------------------------*/
> > //NCURSES_EXPORT(int)
> > set_item_attr(ITEM *item,unsigned int attr)
> > {
> >   if(!item)
> >     RETURN(E_BAD_ARGUMENT);
> >     item->attr=attr;
> >     RETURN(E_OK);
> > }
> > 
> > /*------------------------------------------------------------------------
> > |   Facility      :  libmenu
> > |   Function      :  unsigned int item_attr(ITEM *item)
> > |
> > |   Description   :  Get item attributes
> > |
> > |   Return values :  E_OK            - success
> > |                 :  E_BAD_ARGUMENT  - invalid ITEM
> > +------------------------------------------------------------------------*/
> > //NCURSES_EXPORT(unsigned int)
> > item_attr(ITEM *item)
> > {
> >     if(!item)
> >             RETURN(E_BAD_ARGUMENT);
> >     return item->attr;
> > }
> > 

> 70a71
> >     wattron(menu->win, (int)item->attr);
> 188a190,191
> >     if (item->attr)
> >             wattroff(menu->win, (int)item->attr);

Besides the ABI difference, if item->attr would override menu->back
(possibly merging, but perhaps not as simple as this patch)

-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]