Extract the color enum from color_ostream to toplevel.

develop
Alexander Gavrilov 2012-08-19 09:21:25 +04:00
parent 8ed219d4e0
commit fd0bf2ef92
11 changed files with 46 additions and 44 deletions

@ -275,7 +275,7 @@ namespace DFHack
/// Reset color to default /// Reset color to default
void reset_color(void) void reset_color(void)
{ {
color(Console::COLOR_RESET); color(COLOR_RESET);
if(!rawmode) if(!rawmode)
fflush(dfout_C); fflush(dfout_C);
} }

@ -277,7 +277,7 @@ namespace DFHack
/// Reset color to default /// Reset color to default
void reset_color(void) void reset_color(void)
{ {
color(Console::COLOR_RESET); color(COLOR_RESET);
if(!rawmode) if(!rawmode)
fflush(dfout_C); fflush(dfout_C);
} }

@ -179,7 +179,7 @@ namespace DFHack
void color(int index) void color(int index)
{ {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, index == color_ostream::COLOR_RESET ? default_attributes : index); SetConsoleTextAttribute(hConsole, index == COLOR_RESET ? default_attributes : index);
} }
void reset_color( void ) void reset_color( void )

@ -358,7 +358,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
continue; continue;
if (pcmd.isHotkeyCommand()) if (pcmd.isHotkeyCommand())
con.color(Console::COLOR_CYAN); con.color(COLOR_CYAN);
con.print("%s: %s\n",pcmd.name.c_str(), pcmd.description.c_str()); con.print("%s: %s\n",pcmd.name.c_str(), pcmd.description.c_str());
con.reset_color(); con.reset_color();
if (!pcmd.usage.empty()) if (!pcmd.usage.empty())
@ -481,7 +481,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
{ {
const PluginCommand & pcmd = (plug->operator[](j)); const PluginCommand & pcmd = (plug->operator[](j));
if (pcmd.isHotkeyCommand()) if (pcmd.isHotkeyCommand())
con.color(Console::COLOR_CYAN); con.color(COLOR_CYAN);
con.print(" %-22s - %s\n",pcmd.name.c_str(), pcmd.description.c_str()); con.print(" %-22s - %s\n",pcmd.name.c_str(), pcmd.description.c_str());
con.reset_color(); con.reset_color();
} }
@ -519,7 +519,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
for(auto iter = out.begin();iter != out.end();iter++) for(auto iter = out.begin();iter != out.end();iter++)
{ {
if ((*iter).recolor) if ((*iter).recolor)
con.color(Console::COLOR_CYAN); con.color(COLOR_CYAN);
con.print(" %-22s- %s\n",(*iter).name.c_str(), (*iter).description.c_str()); con.print(" %-22s- %s\n",(*iter).name.c_str(), (*iter).description.c_str());
con.reset_color(); con.reset_color();
} }

@ -252,7 +252,7 @@ static int lua_dfhack_color(lua_State *S)
{ {
int cv = luaL_optint(S, 1, -1); int cv = luaL_optint(S, 1, -1);
if (cv < -1 || cv > color_ostream::COLOR_MAX) if (cv < -1 || cv > COLOR_MAX)
luaL_argerror(S, 1, "invalid color value"); luaL_argerror(S, 1, "invalid color value");
color_ostream *out = Lua::GetOutput(S); color_ostream *out = Lua::GetOutput(S);

@ -41,30 +41,32 @@ namespace dfproto
namespace DFHack namespace DFHack
{ {
enum color_value
{
COLOR_RESET = -1,
COLOR_BLACK = 0,
COLOR_BLUE,
COLOR_GREEN,
COLOR_CYAN,
COLOR_RED,
COLOR_MAGENTA,
COLOR_BROWN,
COLOR_GREY,
COLOR_DARKGREY,
COLOR_LIGHTBLUE,
COLOR_LIGHTGREEN,
COLOR_LIGHTCYAN,
COLOR_LIGHTRED,
COLOR_LIGHTMAGENTA,
COLOR_YELLOW,
COLOR_WHITE,
COLOR_MAX = COLOR_WHITE
};
class DFHACK_EXPORT color_ostream : public std::ostream class DFHACK_EXPORT color_ostream : public std::ostream
{ {
public: public:
enum color_value typedef DFHack::color_value color_value;
{
COLOR_RESET = -1,
COLOR_BLACK = 0,
COLOR_BLUE,
COLOR_GREEN,
COLOR_CYAN,
COLOR_RED,
COLOR_MAGENTA,
COLOR_BROWN,
COLOR_GREY,
COLOR_DARKGREY,
COLOR_LIGHTBLUE,
COLOR_LIGHTGREEN,
COLOR_LIGHTCYAN,
COLOR_LIGHTRED,
COLOR_LIGHTMAGENTA,
COLOR_YELLOW,
COLOR_WHITE,
COLOR_MAX = COLOR_WHITE
};
private: private:
color_value cur_color; color_value cur_color;

@ -189,7 +189,7 @@ void DFHack::Job::printJobDetails(color_ostream &out, df::job *job)
{ {
CHECK_NULL_POINTER(job); CHECK_NULL_POINTER(job);
out.color(job->flags.bits.suspend ? Console::COLOR_DARKGREY : Console::COLOR_GREY); out.color(job->flags.bits.suspend ? COLOR_DARKGREY : COLOR_GREY);
out << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_type); out << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_type);
if (job->flags.whole) if (job->flags.whole)
out << " (" << bitfield_to_string(job->flags) << ")"; out << " (" << bitfield_to_string(job->flags) << ")";

@ -462,7 +462,7 @@ void joinCounts(std::map<df::coord, int> &counts)
static void printCompanionHeader(color_ostream &out, size_t i, df::unit *unit) static void printCompanionHeader(color_ostream &out, size_t i, df::unit *unit)
{ {
out.color(Console::COLOR_GREY); out.color(COLOR_GREY);
if (i < 28) if (i < 28)
out << char('a'+i); out << char('a'+i);

@ -257,7 +257,7 @@ command_result kittens (color_ostream &out, vector <string> & parameters)
}; };
con.cursor(false); con.cursor(false);
con.clear(); con.clear();
Console::color_value color = Console::COLOR_BLUE; Console::color_value color = COLOR_BLUE;
while(1) while(1)
{ {
if(shutdown_flag) if(shutdown_flag)
@ -282,7 +282,7 @@ command_result kittens (color_ostream &out, vector <string> & parameters)
con.flush(); con.flush();
con.msleep(60); con.msleep(60);
((int&)color) ++; ((int&)color) ++;
if(color > Console::COLOR_MAX) if(color > COLOR_MAX)
color = Console::COLOR_BLUE; color = COLOR_BLUE;
} }
} }

@ -73,7 +73,7 @@ void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,color_ostream
con.reset_color(); con.reset_color();
if(isAddr((uint32_t *)(buf+j+i),ranges)) if(isAddr((uint32_t *)(buf+j+i),ranges))
con.color(Console::COLOR_LIGHTRED); //coloring in the middle does not work con.color(COLOR_LIGHTRED); //coloring in the middle does not work
//TODO make something better? //TODO make something better?
} }
if(lbuf[j+i]!=buf[j+i]) if(lbuf[j+i]!=buf[j+i])

@ -1380,15 +1380,15 @@ static void print_constraint(color_ostream &out, ItemConstraint *cv, bool no_job
{ {
Console::color_value color; Console::color_value color;
if (cv->request_resume) if (cv->request_resume)
color = Console::COLOR_GREEN; color = COLOR_GREEN;
else if (cv->request_suspend) else if (cv->request_suspend)
color = Console::COLOR_CYAN; color = COLOR_CYAN;
else else
color = Console::COLOR_DARKGREY; color = COLOR_DARKGREY;
out.color(color); out.color(color);
out << prefix << "Constraint " << flush; out << prefix << "Constraint " << flush;
out.color(Console::COLOR_GREY); out.color(COLOR_GREY);
out << cv->config.val() << " " << flush; out << cv->config.val() << " " << flush;
out.color(color); out.color(color);
out << (cv->goalByCount() ? "count " : "amount ") out << (cv->goalByCount() ? "count " : "amount ")
@ -1437,18 +1437,18 @@ static void print_constraint(color_ostream &out, ItemConstraint *cv, bool no_job
{ {
if (pj->want_resumed) if (pj->want_resumed)
{ {
out.color(Console::COLOR_YELLOW); out.color(COLOR_YELLOW);
out << start << " (delayed)" << endl; out << start << " (delayed)" << endl;
} }
else else
{ {
out.color(Console::COLOR_BLUE); out.color(COLOR_BLUE);
out << start << " (suspended)" << endl; out << start << " (suspended)" << endl;
} }
} }
else else
{ {
out.color(Console::COLOR_GREEN); out.color(COLOR_GREEN);
out << start << endl; out << start << endl;
} }
@ -1472,11 +1472,11 @@ static void print_job(color_ostream &out, ProtectedJob *pj)
isOptionEnabled(CF_AUTOMELT)) isOptionEnabled(CF_AUTOMELT))
{ {
if (meltable_count <= 0) if (meltable_count <= 0)
out.color(Console::COLOR_CYAN); out.color(COLOR_CYAN);
else if (pj->want_resumed && !pj->isActuallyResumed()) else if (pj->want_resumed && !pj->isActuallyResumed())
out.color(Console::COLOR_YELLOW); out.color(COLOR_YELLOW);
else else
out.color(Console::COLOR_GREEN); out.color(COLOR_GREEN);
out << " Meltable: " << meltable_count << " objects." << endl; out << " Meltable: " << meltable_count << " objects." << endl;
out.reset_color(); out.reset_color();
} }