use streams instead of Window::WriteXY()

This commit is contained in:
Andrzej Rybczak
2009-02-16 19:32:43 +01:00
parent 43a8e2284e
commit 32f959d1ec
13 changed files with 42 additions and 37 deletions

View File

@@ -287,13 +287,6 @@ string GetLineValue(string &line, char a, char b, bool once)
return ""; return "";
} }
Window &Statusbar()
{
wFooter->GotoXY(0, Config.statusbar_visibility);
wclrtoeol(wFooter->Raw());
return *wFooter;
}
const Buffer &ShowTag(const string &tag) const Buffer &ShowTag(const string &tag)
{ {
static Buffer result; static Buffer result;

View File

@@ -46,8 +46,6 @@ std::string FindSharedDir(const std::string &, const std::string &);
std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0); std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
Window &Statusbar();
const Buffer &ShowTag(const std::string &); const Buffer &ShowTag(const std::string &);
const std::basic_string<my_char_t> &Scroller(const std::string &, size_t, size_t &); const std::basic_string<my_char_t> &Scroller(const std::string &, size_t, size_t &);

View File

@@ -142,7 +142,7 @@ void Info::GetArtist()
redraw_header = 1; redraw_header = 1;
itsTitle = "Artist's info - " + *artist; itsTitle = "Artist's info - " + *artist;
w->Clear(); w->Clear();
w->WriteXY(0, 0, 0, "Fetching artist's info..."); static_cast<Window &>(*w) << "Fetching artist's info...";
if (!Downloader) if (!Downloader)
{ {
pthread_create(&Downloader, NULL, PrepareArtist, artist); pthread_create(&Downloader, NULL, PrepareArtist, artist);

View File

@@ -121,7 +121,7 @@ void Lyrics::SwitchTo()
redraw_header = 1; redraw_header = 1;
w->Clear(); w->Clear();
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
w->WriteXY(0, 0, 0, "Fetching lyrics..."); static_cast<Window &>(*w) << "Fetching lyrics...";
if (!Downloader) if (!Downloader)
{ {
pthread_create(&Downloader, NULL, Get, &itsSong); pthread_create(&Downloader, NULL, Get, &itsSong);

View File

@@ -98,8 +98,7 @@ void MediaLibrary::Refresh()
Songs->Display(); Songs->Display();
if (Albums->Empty()) if (Albums->Empty())
{ {
Albums->WriteXY(0, 0, 0, "No albums found."); *Albums << XY(0, 0) << "No albums found." << wrefresh;
Albums->Refresh();
} }
} }
@@ -213,8 +212,7 @@ void MediaLibrary::Update()
Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current())); Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current()));
if (Albums->Empty()) // left for compatibility with <mpd-0.14 if (Albums->Empty()) // left for compatibility with <mpd-0.14
{ {
Albums->WriteXY(0, 0, 0, "No albums found."); *Albums << XY(0, 0) << "No albums found." << wrefresh;
Albums->Refresh();
} }
else else
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, locale_to_utf_cpy(Albums->Current().second)); Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, locale_to_utf_cpy(Albums->Current().second));

View File

@@ -218,9 +218,7 @@ int main(int argc, char *argv[])
{ {
if (title_allowed) if (title_allowed)
{ {
wHeader->Bold(1); *wHeader << XY(0, 0) << wclrtoeol << fmtBold << myScreen->Title() << fmtBoldEnd;
wHeader->WriteXY(0, 0, 1, "%s", myScreen->Title().c_str());
wHeader->Bold(0);
} }
else else
{ {
@@ -240,7 +238,7 @@ int main(int argc, char *argv[])
} }
wHeader->SetColor(Config.volume_color); wHeader->SetColor(Config.volume_color);
wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, 0, "%s", volume_state.c_str()); *wHeader << XY(wHeader->GetWidth()-volume_state.length(), 0) << volume_state;
wHeader->SetColor(Config.header_color); wHeader->SetColor(Config.header_color);
wHeader->Refresh(); wHeader->Refresh();
redraw_header = 0; redraw_header = 0;
@@ -873,7 +871,7 @@ int main(int argc, char *argv[])
wFooter->Bold(1); wFooter->Bold(1);
string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]"; string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]";
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 0, "%s", tracklength.c_str()); *wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
double progressbar_size = (double)songpos/(s.GetTotalLength()); double progressbar_size = (double)songpos/(s.GetTotalLength());
int howlong = wFooter->GetWidth()*progressbar_size; int howlong = wFooter->GetWidth()*progressbar_size;

View File

@@ -157,8 +157,7 @@ void PlaylistEditor::Update()
if (Content->Empty()) if (Content->Empty())
{ {
Content->WriteXY(0, 0, 0, "Playlist is empty."); *Content << XY(0, 0) << "Playlist is empty." << wrefresh;
Content->Refresh();
} }
} }

View File

@@ -74,7 +74,7 @@ void SearchEngine::SwitchTo()
if (!w->Back().first) if (!w->Back().first)
{ {
w->WriteXY(0, 0, 0, "Updating list..."); *w << XY(0, 0) << "Updating list...";
UpdateFoundList(); UpdateFoundList();
} }
} }

View File

@@ -293,7 +293,13 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
} }
} }
if (!block_statusbar_update && Config.statusbar_visibility) if (!block_statusbar_update && Config.statusbar_visibility)
wFooter->WriteXY(0, 1, player_state.empty(), "%s", player_state.c_str()); {
*wFooter << XY(0, 1);
if (player_state.empty())
*wFooter << wclrtoeol;
else
*wFooter << player_state;
}
} }
if (changed.SongID) if (changed.SongID)
{ {
@@ -357,12 +363,11 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
tracklength += Song::ShowTime(elapsed); tracklength += Song::ShowTime(elapsed);
tracklength += "]"; tracklength += "]";
} }
wFooter->WriteXY(0, 1, 1, "%s", player_state.c_str()); *wFooter << XY(0, 1) << wclrtoeol << player_state
wFooter->Bold(0); << fmtBoldEnd
*wFooter << Scroller(utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin); << Scroller(utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin)
wFooter->Bold(1); << fmtBold
<< XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str());
} }
if (!block_progressbar_update) if (!block_progressbar_update)
{ {
@@ -381,7 +386,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
else else
{ {
if (!block_statusbar_update && Config.statusbar_visibility) if (!block_statusbar_update && Config.statusbar_visibility)
wFooter->WriteXY(0, 1, 1, ""); *wFooter << XY(0, 1) << wclrtoeol;
} }
} }
@@ -445,7 +450,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
volume_state += IntoStr(Mpd->GetVolume()); volume_state += IntoStr(Mpd->GetVolume());
volume_state += "%"; volume_state += "%";
wHeader->SetColor(Config.volume_color); wHeader->SetColor(Config.volume_color);
wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, 1, "%s", volume_state.c_str()); *wHeader << XY(wHeader->GetWidth()-volume_state.length(), 0) << volume_state;
wHeader->SetColor(Config.header_color); wHeader->SetColor(Config.header_color);
wHeader->Refresh(); wHeader->Refresh();
} }
@@ -456,6 +461,12 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
wFooter->Refresh(); wFooter->Refresh();
} }
Window &Statusbar()
{
*wFooter << XY(0, Config.statusbar_visibility) << wclrtoeol;
return *wFooter;
}
void ShowMessage(const char *format, ...) void ShowMessage(const char *format, ...)
{ {
if (messages_allowed) if (messages_allowed)

View File

@@ -31,6 +31,7 @@ void TraceMpdStatus();
void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *); void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *);
void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *); void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *);
Window &Statusbar();
void ShowMessage(const char *, ...); void ShowMessage(const char *, ...);
#endif #endif

View File

@@ -409,7 +409,7 @@ void TagEditor::Update()
if (Config.albums_in_tag_editor) if (Config.albums_in_tag_editor)
{ {
std::map<string, string, CaseInsensitiveSorting> maplist; std::map<string, string, CaseInsensitiveSorting> maplist;
Albums->WriteXY(0, 0, 0, "Fetching albums' list..."); *Albums << XY(0, 0) << "Fetching albums' list...";
Mpd->GetAlbums("", list); Mpd->GetAlbums("", list);
for (TagList::const_iterator it = list.begin(); it != list.end(); it++) for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
{ {

View File

@@ -332,7 +332,7 @@ void Window::ReadKey() const
wgetch(itsWindow); wgetch(itsWindow);
} }
void Window::Write(bool cte, const char *format, ...) const /*void Window::Write(bool cte, const char *format, ...) const
{ {
va_list list; va_list list;
va_start(list, format); va_start(list, format);
@@ -351,7 +351,7 @@ void Window::WriteXY(int x, int y, bool cte, const char *format, ...) const
va_end(list); va_end(list);
if (cte) if (cte)
wclrtoeol(itsWindow); wclrtoeol(itsWindow);
} }*/
string Window::GetString(const string &base, size_t length, size_t width, bool encrypted) const string Window::GetString(const string &base, size_t length, size_t width, bool encrypted) const
{ {
@@ -703,6 +703,12 @@ Window &Window::operator<<(const Format &format)
return *this; return *this;
} }
Window &Window::operator<<(int (*f)(WINDOW *))
{
f(itsWindow);
return *this;
}
Window &Window::operator<<(const XY &coords) Window &Window::operator<<(const XY &coords)
{ {
GotoXY(coords.x, coords.y); GotoXY(coords.x, coords.y);

View File

@@ -122,12 +122,13 @@ class Window
void ReadKey(int &) const; void ReadKey(int &) const;
void ReadKey() const; void ReadKey() const;
void Write(bool, const char *, ...) const; //void Write(bool, const char *, ...) const;
void WriteXY(int, int, bool, const char *, ...) const; //void WriteXY(int, int, bool, const char *, ...) const;
void Scrollable(bool) const; void Scrollable(bool) const;
virtual void Scroll(Where); virtual void Scroll(Where);
Window &operator<<(int (*)(WINDOW *));
Window &operator<<(const Colors &); Window &operator<<(const Colors &);
Window &operator<<(const Color &); Window &operator<<(const Color &);
Window &operator<<(const Format &); Window &operator<<(const Format &);