- Fixed bug where sometimes list wasn't reset when changing categories

- Updated Colors.cpp to use custom colors where available.
This commit is contained in:
casey 2016-06-27 21:22:33 -07:00
parent 51d3ced344
commit e88a0a1077
15 changed files with 91 additions and 63 deletions

View File

@ -243,8 +243,6 @@ int main(int argc, char* argv[])
cbreak();
noecho();
keypad(stdscr, TRUE);
start_color();
use_default_colors();
refresh();
curs_set(0);
@ -303,7 +301,7 @@ int main(int argc, char* argv[])
else if (kn == "^D") { /* ctrl+d quits */
quit = true;
}
else if (kn == "ALT_R" || kn == "M-r") {
else if (kn == "M-r") {
Window::Invalidate();
}
else if (kn == "KEY_RESIZE") {

View File

@ -159,15 +159,15 @@ bool BrowseLayout::KeyPress(const std::string& key) {
this->categoryList->Requery();
return true;
}
else if (key == "ALT_1" || key == "M-1") {
else if (key == "M-1") {
this->categoryList->SetFieldName(constants::Track::ARTIST);
return true;
}
else if (key == "ALT_2" || key == "M-2") {
else if (key == "M-2") {
this->categoryList->SetFieldName(constants::Track::ALBUM);
return true;
}
else if (key == "ALT_3" || key == "M-3") {
else if (key == "M-3") {
this->categoryList->SetFieldName(constants::Track::GENRE);
return true;
}

View File

@ -72,7 +72,7 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library)
this->AddWindow(this->output);
this->AddWindow(this->resources);
this->commands->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->commands->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->commands->EnterPressed.connect(this, &ConsoleLayout::OnEnterPressed);
this->Help();
@ -133,14 +133,14 @@ void ConsoleLayout::OnEnterPressed(TextInput *input) {
std::string command = this->commands->GetText();
this->commands->SetText("");
output->WriteLine("> " + command + "\n", COLOR_PAIR(BOX_COLOR_BLACK_ON_GREY));
output->WriteLine("> " + command + "\n", COLOR_PAIR(CURSESPP_BLACK_ON_GREY));
if (!this->ProcessCommand(command)) {
if (command.size()) {
output->WriteLine(
"illegal command: '" +
command +
"'\n", COLOR_PAIR(BOX_COLOR_RED_ON_GREY));
"'\n", COLOR_PAIR(CURSESPP_RED_ON_GREY));
}
}
}
@ -311,6 +311,6 @@ void ConsoleLayout::ListPlugins() const {
"v" + std::string((*it)->Version()) + "\n"
" by " + std::string((*it)->Author()) + "\n";
this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE);
this->output->WriteLine(format, CURSESPP_RED_ON_BLUE);
}
}

View File

@ -136,14 +136,14 @@ int64 IndexerLayout::ListItemDecorator(
{
ListWindow* lw = static_cast<ListWindow*>(scrollable);
if (lw->GetSelectedIndex() == index) {
return COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN);
return COLOR_PAIR(CURSESPP_BLACK_ON_GREEN);
}
}
return -1;
}
void IndexerLayout::InitializeWindows() {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->title.reset(new TextLabel());
this->title->SetText("settings", TextLabel::AlignCenter);
@ -155,9 +155,9 @@ void IndexerLayout::InitializeWindows() {
this->addedPathsLabel->SetText("indexed paths (BACKSPACE to remove)", TextLabel::AlignLeft);
this->addedPathsList.reset(new cursespp::ListWindow(&this->addedPathsAdapter));
this->addedPathsList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->addedPathsList->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->browseList.reset(new cursespp::ListWindow(&this->browseAdapter));
this->browseList->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->browseList->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
ScrollAdapterBase::ItemDecorator decorator =
std::bind(

View File

@ -105,7 +105,7 @@ void SearchLayout::Layout() {
void SearchLayout::InitializeWindows(PlaybackService& playback) {
this->input.reset(new cursespp::TextInput());
this->input->TextChanged.connect(this, &SearchLayout::OnInputChanged);
this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->input->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->input->SetFocusOrder(0);
this->AddWindow(this->input);

View File

@ -93,7 +93,7 @@ void TrackSearchLayout::Layout() {
void TrackSearchLayout::InitializeWindows() {
this->input.reset(new cursespp::TextInput());
this->input->TextChanged.connect(this, &TrackSearchLayout::OnInputChanged);
this->input->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->input->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->input->SetFocusOrder(0);
this->AddWindow(this->input);

View File

@ -62,7 +62,7 @@ CategoryListView::CategoryListView(
const std::string& fieldName)
: ListWindow(NULL)
, playback(playback) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->selectAfterQuery = 0;
this->library = library;
this->library->QueryCompleted.connect(this, &CategoryListView::OnQueryCompleted);
@ -207,14 +207,14 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) {
bool selected = index == parent.GetSelectedIndex();
int64 attrs = selected ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1LL;
int64 attrs = selected ? COLOR_PAIR(CURSESPP_BLACK_ON_GREEN) : -1LL;
if (playing) {
if (selected) {
attrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_YELLOW);
attrs = COLOR_PAIR(CURSESPP_BLACK_ON_YELLOW);
}
else {
attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD;
attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD;
}
}

View File

@ -47,7 +47,7 @@ typedef IScrollAdapter::IEntry IEntry;
LogWindow::LogWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->adapter = new SimpleScrollAdapter();
this->adapter->SetMaxEntries(500);
@ -78,18 +78,18 @@ void LogWindow::Update() {
WINDOW* contents = this->GetContent();
for (size_t i = 0; i < pending.size(); i++) {
int64 attrs = COLOR_PAIR(BOX_COLOR_WHITE_ON_BLACK);
int64 attrs = COLOR_PAIR(CURSESPP_WHITE_ON_TRANSPARENT);
LogEntry* entry = pending[i];
switch (entry->level) {
case musik::debug::level_error: {
attrs = COLOR_PAIR(BOX_COLOR_RED_ON_BLACK) | A_BOLD;
attrs = COLOR_PAIR(CURSESPP_RED_ON_TRANSPARENT) | A_BOLD;
break;
}
case musik::debug::level_warning: {
attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD;
attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD;
break;
}
}

View File

@ -47,7 +47,7 @@ typedef IScrollAdapter::EntryPtr EntryPtr;
OutputWindow::OutputWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_BLACK_ON_GREY);
this->SetContentColor(CURSESPP_BLACK_ON_GREY);
this->adapter = new SimpleScrollAdapter();
this->adapter->SetDisplaySize(this->GetContentWidth(), this->GetContentHeight());
this->adapter->SetMaxEntries(500);

View File

@ -67,7 +67,7 @@ using std::setiosflags;
TrackListView::TrackListView(PlaybackService& playback, LibraryPtr library)
: ListWindow(NULL)
, playback(playback) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->library = library;
this->library->QueryCompleted.connect(this, &TrackListView::OnQueryCompleted);
this->playback.TrackChanged.connect(this, &TrackListView::OnTrackChanged);
@ -111,6 +111,7 @@ void TrackListView::ProcessMessage(IMessage &message) {
mess with the selected index */
if (this->lastQueryHash != query->GetQueryHash()) {
this->SetSelectedIndex(0);
this->ScrollToTop();
}
this->lastQueryHash = this->query->GetQueryHash();
@ -153,7 +154,7 @@ constants) */
IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
bool selected = index == parent.GetSelectedIndex();
int64 attrs = selected ? COLOR_PAIR(BOX_COLOR_BLACK_ON_GREEN) : -1LL;
int64 attrs = selected ? COLOR_PAIR(CURSESPP_BLACK_ON_GREEN) : -1LL;
TrackPtr track = parent.metadata->Get(index);
@ -163,10 +164,10 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
playing->LibraryId() == track->LibraryId())
{
if (selected) {
attrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_YELLOW);
attrs = COLOR_PAIR(CURSESPP_BLACK_ON_YELLOW);
}
else {
attrs = COLOR_PAIR(BOX_COLOR_YELLOW_ON_BLACK) | A_BOLD;
attrs = COLOR_PAIR(CURSESPP_YELLOW_ON_TRANSPARENT) | A_BOLD;
}
}
@ -207,7 +208,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
if (this->parent.headers->find(index) != this->parent.headers->end()) {
std::string album = track->GetValue(constants::Track::ALBUM);
std::shared_ptr<EntryWithHeader> entry(new EntryWithHeader(album, text));
entry->SetAttrs(COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK), attrs);
entry->SetAttrs(COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT), attrs);
return entry;
}
else {

View File

@ -130,7 +130,7 @@ size_t writePlayingFormat(
TokenList tokens;
tokenize(playingFormat, tokens);
int64 gb = COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK);
int64 gb = COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT);
size_t remaining = width;
auto it = tokens.begin();
@ -182,7 +182,7 @@ TransportWindow::TransportWindow(musik::box::PlaybackService& playback)
, playback(playback)
, transport(playback.GetTransport())
{
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->SetContentColor(CURSESPP_WHITE_ON_TRANSPARENT);
this->SetFrameVisible(false);
this->playback.TrackChanged.connect(this, &TransportWindow::OnPlaybackServiceTrackChanged);
this->playback.ModeChanged.connect(this, &TransportWindow::OnPlaybackModeChanged);
@ -241,7 +241,7 @@ void TransportWindow::Update() {
bool paused = (transport.GetPlaybackState() == ITransport::PlaybackPaused);
bool stopped = (transport.GetPlaybackState() == ITransport::PlaybackStopped);
int64 gb = COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK);
int64 gb = COLOR_PAIR(CURSESPP_GREEN_ON_TRANSPARENT);
/* playing SONG TITLE from ALBUM NAME */
std::string duration = "0";
@ -326,7 +326,7 @@ void TransportWindow::Update() {
system_clock::now().time_since_epoch()).count();
if (now % 2 == 0) {
timerAttrs = COLOR_PAIR(BOX_COLOR_BLACK_ON_BLACK);
timerAttrs = COLOR_PAIR(CURSESPP_BLACK_ON_TRANSPARENT);
}
}

View File

@ -98,7 +98,7 @@ void Checkbox::Redraw() {
std::string ellipsized = symbol + " " + this->buffer;
text::Ellipsize(ellipsized, cx);
int64 attrs = this->focused ? BOX_COLOR_RED_ON_BLACK : -1LL;
int64 attrs = this->focused ? CURSESPP_RED_ON_TRANSPARENT : -1LL;
if (attrs != -1) {
wattron(c, COLOR_PAIR(attrs));

View File

@ -37,21 +37,50 @@
using namespace cursespp;
static int white = COLOR_WHITE;
static int blue = COLOR_BLUE;
static int red = COLOR_RED;
static int yellow = COLOR_YELLOW;
static int green = COLOR_GREEN;
static int black = COLOR_BLACK;
static int background = -1;
#define COLOR_CUSTOM_WHITE 9
#define COLOR_CUSTOM_BLUE 10
#define COLOR_CUSTOM_RED 11
#define COLOR_CUSTOM_YELLOW 12
#define COLOR_CUSTOM_GREEN 13
#define COLOR_CUSTOM_BLACK 14
Colors::Colors() {
}
void Colors::Init() {
init_pair(BOX_COLOR_WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
init_pair(BOX_COLOR_RED_ON_BLUE, COLOR_RED, COLOR_BLUE);
init_pair(BOX_COLOR_YELLOW_ON_BLUE, COLOR_YELLOW, COLOR_BLUE);
init_pair(BOX_COLOR_BLACK_ON_GREY, COLOR_BLACK, COLOR_WHITE);
init_pair(BOX_COLOR_BLACK_ON_GREEN, COLOR_BLACK, COLOR_GREEN);
init_pair(BOX_COLOR_YELLOW_ON_BLACK, COLOR_YELLOW, -1);
init_pair(BOX_COLOR_WHITE_ON_BLACK, COLOR_WHITE, -1);
init_pair(BOX_COLOR_RED_ON_BLACK, COLOR_RED, -1);
init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE);
init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, -1);
init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, -1);
init_pair(BOX_COLOR_RED_ON_GREEN, COLOR_RED, COLOR_GREEN);
init_pair(BOX_COLOR_BLACK_ON_YELLOW, COLOR_BLACK, COLOR_YELLOW);
start_color();
use_default_colors();
/* the default colors are a bit harsh for my taste, so
let's use custom colors if the terminal supports it. in
the future we'll allow users to configure this via setting */
if (COLORS > 8) {
init_color(COLOR_CUSTOM_RED, 1000, 431, 392);
red = COLOR_CUSTOM_RED;
init_color(COLOR_CUSTOM_GREEN, 373, 980, 392);
green = COLOR_CUSTOM_GREEN;
}
init_pair(CURSESPP_WHITE_ON_BLUE, white, blue);
init_pair(CURSESPP_RED_ON_BLUE, red, blue);
init_pair(CURSESPP_YELLOW_ON_BLUE, yellow, blue);
init_pair(CURSESPP_BLACK_ON_GREY, black, white);
init_pair(CURSESPP_BLACK_ON_GREEN, black, green);
init_pair(CURSESPP_YELLOW_ON_TRANSPARENT, yellow, background);
init_pair(CURSESPP_WHITE_ON_TRANSPARENT, white, background);
init_pair(CURSESPP_RED_ON_TRANSPARENT, red, background);
init_pair(CURSESPP_RED_ON_GREY, red, white);
init_pair(CURSESPP_GREEN_ON_TRANSPARENT, green, background);
init_pair(CURSESPP_BLACK_ON_TRANSPARENT, black, background);
init_pair(CURSESPP_RED_ON_GREEN, red, green);
init_pair(CURSESPP_BLACK_ON_YELLOW, black, yellow);
}

View File

@ -36,19 +36,19 @@
#include "curses_config.h"
#define BOX_COLOR_WHITE_ON_BLUE 1
#define BOX_COLOR_RED_ON_BLUE 2
#define BOX_COLOR_YELLOW_ON_BLUE 3
#define BOX_COLOR_BLACK_ON_GREY 4
#define BOX_COLOR_BLACK_ON_GREEN 5
#define BOX_COLOR_YELLOW_ON_BLACK 6
#define BOX_COLOR_WHITE_ON_BLACK 7
#define BOX_COLOR_RED_ON_BLACK 8
#define BOX_COLOR_RED_ON_GREY 9
#define BOX_COLOR_GREEN_ON_BLACK 10
#define BOX_COLOR_BLACK_ON_BLACK 11
#define BOX_COLOR_RED_ON_GREEN 12
#define BOX_COLOR_BLACK_ON_YELLOW 13
#define CURSESPP_WHITE_ON_BLUE 1
#define CURSESPP_RED_ON_BLUE 2
#define CURSESPP_YELLOW_ON_BLUE 3
#define CURSESPP_BLACK_ON_GREY 4
#define CURSESPP_BLACK_ON_GREEN 5
#define CURSESPP_YELLOW_ON_TRANSPARENT 6
#define CURSESPP_WHITE_ON_TRANSPARENT 7
#define CURSESPP_RED_ON_TRANSPARENT 8
#define CURSESPP_RED_ON_GREY 9
#define CURSESPP_GREEN_ON_TRANSPARENT 10
#define CURSESPP_BLACK_ON_TRANSPARENT 11
#define CURSESPP_RED_ON_GREEN 12
#define CURSESPP_BLACK_ON_YELLOW 13
namespace cursespp {
class Colors {

View File

@ -64,12 +64,12 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) {
static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
if (oldFocus) {
oldFocus->SetFrameColor(BOX_COLOR_WHITE_ON_BLACK);
oldFocus->SetFrameColor(CURSESPP_WHITE_ON_TRANSPARENT);
oldFocus->Blur();
}
if (newFocus) {
newFocus->SetFrameColor(BOX_COLOR_RED_ON_BLACK);
newFocus->SetFrameColor(CURSESPP_RED_ON_TRANSPARENT);
newFocus->Focus();
}