changed naming scheme
This commit is contained in:
@ -29,36 +29,36 @@ console_output::console_output(std::ostream &cout): out{cout} {}
|
|||||||
X Y are numbers from above
|
X Y are numbers from above
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::string console_output::get_code(const int attr) {
|
std::string console_output::get_code(const int attrs) {
|
||||||
if (attr < 255)
|
if (attrs < 255)
|
||||||
return "\033[0m";
|
return "\033[0m";
|
||||||
|
|
||||||
std::string result = "\033[0m\033[";
|
std::string result = "\033[0m\033[";
|
||||||
|
|
||||||
if (attr & A_BOLD)
|
if (attrs & A_BOLD)
|
||||||
result += "1;";
|
result += "1;";
|
||||||
|
|
||||||
if (attr & A_UNDERLINE)
|
if (attrs & A_UNDERLINE)
|
||||||
result += "4;";
|
result += "4;";
|
||||||
|
|
||||||
if (attr & A_STANDOUT)
|
if (attrs & A_STANDOUT)
|
||||||
result += "7;";
|
result += "7;";
|
||||||
|
|
||||||
if ((attr & COLOR_PAIR(COLOR_WHITE)) == COLOR_PAIR(COLOR_WHITE))
|
if ((attrs & COLOR_PAIR(COLOR_WHITE)) == COLOR_PAIR(COLOR_WHITE))
|
||||||
result += "37;";
|
result += "37;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_CYAN)) == COLOR_PAIR(COLOR_CYAN))
|
else if ((attrs & COLOR_PAIR(COLOR_CYAN)) == COLOR_PAIR(COLOR_CYAN))
|
||||||
result += "36;";
|
result += "36;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_MAGENTA)) == COLOR_PAIR(COLOR_MAGENTA))
|
else if ((attrs & COLOR_PAIR(COLOR_MAGENTA)) == COLOR_PAIR(COLOR_MAGENTA))
|
||||||
result += "35;";
|
result += "35;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_BLUE)) == COLOR_PAIR(COLOR_BLUE))
|
else if ((attrs & COLOR_PAIR(COLOR_BLUE)) == COLOR_PAIR(COLOR_BLUE))
|
||||||
result += "34;";
|
result += "34;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_YELLOW)) == COLOR_PAIR(COLOR_YELLOW))
|
else if ((attrs & COLOR_PAIR(COLOR_YELLOW)) == COLOR_PAIR(COLOR_YELLOW))
|
||||||
result += "33;";
|
result += "33;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_RED)) == COLOR_PAIR(COLOR_RED))
|
else if ((attrs & COLOR_PAIR(COLOR_RED)) == COLOR_PAIR(COLOR_RED))
|
||||||
result += "31;";
|
result += "31;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_GREEN)) == COLOR_PAIR(COLOR_GREEN))
|
else if ((attrs & COLOR_PAIR(COLOR_GREEN)) == COLOR_PAIR(COLOR_GREEN))
|
||||||
result += "32;";
|
result += "32;";
|
||||||
else if ((attr & COLOR_PAIR(COLOR_BLACK_ON_WHITE)) == COLOR_BLACK_ON_WHITE)
|
else if ((attrs & COLOR_PAIR(COLOR_BLACK_ON_WHITE)) == COLOR_BLACK_ON_WHITE)
|
||||||
result += "30;47;";
|
result += "30;47;";
|
||||||
|
|
||||||
result[result.length() - 1] = 'm';
|
result[result.length() - 1] = 'm';
|
||||||
@ -80,20 +80,20 @@ void console_output::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void console_output::print_char(const position &pos, const char ch,
|
void console_output::print_char(const position &pos, const char ch,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
contents[pos.y * DISPLAY_WIDTH + pos.x] = attr | ch;
|
contents[pos.y * DISPLAY_WIDTH + pos.x] = attrs | ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_output::print_str(const position &pos, const std::string &str,
|
void console_output::print_str(const position &pos, const std::string &str,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int head = pos.y * DISPLAY_WIDTH + pos.x;
|
int head = pos.y * DISPLAY_WIDTH + pos.x;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < str.length(); ++i)
|
for (std::size_t i = 0; i < str.length(); ++i)
|
||||||
contents[i + head] = attr | str[i];
|
contents[i + head] = attrs | str[i];
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,15 @@
|
|||||||
class console_output final : public display {
|
class console_output final : public display {
|
||||||
private:
|
private:
|
||||||
std::ostream &out;
|
std::ostream &out;
|
||||||
std::string get_code(const int attr);
|
std::string get_code(const int attrs);
|
||||||
public:
|
public:
|
||||||
console_output(std::ostream &cout);
|
console_output(std::ostream &cout);
|
||||||
|
|
||||||
void render() override;
|
void render() override;
|
||||||
void print_char(const position &pos,
|
void print_char(const position &pos,
|
||||||
const char ch, const int attr) override;
|
const char ch, const int attrs) override;
|
||||||
void print_str(const position &pos,
|
void print_str(const position &pos,
|
||||||
const std::string &str, const int attr) override;
|
const std::string &str, const int attrs) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,22 +12,22 @@ void curses_output::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void curses_output::print_char(const position &pos, const char ch,
|
void curses_output::print_char(const position &pos, const char ch,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
curse->print_char(pos, ch, attr);
|
curse->print_char(pos, ch, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void curses_output::print_str(const position &pos, const std::string &str,
|
void curses_output::print_str(const position &pos, const std::string &str,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
position tmp = pos;
|
position tmp = pos;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < str.length(); ++i) {
|
for (std::size_t i = 0; i < str.length(); ++i) {
|
||||||
curse->print_char(tmp, str[i], attr);
|
curse->print_char(tmp, str[i], attrs);
|
||||||
tmp += {1, 0};
|
tmp += {1, 0};
|
||||||
|
|
||||||
if (tmp.x >= DISPLAY_WIDTH)
|
if (tmp.x >= DISPLAY_WIDTH)
|
||||||
|
@ -15,9 +15,9 @@ public:
|
|||||||
void render() override;
|
void render() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void print_char(const position &pos,
|
void print_char(const position &pos,
|
||||||
const char ch, const int attr) override;
|
const char ch, const int attrs) override;
|
||||||
void print_str(const position &pos,
|
void print_str(const position &pos,
|
||||||
const std::string &str, const int attr) override;
|
const std::string &str, const int attrs) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,10 +24,10 @@ public:
|
|||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
virtual void print_char(const position &pos, const char ch,
|
virtual void print_char(const position &pos, const char ch,
|
||||||
const int attr =
|
const int attrs =
|
||||||
A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0;
|
A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0;
|
||||||
virtual void print_str(const position &pos, const std::string &str,
|
virtual void print_str(const position &pos, const std::string &str,
|
||||||
const int attr =
|
const int attrs =
|
||||||
A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0;
|
A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0;
|
||||||
// default arguments are to be set in the base class's declaration
|
// default arguments are to be set in the base class's declaration
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ void file_output::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void file_output::print_char(const position &pos, const char ch,
|
void file_output::print_char(const position &pos, const char ch,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ void file_output::print_char(const position &pos, const char ch,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void file_output::print_str(const position &pos, const std::string &str,
|
void file_output::print_str(const position &pos, const std::string &str,
|
||||||
const int attr) {
|
const int attrs) {
|
||||||
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ public:
|
|||||||
|
|
||||||
void render() override;
|
void render() override;
|
||||||
void print_char(const position &pos,
|
void print_char(const position &pos,
|
||||||
const char ch, const int attr) override;
|
const char ch, const int attrs) override;
|
||||||
void print_str(const position &pos,
|
void print_str(const position &pos,
|
||||||
const std::string &str, const int attr) override;
|
const std::string &str, const int attrs) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user