From d26c3c8fc54f50f8b55381cbbc1736b89c1eee5d Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 11 Nov 2014 16:08:48 +0100 Subject: [PATCH] window: fill background color on clearing to EOL --- src/status.cpp | 13 +++++++------ src/statusbar.cpp | 8 ++++---- src/title.cpp | 4 ++-- src/window.cpp | 13 +++++++++++-- src/window.h | 6 ++++-- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/status.cpp b/src/status.cpp index cd4ea7f3..f087c078 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -465,7 +465,8 @@ void Status::Changes::playerState() myPlaylist->reloadRemaining(); if (Config.design == Design::Alternative) { - *wHeader << NC::XY(0, 0) << wclrtoeol << NC::XY(0, 1) << wclrtoeol; + *wHeader << NC::XY(0, 0) << NC::TermManip::ClearToEOL; + *wHeader << NC::XY(0, 1) << NC::TermManip::ClearToEOL; mixer(); flags(); } @@ -488,7 +489,7 @@ void Status::Changes::playerState() { *wFooter << NC::XY(0, 1); if (state.empty()) - *wFooter << wclrtoeol; + *wFooter << NC::TermManip::ClearToEOL; else *wFooter << NC::Format::Bold << state << NC::Format::NoBold; } @@ -551,7 +552,7 @@ void Status::Changes::elapsedTime(bool update_elapsed) if (m_player_state == MPD::psStop) { if (Statusbar::isUnlocked() && Config.statusbar_visibility) - *wFooter << NC::XY(0, 1) << wclrtoeol; + *wFooter << NC::XY(0, 1) << NC::TermManip::ClearToEOL; return; } @@ -592,7 +593,7 @@ void Status::Changes::elapsedTime(bool update_elapsed) } NC::WBuffer np_song; Format::print(Config.song_status_wformat, np_song, &np); - *wFooter << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold; + *wFooter << NC::XY(0, 1) << NC::TermManip::ClearToEOL << NC::Format::Bold << ps << NC::Format::NoBold; writeCyclicBuffer(np_song, *wFooter, playing_song_scroll_begin, wFooter->getWidth()-ps.length()-tracklength.length(), L" ** "); *wFooter << NC::Format::Bold << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength << NC::Format::NoBold; } @@ -631,11 +632,11 @@ void Status::Changes::elapsedTime(bool update_elapsed) size_t second_start = second_len < COLS-second_margin ? (COLS-second_len)/2 : ps.length()+1; if (!Global::SeekingInProgress) - *wHeader << NC::XY(0, 0) << wclrtoeol << tracklength; + *wHeader << NC::XY(0, 0) << NC::TermManip::ClearToEOL << tracklength; *wHeader << NC::XY(first_start, 0); writeCyclicBuffer(first, *wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, L" ** "); - *wHeader << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold; + *wHeader << NC::XY(0, 1) << NC::TermManip::ClearToEOL << NC::Format::Bold << ps << NC::Format::NoBold; *wHeader << NC::XY(second_start, 1); writeCyclicBuffer(second, *wHeader, second_line_scroll_begin, COLS-ps.length()-8-2, L" ** "); diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 851d4ed5..46f82405 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -112,7 +112,7 @@ Statusbar::ScopedLock::~ScopedLock() noexcept switch (Config.design) { case Design::Classic: - put() << wclrtoeol; + put(); // clear statusbar break; case Design::Alternative: Progressbar::draw(Status::State::elapsedTime(), Status::State::totalTime()); @@ -149,7 +149,7 @@ void Statusbar::tryRedraw() { case MPD::psUnknown: case MPD::psStop: - put() << wclrtoeol; + put(); // clear statusbar break; case MPD::psPlay: case MPD::psPause: @@ -168,7 +168,7 @@ void Statusbar::tryRedraw() NC::Window &Statusbar::put() { - *wFooter << NC::XY(0, Config.statusbar_visibility ? 1 : 0) << wclrtoeol; + *wFooter << NC::XY(0, Config.statusbar_visibility ? 1 : 0) << NC::TermManip::ClearToEOL; return *wFooter; } @@ -183,7 +183,7 @@ void Statusbar::print(int delay, const std::string &message) else progressbar_block_update = true; wFooter->goToXY(0, Config.statusbar_visibility); - *wFooter << message << wclrtoeol; + *wFooter << message << NC::TermManip::ClearToEOL; wFooter->refresh(); } } diff --git a/src/title.cpp b/src/title.cpp index 59853582..f2bdc0c8 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -47,14 +47,14 @@ void drawHeader() switch (Config.design) { case Design::Classic: - *wHeader << NC::XY(0, 0) << wclrtoeol << NC::Format::Bold << myScreen->title() << NC::Format::NoBold; + *wHeader << NC::XY(0, 0) << NC::TermManip::ClearToEOL << NC::Format::Bold << myScreen->title() << NC::Format::NoBold; *wHeader << Config.volume_color; *wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState; *wHeader << NC::Color::End; break; case Design::Alternative: std::wstring title = myScreen->title(); - *wHeader << NC::XY(0, 3) << wclrtoeol; + *wHeader << NC::XY(0, 3) << NC::TermManip::ClearToEOL; *wHeader << NC::Format::Bold << Config.alternative_ui_separator_color; mvwhline(wHeader->raw(), 2, 0, 0, COLS); mvwhline(wHeader->raw(), 4, 0, 0, COLS); diff --git a/src/window.cpp b/src/window.cpp index fe262b3c..8d2daf2a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1094,9 +1094,18 @@ Window &Window::operator<<(Format format) return *this; } -Window &Window::operator<<(int (*f)(WINDOW *)) +Window &Window::operator<<(TermManip tm) { - f(m_window); + switch (tm) + { + case TermManip::ClearToEOL: + { + auto x = getX(), y = getY(); + mvwhline(m_window, y, x, ' ', m_width-x); + goToXY(x, y); + } + break; + } return *this; } diff --git a/src/window.h b/src/window.h index f32ce8ad..4d011c95 100644 --- a/src/window.h +++ b/src/window.h @@ -187,6 +187,9 @@ private: std::ostream &operator<<(std::ostream &os, const Color &c); std::istream &operator>>(std::istream &is, Color &f); +/// Terminal manipulation functions +enum class TermManip { ClearToEOL }; + /// Format flags used by NCurses enum class Format { None, @@ -410,8 +413,7 @@ struct Window /// @param where indicates how many lines it has to scroll virtual void scroll(Scroll where); - /// Applies function of compatible prototype to internal WINDOW pointer - Window &operator<<(int (*f)(WINDOW *)); + Window &operator<<(TermManip tm); Window &operator<<(const Color &color); Window &operator<<(Format format); Window &operator<<(const XY &coords);