feat(console coloring): removed the standard c lib
This commit is contained in:
parent
20db36cd82
commit
7447d6ab45
4 changed files with 40 additions and 18 deletions
|
|
@ -10,12 +10,18 @@ file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/Src/*.c")
|
||||||
add_library(Iony STATIC ${SRC_FILES})
|
add_library(Iony STATIC ${SRC_FILES})
|
||||||
add_executable(IonyTest ${PROJECT_SOURCE_DIR}/Tests/Main.c)
|
add_executable(IonyTest ${PROJECT_SOURCE_DIR}/Tests/Main.c)
|
||||||
|
|
||||||
target_link_libraries(Iony PRIVATE ${HALLOCY_LIB_PATH})
|
|
||||||
target_include_directories(IonyTest PRIVATE ${PROJECT_SOURCE_DIR}/Tests)
|
target_include_directories(IonyTest PRIVATE ${PROJECT_SOURCE_DIR}/Tests)
|
||||||
target_link_libraries(IonyTest Iony)
|
target_link_libraries(IonyTest Iony)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(Iony PRIVATE /W4 /Zl)
|
target_compile_options(Iony PRIVATE /W4 /Zl /GS- /kernel)
|
||||||
|
|
||||||
|
target_link_options(IonyTest PRIVATE /NODEFAULTLIB /ENTRY:_start)
|
||||||
|
|
||||||
|
target_link_libraries(Iony PRIVATE kernel32)
|
||||||
|
target_link_libraries(IonyTest PRIVATE kernel32)
|
||||||
else()
|
else()
|
||||||
target_compile_options(Iony PRIVATE -Wall -Wextra -pedantic)
|
target_compile_options(Iony PRIVATE -Wall -Wextra -pedantic -ffreestanding -fno-builtin)
|
||||||
|
target_link_options(Iony PRIVATE -nostdlib)
|
||||||
|
target_link_options(IonyTest PRIVATE -nostdlib)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -23,19 +23,26 @@
|
||||||
#ifndef IONY_SYSTEM
|
#ifndef IONY_SYSTEM
|
||||||
#define IONY_SYSTEM
|
#define IONY_SYSTEM
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
#define IONY_SYS_READ 0
|
#define IONY_SYS_READ 0
|
||||||
#define IONY_SYS_WRITE 1
|
#define IONY_SYS_WRITE 1
|
||||||
|
#define IONY_SYS_EXIT 60
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
#define IONY_SYS_READ 3
|
#define IONY_SYS_READ 3
|
||||||
#define IONY_SYS_WRITE 4
|
#define IONY_SYS_WRITE 4
|
||||||
|
#define IONY_SYS_EXIT 1
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
#define IONY_SYS_READ 63
|
#define IONY_SYS_READ 63
|
||||||
#define IONY_SYS_WRITE 64
|
#define IONY_SYS_WRITE 64
|
||||||
|
#define IONY_SYS_EXIT 93
|
||||||
#elif defined(__arm__)
|
#elif defined(__arm__)
|
||||||
#define IONY_SYS_READ 3
|
#define IONY_SYS_READ 3
|
||||||
#define IONY_SYS_WRITE 4
|
#define IONY_SYS_WRITE 4
|
||||||
|
#define IONY_SYS_EXIT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline long iony_system_call(long number, long argument1, long argument2, long argument3, long argument4, long argument5, long argument6) {
|
static inline long iony_system_call(long number, long argument1, long argument2, long argument3, long argument4, long argument5, long argument6) {
|
||||||
|
|
@ -98,6 +105,16 @@ static inline long iony_system_call(long number, long argument1, long argument2,
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#error "Unsupported architecture"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline void iony_exit_process(int exit_code) {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
ExitProcess(exit_code);
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
iony_system_call(IONY_SYS_EXIT, exit_code, 0, 0, 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,15 @@
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
#include "../../Include/Iony/Core/Console.h"
|
#include "../../Include/Iony/Core/Console.h"
|
||||||
#include "Iony/Utils/Error.h"
|
|
||||||
|
#include "../../Include/Iony/Utils/System.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
static HANDLE iony_standard_console_out = 0;
|
static HANDLE iony_standard_console_out = 0;
|
||||||
static HANDLE iony_standard_console_in = 0;
|
static HANDLE iony_standard_console_in = 0;
|
||||||
|
|
||||||
static WORD iony_original_console_attributes = 0;
|
static WORD iony_original_console_attributes = 0;
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#include "../../Include/Iony/Utils/System.h"
|
|
||||||
|
|
||||||
static const char IONY_RESET_COLOR[] = "\033[0m";
|
static const char IONY_RESET_COLOR[] = "\033[0m";
|
||||||
static const char *IONY_ANSI_COLORS[] = {
|
static const char *IONY_ANSI_COLORS[] = {
|
||||||
|
|
|
||||||
21
Tests/Main.c
21
Tests/Main.c
|
|
@ -19,45 +19,46 @@
|
||||||
* Author: Mineplay
|
* Author: Mineplay
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#include <Iony/Utils/System.h>
|
||||||
#include <Iony/Utils/Error.h>
|
#include <Iony/Utils/Error.h>
|
||||||
#include <Iony/Core/Console.h>
|
#include <Iony/Core/Console.h>
|
||||||
|
|
||||||
int main(void) {
|
void _start(void) {
|
||||||
if (iony_console_print("Press enter to continue...", 27) != IONY_ERROR_NONE) {
|
if (iony_console_print("Press enter to continue...", 27) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char character = ' ';
|
char character = ' ';
|
||||||
if (iony_console_get_character(&character) != IONY_ERROR_NONE) {
|
if (iony_console_get_character(&character) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iony_console_clear() != IONY_ERROR_NONE) {
|
if (iony_console_clear() != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iony_console_print("Enter your name: ", 18) != IONY_ERROR_NONE) {
|
if (iony_console_print("Enter your name: ", 18) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char name_input[256];
|
char name_input[256];
|
||||||
long characters_read = 0;
|
long characters_read = 0;
|
||||||
if (iony_console_get_line(name_input, 256, &characters_read) != IONY_ERROR_NONE) {
|
if (iony_console_get_line(name_input, 256, &characters_read) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
iony_console_set_color(IONY_CONSOLE_COLOR_LIGHT_RED);
|
iony_console_set_color(IONY_CONSOLE_COLOR_LIGHT_RED);
|
||||||
if (iony_console_print("Your name is ", 14) != IONY_ERROR_NONE) {
|
if (iony_console_print("Your name is ", 14) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iony_console_print(name_input, characters_read) != IONY_ERROR_NONE) {
|
if (iony_console_print(name_input, characters_read) != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iony_console_reset_color() != IONY_ERROR_NONE) {
|
if (iony_console_reset_color() != IONY_ERROR_NONE) {
|
||||||
return -1;
|
iony_exit_process(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
iony_exit_process(0);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue