28 #include <ncursesw/ncurses.h>
48 inline static int colors() {
return _colors ? _colors : ::COLORS; }
51 inline static int color_pairs() {
return _pairs ? _pairs : ::COLOR_PAIRS; }
57 inline static chtype color_pair(
short fg,
short bg ) {
return colors() ? COLOR_PAIR( bg * colors() + COLOR_WHITE - fg ) : A_NORMAL; }
59 inline static chtype color_pair(
int i ) {
return colors() ? COLOR_PAIR( i ) : A_NORMAL; }
61 inline static short fg_color_pair(
int i ) {
return colors() ? ( COLOR_WHITE - ( i % colors() ) ) : -1; }
63 inline static short bg_color_pair(
int i ) {
return colors() ? ( i / colors() ) : -1; }
68 inline static int color_pair_of( chtype ch ) {
return PAIR_NUMBER( ch ); }
70 inline static short fg_color_of( chtype ch ) {
return fg_color_pair( color_pair_of( ch ) ); }
72 inline static short bg_color_of( chtype ch ) {
return bg_color_pair( color_pair_of( ch ) ); }
77 static const chtype style_mask = A_ATTRIBUTES & ~A_COLOR & ~A_ALTCHARSET;
78 static const chtype color_mask = A_COLOR;
79 static const chtype char_mask = A_CHARTEXT | A_ALTCHARSET;
81 inline static chtype getStyle( chtype a ) {
return a & style_mask; }
83 inline static chtype getColor( chtype a ) {
return a & color_mask; }
85 inline static chtype getChar( chtype a ) {
return a & char_mask; }
87 inline static chtype getNonChar( chtype a ) {
return a & ~char_mask; }
89 inline static void setStyle( chtype & a, chtype ch ) { a = ( a & ~style_mask ) | ( ch & style_mask ); }
91 inline static void setColor( chtype & a, chtype ch ) {
if ( colors() ) a = ( a & ~color_mask ) | ( ch & color_mask ); }
93 inline static void setChar( chtype & a, chtype ch ) { a = ( a & ~char_mask ) | ( ch & char_mask ); }
95 inline static void addStyle( chtype & a, chtype ch ) { a = a | ( ch & style_mask ); }
97 inline static void delStyle( chtype & a, chtype ch ) { a = a & ~( ch & style_mask ); }
99 inline static void toggleStyle( chtype & a, chtype ch ) { setStyle( a, ( a & ~ch ) | (( a ^ ch ) & ch ) ); }
101 inline static void addAlt( chtype & a ) { a |= A_ALTCHARSET; }
103 inline static void delAlt( chtype & a ) { a &= ~A_ALTCHARSET; }
106 inline static short getFg( chtype a ) {
return fg_color_of( a ); }
108 inline static short getBg( chtype a ) {
return bg_color_of( a ); }
110 inline static void setFg( chtype & a,
short c ) {
if ( colors() ) setColor( a, color_pair(( colors() + c ) % colors(), getBg( a ) ) ); }
112 inline static void setBg( chtype & a,
short c ) {
if ( colors() ) setColor( a, color_pair( getFg( a ), ( colors() + c ) % colors() ) ); }
121 #define OUTS(X) case COLOR_##X: return #X
138 return std::string(
"[" ) +
colorAsString( fg_color_pair( i ) )
146 static void init_colors()
153 _pairs = ::COLOR_PAIRS;
159 if ( _colors > COLOR_WHITE + 1 )
161 _colors = COLOR_WHITE + 1;
163 if ( _pairs > _colors * _colors )
165 _pairs = _colors * _colors;
167 for (
short i = 1; i < color_pairs(); ++i )
168 ::init_pair( i, fg_color_pair( i ), bg_color_pair( i ) );
179 std::vector<chtype> attr;
183 NCattrset(
unsigned num ) : attr( num, A_NORMAL ) {}
189 const chtype & operator[](
unsigned a )
const {
return attr[a]; }
191 chtype getAttr(
unsigned a )
const {
return attr[a]; }
193 chtype getStyle(
unsigned a )
const {
return NCattribute::getStyle( attr[a] ); }
195 chtype getColor(
unsigned a )
const {
return NCattribute::getColor( attr[a] ); }
197 chtype getChar(
unsigned a )
const {
return NCattribute::getChar( attr[a] ); }
199 chtype getNonChar(
unsigned a )
const {
return NCattribute::getNonChar( attr[a] ); }
201 void setAttr(
unsigned a, chtype ch ) { attr[a] = ch; }
203 void setStyle(
unsigned a, chtype ch ) { NCattribute::setStyle( attr[a], ch ); }
205 void setColor(
unsigned a, chtype ch ) { NCattribute::setColor( attr[a], ch ); }
207 void setChar(
unsigned a, chtype ch ) { NCattribute::setChar( attr[a], ch ); }
209 void addStyle(
unsigned a, chtype ch ) { NCattribute::addStyle( attr[a], ch ); }
211 void delStyle(
unsigned a, chtype ch ) { NCattribute::delStyle( attr[a], ch ); }
213 void toggleStyle(
unsigned a, chtype ch ) { NCattribute::toggleStyle( attr[a], ch ); }
215 void addAlt(
unsigned a ) { NCattribute::addAlt( attr[a] ); }
217 void delAlt(
unsigned a ) { NCattribute::delAlt( attr[a] ); }
221 short getFg(
unsigned a )
const {
return NCattribute::getFg( attr[a] ); }
223 short getBg(
unsigned a )
const {
return NCattribute::getBg( attr[a] ); }
225 void setFg(
unsigned a,
short c ) { NCattribute::setFg( attr[a], c ); }
227 void setBg(
unsigned a,
short c ) { NCattribute::setBg( attr[a], c ); }
275 DialogActiveFramePlain,
276 DialogActiveFrameLabel,
277 DialogActiveFrameData,
278 DialogActiveFrameHint,
279 DialogActiveFrameScrl,
305 RichTextActiveArmedlink,
327 const chtype & title;
329 StBase(
const chtype & ti,
const chtype & te )
330 : title( ti ), text( te )
336 const chtype & chattr;
337 chtype getChar()
const {
return NCattribute::getChar( chattr ); }
339 chtype getNonChar()
const {
return NCattribute::getNonChar( chattr ); }
341 STChar(
const chtype & cha )
348 const chtype & plain;
349 const chtype & label;
352 StItem(
const chtype & p,
const chtype & l,
const chtype & d,
const chtype & h )
353 : plain( p ), label( l ), data( d ), hint( h )
360 StWidget(
const chtype & p,
const chtype & l,
const chtype & d,
const chtype & h,
362 :
StItem( p, l, d, h ), scrl( s )
368 const chtype & title;
372 : title( t ), item( i ), selected( s )
375 const StItem & getItem(
bool sel )
const {
return sel ? selected : item; }
382 StProgbar(
const chtype & b,
const chtype & nb )
383 : bar( b ), nonbar( nb )
389 const chtype & plain;
390 const chtype & title;
392 const chtype & armedlink;
393 const chtype & activearmedlink;
394 const chtype & visitedlink;
403 StRichtext(
const chtype & p,
const chtype & tit,
404 const chtype & l,
const chtype & al,
const chtype & aal,
const chtype & vl,
405 const chtype & b,
const chtype & i,
const chtype & t,
406 const chtype & bi,
const chtype & bt,
const chtype & it,
408 : plain( p ), title( tit ),
409 link( l ), armedlink( al ), activearmedlink( aal ), visitedlink( vl ),
410 B( b ), I( i ), T( t ),
411 BI( bi ), BT( bt ), IT( it ),
415 const chtype & getArmed( NC::WState s )
const
417 return ( s == NC::WSactive ) ? activearmedlink : armedlink;
436 const chtype & cursor;
444 const chtype & curs )
445 : border( b ), activeBorder( ab ), dumb( d ), disabled( dis ),
446 normal( n ), active( a ),
447 frame( f ), activeFrame( af ),
448 list( l ), activeList( al ), disabledList( dl ),
456 const StBase & getDlgBorder(
bool active )
const {
return active ? activeBorder : border; }
458 const StBase & getDumb()
const {
return dumb; }
460 const StWidget & getWidget( NC::WState s,
bool nonactive =
false )
const
465 case NC::WSdisabeled:
469 return nonactive ? normal : active;
480 const StWidget & getFrame( NC::WState s )
const
485 case NC::WSdisabeled:
500 const StList & getList( NC::WState s )
const
505 case NC::WSdisabeled:
533 static unsigned sanitycheck();
538 NCattrset & getAttrGlobal() {
return attrGlobal; }
540 NCattrset & getAttrLocal() {
return *
this; }
554 const chtype & attr( STglobal a )
const {
return attrGlobal[a]; }
556 const chtype & attr( STlocal a )
const {
return NCattrset::operator[]( a ); }
558 const chtype & operator()( STglobal a )
const {
return attr( a ); }
560 const chtype & operator()( STlocal a )
const {
return attr( a ); }
577 std::string styleName;
579 std::vector<Style> styleSet;
581 StyleSet fakestyle_e;
582 void fakestyle( StyleSet f );
583 Style & getStyle( StyleSet a ) {
return styleSet[a]; }
590 const chtype & operator()( STglobal a )
const {
return Style::attrGlobal[a]; }
592 const Style & operator[]( StyleSet a )
const
594 if ( fakestyle_e != MaxStyleSet )
595 return styleSet[fakestyle_e];
603 static std::string dumpName( StyleSet a );
604 static std::string dumpName( STglobal a );
605 static std::string dumpName( STlocal a );
static std::string color_pairAsString(int i)
static std::string colorAsString(short i)