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

View File

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

View File

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

View File

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