fixed ncurses output attributes

This commit is contained in:
2024-07-07 20:08:13 -04:00
parent 3d7484351f
commit d85f375fbe
5 changed files with 37 additions and 2 deletions

1
src/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
testing*

View File

@ -35,12 +35,15 @@ std::string console_output::get_code(const int attr) {
std::string result = "\033[0m\033["; std::string result = "\033[0m\033[";
if (attr & A_STANDOUT) if (attr & A_BOLD)
result += "1;"; result += "1;";
if (attr & A_UNDERLINE) if (attr & A_UNDERLINE)
result += "4;"; result += "4;";
if (attr & A_STANDOUT)
result += "7;";
if ((attr & COLOR_PAIR(COLOR_WHITE)) == COLOR_PAIR(COLOR_WHITE)) if ((attr & 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 ((attr & COLOR_PAIR(COLOR_CYAN)) == COLOR_PAIR(COLOR_CYAN))
@ -55,6 +58,8 @@ std::string console_output::get_code(const int attr) {
result += "31;"; result += "31;";
else if ((attr & COLOR_PAIR(COLOR_GREEN)) == COLOR_PAIR(COLOR_GREEN)) else if ((attr & 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)
result += "30;47;";
result[result.length() - 1] = 'm'; result[result.length() - 1] = 'm';
return result; return result;

View File

@ -1,6 +1,7 @@
#ifndef __CONSTANTS_H__ #ifndef __CONSTANTS_H__
#define __CONSTANTS_H__ #define __CONSTANTS_H__
#include <vector> #include <vector>
#include <ncurses.h>
#include "position.h" #include "position.h"
// IMPORTANT: panic is reserved for invalid results // IMPORTANT: panic is reserved for invalid results
@ -89,6 +90,8 @@ const feature FEATURE_LIST_ARGS = 1 << 31;
const int RETURN_FINE = 0; const int RETURN_FINE = 0;
const int RETURN_PANICKED = 1; const int RETURN_PANICKED = 1;
const int COLOR_BLACK_ON_WHITE = 8;
typedef std::vector<position> position_list; typedef std::vector<position> position_list;
typedef std::vector<direction> direction_list; typedef std::vector<direction> direction_list;

View File

@ -13,10 +13,24 @@ 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 attr) {
if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
return;
curse->print_char(pos, ch, attr); curse->print_char(pos, ch, attr);
} }
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 attr) {
curse->print_str(pos, str, attr); if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT)
return;
position tmp = pos;
for (std::size_t i = 0; i < str.length(); ++i) {
curse->print_char(tmp, str[i], attr);
tmp += {1, 0};
if (tmp.x >= DISPLAY_WIDTH)
tmp = {0, tmp.y + 1};
}
} }

View File

@ -3,6 +3,18 @@
cursor::cursor() { cursor::cursor() {
initscr(); initscr();
if (has_colors()) {
start_color();
init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
init_pair(COLOR_BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
}
} }
cursor::~cursor() { cursor::~cursor() {