feat(console coloring): implemented base types
This commit is contained in:
parent
dad7db99d8
commit
acee93cf39
2 changed files with 47 additions and 15 deletions
32
Include/Iony/Utils/Base.h
Normal file
32
Include/Iony/Utils/Base.h
Normal file
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue