fix setting format flags in Window::operator<<(Format)

I though static variables are created for each class object,
but apparently they aren't, which makes the previous design
utterly broken. I'm suprised it somehow worked before.
This commit is contained in:
Andrzej Rybczak
2009-07-12 15:42:30 +02:00
parent c20d8694ae
commit 26326de2c8
4 changed files with 25 additions and 25 deletions

View File

@@ -139,7 +139,6 @@ int main(int argc, char *argv[])
wFooter->SetTimeout(ncmpcpp_window_timeout);
wFooter->SetGetStringHelper(StatusbarGetStringHelper);
wFooter->CreateHistory();
*wFooter << fmtBold; // bold by default
myPlaylist->SwitchTo();
myPlaylist->UpdateTimer();
@@ -1072,7 +1071,7 @@ int main(int argc, char *argv[])
songpos = 0;
}
wFooter->Bold(1);
*wFooter << fmtBold;
std::string tracklength = "[" + Song::ShowTime(songpos) + "/" + s->GetLength() + "]";
*wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
double progressbar_size = songpos/double(s->GetTotalLength());
@@ -1081,7 +1080,7 @@ int main(int argc, char *argv[])
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
mvwhline(wFooter->Raw(), 0, 0, '=',howlong);
mvwaddch(wFooter->Raw(), 0, howlong, '>');
wFooter->Bold(0);
*wFooter << fmtBoldEnd;
wFooter->Refresh();
}
Mpd.Seek(songpos);

View File

@@ -173,7 +173,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
static MPD::Song np;
int sx, sy;
wFooter->Bold(1);
*wFooter << fmtBold;
wFooter->GetXY(sx, sy);
if ((myPlaylist->NowPlaying != Mpd.GetCurrentSongPos() || changed.SongID) && !Playlist::BlockNowPlayingUpdate)
@@ -525,7 +525,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
}
if (myScreen == myPlaylist && !Playlist::BlockRefreshing)
myPlaylist->Main()->Refresh();
wFooter->Bold(0);
*wFooter << fmtBoldEnd;
wFooter->GotoXY(sx, sy);
wFooter->Refresh();
}
@@ -547,14 +547,13 @@ void ShowMessage(const char *format, ...)
else
block_progressbar_update = 1;
wFooter->GotoXY(0, Config.statusbar_visibility);
wFooter->Bold(0);
*wFooter << fmtBoldEnd;
va_list list;
va_start(list, format);
wmove(wFooter->Raw(), Config.statusbar_visibility, 0);
vw_printw(wFooter->Raw(), format, list);
wclrtoeol(wFooter->Raw());
va_end(list);
wFooter->Bold(1);
wFooter->Refresh();
}
}

View File

@@ -91,7 +91,10 @@ Window::Window(size_t startx,
itsBgColor(clDefault),
itsBaseBgColor(clDefault),
itsBorder(border),
itsHistory(0)
itsHistory(0),
itsBoldCounter(0),
itsReverseCounter(0),
itsAltCharsetCounter(0)
{
if (itsStartX > size_t(COLS)
|| itsStartY > size_t(LINES)
@@ -756,38 +759,33 @@ Window &Window::operator<<(Color color)
Window &Window::operator<<(Format format)
{
static int bold_num = 0, reverse_num = 0, altcharset_num = 0;
switch (format)
{
case fmtNone:
Bold((bold_num = 0));
Reverse((reverse_num = 0));
AltCharset((altcharset_num = 0));
Bold((itsBoldCounter = 0));
Reverse((itsReverseCounter = 0));
AltCharset((itsAltCharsetCounter = 0));
break;
case fmtBold:
Bold(++bold_num);
Bold(++itsBoldCounter);
break;
case fmtBoldEnd:
// FIXME: No idea why this needs to de disabled at 1 :X
// Probably a mistake somewhere in the code, but for now
// I was not able to find it
if (--bold_num <= 1)
Bold((bold_num = 0));
if (--itsBoldCounter <= 0)
Bold((itsBoldCounter = 0));
break;
case fmtReverse:
Reverse(++reverse_num);
Reverse(++itsReverseCounter);
break;
case fmtReverseEnd:
if (--reverse_num <= 0)
Reverse((reverse_num = 0));
if (--itsReverseCounter <= 0)
Reverse((itsReverseCounter = 0));
break;
case fmtAltCharset:
AltCharset(++altcharset_num);
AltCharset(++itsAltCharsetCounter);
break;
case fmtAltCharsetEnd:
if (--altcharset_num <= 0)
AltCharset((altcharset_num = 0));
if (--itsAltCharsetCounter <= 0)
AltCharset((itsAltCharsetCounter = 0));
break;
}
return *this;

View File

@@ -195,6 +195,10 @@ namespace NCurses
private:
std::deque<std::wstring> *itsHistory;
int itsBoldCounter;
int itsReverseCounter;
int itsAltCharsetCounter;
};
}