From acee93cf39a207b386819a4955ed92476710bbb2 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Mon, 20 Oct 2025 09:22:00 -0500 Subject: [PATCH] feat(console coloring): implemented base types --- Include/Iony/Utils/Base.h | 32 ++++++++++++++++++++++++++++++++ Src/Core/Console.c | 30 +++++++++++++++--------------- 2 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 Include/Iony/Utils/Base.h diff --git a/Include/Iony/Utils/Base.h b/Include/Iony/Utils/Base.h new file mode 100644 index 0000000..f2d9443 --- /dev/null +++ b/Include/Iony/Utils/Base.h @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Console.h + * Description: + * This file contains base c types like bool. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef IONY_BOOL +#define IONY_BOOL + +#define IONY_NULL ((void*)0) + +typedef enum { + IONY_BOOL_FALSE = 0, + IONY_BOOL_TRUE = 1 +} IonyBool; + +#endif diff --git a/Src/Core/Console.c b/Src/Core/Console.c index 55fdce5..a0f1ad6 100644 --- a/Src/Core/Console.c +++ b/Src/Core/Console.c @@ -22,12 +22,12 @@ #include "../../Include/Iony/Core/Console.h" #include "../../Include/Iony/Utils/System.h" -#include "Iony/Utils/Error.h" +#include "../../Include/Iony/Utils/Base.h" #if defined(_WIN32) -static HANDLE iony_standard_console_out = 0; -static HANDLE iony_standard_console_in = 0; -static HANDLE iony_standard_console_error = 0; +static HANDLE iony_standard_console_out = IONY_NULL; +static HANDLE iony_standard_console_in = IONY_NULL; +static HANDLE iony_standard_console_error = IONY_NULL; static WORD iony_original_console_attributes = 0; #elif defined(__GNUC__) @@ -53,12 +53,12 @@ static const char IONY_ANSI_COLORS[][8] = { #endif IonyError iony_console_print(const char *text, const unsigned long length) { - if (text == 0) { + if (text == IONY_NULL) { return IONY_ERROR_INVALID_POINTER; } #if defined(_WIN32) - if (iony_standard_console_out == 0) { + if (iony_standard_console_out == IONY_NULL) { iony_standard_console_out = GetStdHandle(STD_OUTPUT_HANDLE); if (iony_standard_console_out == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -79,12 +79,12 @@ IonyError iony_console_print(const char *text, const unsigned long length) { } IonyError iony_console_error(const char *text, unsigned long length) { - if (text == 0) { + if (text == IONY_NULL) { return IONY_ERROR_INVALID_POINTER; } #if defined(_WIN32) - if (iony_standard_console_error == 0) { + if (iony_standard_console_error == IONY_NULL) { iony_standard_console_error = GetStdHandle(STD_ERROR_HANDLE); if (iony_standard_console_error == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -106,7 +106,7 @@ IonyError iony_console_error(const char *text, unsigned long length) { IonyError iony_console_clear(void) { #if defined(_WIN32) - if (iony_standard_console_out == 0) { + if (iony_standard_console_out == IONY_NULL) { iony_standard_console_out = GetStdHandle(STD_OUTPUT_HANDLE); if (iony_standard_console_out == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -140,12 +140,12 @@ IonyError iony_console_clear(void) { } IonyError iony_console_get_character(char *character) { - if (character == 0) { + if (character == IONY_NULL) { return IONY_ERROR_INVALID_POINTER; } #if defined(_WIN32) - if (iony_standard_console_in == 0) { + if (iony_standard_console_in == IONY_NULL) { iony_standard_console_in = GetStdHandle(STD_INPUT_HANDLE); if (iony_standard_console_in == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -172,12 +172,12 @@ IonyError iony_console_get_character(char *character) { } IonyError iony_console_get_line(char *character_string, const long max_length, unsigned long *characters_read) { - if (character_string == 0) { + if (character_string == IONY_NULL) { return IONY_ERROR_INVALID_POINTER; } #if defined(_WIN32) - if (iony_standard_console_in == 0) { + if (iony_standard_console_in == IONY_NULL) { iony_standard_console_in = GetStdHandle(STD_INPUT_HANDLE); if (iony_standard_console_in == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -201,7 +201,7 @@ IonyError iony_console_get_line(char *character_string, const long max_length, u IonyError iony_console_set_color(IonyConsoleColor color) { #if defined(_WIN32) - if (iony_standard_console_out == 0) { + if (iony_standard_console_out == IONY_NULL) { iony_standard_console_out = GetStdHandle(STD_OUTPUT_HANDLE); if (iony_standard_console_out == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND; @@ -231,7 +231,7 @@ IonyError iony_console_set_color(IonyConsoleColor color) { IonyError iony_console_reset_color(void) { #if defined(_WIN32) - if (iony_standard_console_out == 0) { + if (iony_standard_console_out == IONY_NULL) { iony_standard_console_out = GetStdHandle(STD_OUTPUT_HANDLE); if (iony_standard_console_out == INVALID_HANDLE_VALUE) { return IONY_ERROR_HANDLE_NOT_FOUND;