13#include <notcurses/nckeys.h>
28 log_msg(ERROR,
"output_handler",
"Null Notcurses instance provided");
33 log_msg(ERROR,
"output_handler",
"Null standard plane provided");
41 log_msg(ERROR,
"output_handler",
"Output handler not initialized");
46 ncplane_set_base(stdplane,
" ", 0, DEFAULT_COLORS);
47 ncplane_erase(stdplane);
50void print_text(
int y,
int x,
const char* text, uint64_t ncchannel) {
51 if (!stdplane || !text) {
52 log_msg(ERROR,
"output_handler",
"Output handler not initialized or null text");
57 ncplane_set_channels(stdplane, ncchannel);
58 ncplane_putstr_yx(stdplane, y, x, text);
65void print_text_multi_line(
int y,
int x,
const char* text,
int max_width, uint64_t ncchannel) {
66 if (!stdplane || !text || max_width <= 0) {
67 log_msg(ERROR,
"output_handler",
"Invalid parameters for print_text_multi_line");
72 ncplane_set_channels(stdplane, ncchannel);
75 const char* ptr = text;
78 char line_buffer[256];
83 while (*ptr && *ptr !=
'\n' && line_len < max_width) {
84 line_buffer[line_len++] = *ptr++;
86 line_buffer[line_len] =
'\0';
89 ncplane_putstr_yx(stdplane, current_y, x, line_buffer);
100 print_text_multi_line(y, x, text, max_width, DEFAULT_COLORS);
104 if (!stdplane || !text || count <= 0) {
105 log_msg(ERROR,
"output_handler",
"Invalid parameters for print_text_multi_strings");
110 ncplane_set_channels(stdplane, ncchannel);
113 for (
int i = 0; i < count; i++) {
115 ncplane_putstr_yx(stdplane, y + i, x, text[i]);
124void print_menu(
const char* title,
const char** options,
int option_count,
125 int selected_index,
int y,
int x,
126 uint64_t title_channel,
127 uint64_t option_channel,
128 uint64_t selected_channel) {
129 if (!stdplane || !title || !options || option_count <= 0) {
130 log_msg(ERROR,
"output_handler",
"Invalid menu parameters");
135 ncplane_set_channels(stdplane, title_channel);
136 ncplane_putstr_yx(stdplane, y, x, title);
139 for (
int i = 0; i < option_count; i++) {
140 if (i == selected_index) {
142 ncplane_set_channels(stdplane, selected_channel);
144 ncplane_set_channels(stdplane, option_channel);
146 ncplane_putstr_yx(stdplane, y + i + 1, x, options[i]);
151 int selected_index,
int y,
int x) {
152 print_menu(title, options, option_count, selected_index, y, x,
153 DEFAULT_COLORS, DEFAULT_COLORS, INVERTED_COLORS);
157 const char* confirm_msg,
int y,
int x) {
158 if (!stdplane || !buffer || buffer_size <= 0) {
159 log_msg(ERROR,
"output_handler",
"Invalid parameters for get_text_input");
164 memset(buffer, 0, buffer_size);
166 bool input_active =
true;
167 bool confirmed =
false;
169 while (input_active) {
194 uint32_t key_id = input_event.raw_input.id;
196 if (input_event.type == INPUT_CONFIRM && text_length > 0) {
198 input_active =
false;
200 }
else if (input_event.type == INPUT_CANCEL) {
202 input_active =
false;
204 }
else if (key_id == NCKEY_BACKSPACE && text_length > 0) {
206 buffer[--text_length] =
'\0';
207 }
else if (key_id != 0 && text_length < buffer_size - 1 &&
208 !(input_event.type == INPUT_UP ||
209 input_event.type == INPUT_DOWN ||
210 input_event.type == INPUT_LEFT ||
211 input_event.type == INPUT_RIGHT)) {
213 buffer[text_length++] = key_id;
214 buffer[text_length] =
'\0';
222 if (!stdplane || !message) {
223 log_msg(ERROR,
"output_handler",
"Invalid parameters for show_message_screen");
234 if (continue_message) {
248 log_msg(ERROR,
"output_handler",
"Output handler not initialized");
253 int ret = notcurses_render(nc);
258 if (!stdplane || !width || !height) {
259 log_msg(ERROR,
"output_handler",
"Invalid parameters for get_screen_dimensions");
264 *width = ncplane_dim_x(stdplane);
265 *height = ncplane_dim_y(stdplane);
Defines common macros, types, and global variables for color schemes and utilities.
Exposes functions for the IO-Handler.
void log_msg(const log_level_t level, const char *module, const char *format,...)
Logs a formatted message with a specified log level and module.
Header file for logging functionality of the game.
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
bool get_text_input(const char *prompt, char *buffer, int buffer_size, const char *confirm_msg, int y, int x)
Get a text input from the user.
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.
void print_text_multi_strings_default(int y, int x, const char *text[], int count)
Print multiple strings on consecutive lines with default colors.
void shutdown_output_handler(void)
Shutdown the output handler.
bool render_frame(void)
Render the current frame.
bool init_output_handler()
Initialize the output handler.
bool get_screen_dimensions(int *width, int *height)
Get the dimensions of the standard plane.
void print_menu(const char *title, const char **options, int option_count, int selected_index, int y, int x, uint64_t title_channel, uint64_t option_channel, uint64_t selected_channel)
Print a menu with selection highlighting.
void clear_screen(void)
Clear the screen.
void print_text_multi_line_default(int y, int x, const char *text, int max_width)
Print multi-line text with word wrapping and default colors.
void print_text_multi_strings(int y, int x, const char *text[], int count, uint64_t ncchannel)
Print multiple strings on consecutive lines.
void show_message_screen(const char *message, const char *continue_message, int y, int x)
Show a message screen.
void print_menu_default(const char *title, const char **options, int option_count, int selected_index, int y, int x)
Print a menu with selection highlighting using default colors.
Exposes functions for outputting to the console.