Skip to content

Commit

Permalink
color is changeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhui ZHI authored and Yuhui ZHI committed Nov 22, 2016
1 parent d064d25 commit 263ead6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class Column
{
color = color_head;
}
else if (len - delta == 1) // this should be "1.0*delta/pos<0.7" but this calculation is too heavy
{
color = color_tail;
}
//else if (len - delta == 1) // this should be "1.0*delta/pos<0.7" but this calculation is too heavy
//{
// color = color_tail;
//}
else
{
color = color_body;
Expand Down
2 changes: 1 addition & 1 deletion Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Scene
millisec = (millisec == SysTool::TIME_HIGH) ? millisec : millisec + SysTool::TIME_DELTA;
}
showScene();
std::for_each(column.begin(), column.end(), [&](Column & d){ d.refresh(generator, SysTool::COLOR_HEAD, SysTool::COLOR_BODY, SysTool::COLOR_TAIL, SysTool::COLOR_EMPTY, std::forward<StringType>(st)...); });
std::for_each(column.begin(), column.end(), [&](Column & d){ d.refresh(generator, SysTool::COLOR_HEAD, SysTool::getColorBody(), SysTool::COLOR_TAIL, SysTool::COLOR_EMPTY, std::forward<StringType>(st)...); });
std::this_thread::sleep_for(std::chrono::milliseconds(millisec));
}
}
Expand Down
17 changes: 14 additions & 3 deletions SysTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@


const int SysTool::COLOR_HEAD{255};
const int SysTool::COLOR_BODY{46};
const int SysTool::COLOR_TAIL{2};
const int SysTool::COLOR_EMPTY{COLOR_BLACK};
const int SysTool::TIME_LOW{0};
const int SysTool::TIME_HIGH{300};
const int SysTool::TIME_DELTA{30};

int SysTool::colorBody{46};


int SysTool::getCols()
{
Expand Down Expand Up @@ -49,7 +50,7 @@ void SysTool::init()
noecho();
start_color();
init_pair(COLOR_HEAD, COLOR_HEAD, COLOR_EMPTY);
init_pair(COLOR_BODY, COLOR_BODY, COLOR_EMPTY);
init_pair(colorBody, colorBody, COLOR_EMPTY);
init_pair(COLOR_TAIL, COLOR_TAIL, COLOR_EMPTY);
}

Expand All @@ -58,7 +59,17 @@ void SysTool::setColor(int color)
attron(COLOR_PAIR(color));
}

void SysTool::finish()
void SysTool::setColorBody(int cb)
{
colorBody = cb;
}

int SysTool::getColorBody()
{
return colorBody;
}

void SysTool::finalize()
{
endwin();
}
7 changes: 5 additions & 2 deletions SysTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class SysTool
static int getchNonBlocking();
static void init();
static void setColor(int);
static void finish();
static int getColorBody();
static void setColorBody(int);
static void finalize();

const static int COLOR_HEAD;
const static int COLOR_BODY;
const static int COLOR_TAIL;
const static int COLOR_EMPTY;
const static int TIME_LOW;
const static int TIME_HIGH;
const static int TIME_DELTA;
private:
static int colorBody;
};

#endif
41 changes: 38 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,56 @@ int main(int argc, char ** argv)

std::cin.get();

SysTool::init();
Scene scene(SysTool::getCols(), SysTool::getLines());
if (argc == 1)
{
SysTool::init();
Scene scene(SysTool::getCols(), SysTool::getLines());
scene.execute();
}
else if (argc == 2)
{
std::string arg(argv[1]);
bool isColor = true;
for (auto it : arg)
{
if (!std::isdigit(it))
{
isColor = false;
break;
}
}
if (isColor)
{
std::istringstream iss(argv[1]);
int color;
iss >> color;
SysTool::setColorBody(color);
SysTool::init();
Scene scene(SysTool::getCols(), SysTool::getLines());
scene.execute();
}
else
{
SysTool::init();
Scene scene(SysTool::getCols(), SysTool::getLines());
scene.execute(argv[1]);
}
}
else if (argc == 3)
{
std::istringstream iss(argv[2]);
int color;
iss >> color;
SysTool::setColorBody(color);
SysTool::init();
Scene scene(SysTool::getCols(), SysTool::getLines());
scene.execute(argv[1]);
}
else
{
std::cerr<<"Error"<<std::endl;
}
SysTool::finish();
SysTool::finalize();


return EXIT_SUCCESS;
Expand Down

0 comments on commit 263ead6

Please sign in to comment.