diff --git a/src/TUI/Renderer.c b/src/TUI/Renderer.c index 1350702..c58342c 100644 --- a/src/TUI/Renderer.c +++ b/src/TUI/Renderer.c @@ -1,10 +1,5 @@ #include "tui_internal.h" -int TCI_fwrite(FILE* file, TermCharInfo tci){ - kprint_setColor(tci.color); - return termchar_fwrite(file, tci.ch); -} - ////////////////////////////////////// // FrameBuffer // ////////////////////////////////////// diff --git a/src/TUI/tui.c b/src/TUI/tui.c index 2a35b68..74ce8a7 100644 --- a/src/TUI/tui.c +++ b/src/TUI/tui.c @@ -4,8 +4,14 @@ kt_define(DrawingArea, NULL, NULL); kt_define(UIBorder, NULL, NULL); void kt_initScolteTypes(){ + // term + kt_register(TerminalSize); + kt_register(TermCharInfo); + // tui kt_register(DrawingArea); kt_register(UIBorder); + kt_register(FrameBuffer); + kt_register(Renderer); kt_register(UIElement); kt_register(Grid); kt_register(TextBlock); diff --git a/src/TUI/tui.h b/src/TUI/tui.h index 88bb9fa..6be3c9d 100644 --- a/src/TUI/tui.h +++ b/src/TUI/tui.h @@ -5,7 +5,6 @@ extern "C" { #endif #include "../../kerep/src/String/string.h" -#include "../../kerep/src/kprint/kprint_format.h" #include "../../kerep/src/Array/Array.h" #include "../term/term.h" #include "../encoding/encoding.h" @@ -43,17 +42,9 @@ STRUCT(UIBorder, UIBorderThickness left; UIBorderThickness top; UIBorderThickness bottom; - kp_fmt color; + termcolor color; ) -STRUCT(TermCharInfo, - termchar ch; - kp_fmt color; /* background + foreground */ -) - -#define TCI(CH,COLOR)(TermCharInfo){.ch=CH, .color=COLOR} -int TCI_fwrite(FILE* file, TermCharInfo tci); -#define TCI_print(tci) TCI_fwrite(stdout, tci); ////////////////////////////////////// // Renderer // @@ -99,7 +90,7 @@ STRUCT(UIElement, u16 min_height; u16 width_scaling; u16 height_scaling; - kp_fmt color; + termcolor color; UIBorder border; UIElement_draw_t draw; ) diff --git a/src/encoding/encoding.h b/src/encoding/encoding.h index 2255c3d..a527fda 100644 --- a/src/encoding/encoding.h +++ b/src/encoding/encoding.h @@ -15,11 +15,6 @@ typedef u32 utf32char; ///@returns <0 error code of fputc int utf32char_fwrite(FILE* file, utf32char ch); -typedef utf32char termchar; -#define TERMCHAR(CHAR) U##CHAR -#define TERMSTR(STR) U##STR -#define termchar_fwrite utf32char_fwrite - #if __cplusplus } #endif diff --git a/src/term/TermCharInfo.c b/src/term/TermCharInfo.c new file mode 100644 index 0000000..3ac9d31 --- /dev/null +++ b/src/term/TermCharInfo.c @@ -0,0 +1,8 @@ +#include "term.h" + +kt_define(TermCharInfo, NULL, NULL); + +int TCI_fwrite(FILE* file, TermCharInfo tci){ + kprint_setColor(tci.color); + return termchar_fwrite(file, tci.ch); +} diff --git a/src/term/term.c b/src/term/term.c index e41dfbf..7e32e31 100644 --- a/src/term/term.c +++ b/src/term/term.c @@ -3,14 +3,17 @@ #include #include IFWIN("windows.h", "sys/ioctl.h") -void term_moveCursor(u16 row, u16 column){ - printf("\e[%u;%uf",row,column); - +char* TerminalSize_toString(TerminalSize t){ + char buf[64]; + sprintf_s(buf, sizeof(buf), "(%ux%u)", t.cols, t.rows); + return cptr_copy(buf); } -void term_clear() { - printf("\e[2j"); -} +char* __TerminalSize_toString(void* _t, u32 fmt){ return TerminalSize_toString(*(TerminalSize*)_t); } + +kt_define(TerminalSize, NULL, __TerminalSize_toString); + +TerminalSize term_default_size={.cols=80, .rows=16}; bool term_getSize(TerminalSize* out) { #if defined(_WIN64) || defined(_WIN32) @@ -35,4 +38,11 @@ bool term_getSize(TerminalSize* out) { return true; } -TerminalSize term_default_size={.cols=80, .rows=16}; + +void term_moveCursor(u16 row, u16 column){ + printf("\e[%u;%uf",row,column); +} + +void term_clear() { + printf("\e[2j"); +} diff --git a/src/term/term.h b/src/term/term.h index 2bc9cdd..2a71424 100644 --- a/src/term/term.h +++ b/src/term/term.h @@ -5,13 +5,15 @@ extern "C" { #endif #include "../../kerep/src/base/base.h" +#include "../../kerep/src/kprint/kprint_format.h" +#include "../encoding/encoding.h" void term_moveCursor(u16 row, u16 column); void term_clear(); STRUCT(TerminalSize, - u16 rows; u16 cols; + u16 rows; ) ///@return TRUE if have got terminal size, otherwise FALSE @@ -20,6 +22,21 @@ bool term_getSize(TerminalSize* out) WARN_UNUSED_REZULT; /// can be used if term_getSize() fails extern TerminalSize term_default_size; +typedef kp_fmt termcolor; +typedef utf32char termchar; +#define TERMCHAR(CHAR) U##CHAR +#define TERMSTR(STR) U##STR +#define termchar_fwrite utf32char_fwrite + +STRUCT(TermCharInfo, + termchar ch; + termcolor color; /* background + foreground */ +) + +#define TCI(CH,COLOR)(TermCharInfo){.ch=CH, .color=COLOR} +int TCI_fwrite(FILE* file, TermCharInfo tci); +#define TCI_print(tci) TCI_fwrite(stdout, tci); + #if __cplusplus } #endif