diff options
author | Daniil Rozanov <dev@rozanov.info> | 2025-03-15 18:03:23 +0400 |
---|---|---|
committer | Daniil Rozanov <dev@rozanov.info> | 2025-03-15 18:03:23 +0400 |
commit | 4a9ce6e2555dfaf9155fa279f25667350377f688 (patch) | |
tree | 11bc0ea3a7b1c0be2c47419b7058d46d16e5f9f4 /tests/colors |
feat: chtype wrap
Diffstat (limited to 'tests/colors')
-rw-r--r-- | tests/colors/colors.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/colors/colors.cpp b/tests/colors/colors.cpp new file mode 100644 index 0000000..dfed275 --- /dev/null +++ b/tests/colors/colors.cpp @@ -0,0 +1,47 @@ +#include <cassert> +#include <cstdlib> +#include <ncurses.h> +#include <ncurses/colors.hpp> + +using uc = unsigned char; + +void test_color(int index, uc r, uc g, uc b) { + short r_, g_, b_; + assert(color_content(static_cast<short>(index), &r_, &g_, &b_) == OK); + assert(static_cast<unsigned char>(ncurses::curses_to_rgb(r_) == r)); + assert(static_cast<unsigned char>(ncurses::curses_to_rgb(g_) == g)); + assert(static_cast<unsigned char>(ncurses::curses_to_rgb(b_) == b)); +} + +void test_color_pair(int index, int a_index, int a_r, int a_g, int a_b, + int b_index, int b_r, int b_g, int b_b) { + short a_index_, a_r_, a_g_, a_b_, b_index_, b_r_, b_g_, b_b_; + assert(pair_content(index, &a_index_, &b_index_) == OK); + assert(a_index_ == a_index && b_index_ == b_index); + test_color(a_index, a_r, a_g, a_b); + test_color(b_index, b_r, b_g, b_b); +} + +int main(int argc, char *argv[]) { + initscr(); + if (has_colors() == FALSE) { + endwin(); + std::exit(1); + } + start_color(); + + uc i = 0; + while (1) { + assert(i == ncurses::curses_to_rgb(ncurses::rgb_to_curses(i))); + if (i == 255) + break; + i++; + } + + // TODO: what if user wants to use color/pair as rvalue, or instantiate it as + // a variable? Problem is current realization only accepts api as above. + // Should I forbid anything else or somehow extend functionality? + + endwin(); + return 0; +} |