kt_register for all types

This commit is contained in:
Timerix22 2023-05-19 20:21:55 +06:00
parent 768c55af4a
commit 9febbe1de0
7 changed files with 51 additions and 29 deletions

View File

@ -1,10 +1,5 @@
#include "tui_internal.h" #include "tui_internal.h"
int TCI_fwrite(FILE* file, TermCharInfo tci){
kprint_setColor(tci.color);
return termchar_fwrite(file, tci.ch);
}
////////////////////////////////////// //////////////////////////////////////
// FrameBuffer // // FrameBuffer //
////////////////////////////////////// //////////////////////////////////////

View File

@ -4,8 +4,14 @@ kt_define(DrawingArea, NULL, NULL);
kt_define(UIBorder, NULL, NULL); kt_define(UIBorder, NULL, NULL);
void kt_initScolteTypes(){ void kt_initScolteTypes(){
// term
kt_register(TerminalSize);
kt_register(TermCharInfo);
// tui
kt_register(DrawingArea); kt_register(DrawingArea);
kt_register(UIBorder); kt_register(UIBorder);
kt_register(FrameBuffer);
kt_register(Renderer);
kt_register(UIElement); kt_register(UIElement);
kt_register(Grid); kt_register(Grid);
kt_register(TextBlock); kt_register(TextBlock);

View File

@ -5,7 +5,6 @@ extern "C" {
#endif #endif
#include "../../kerep/src/String/string.h" #include "../../kerep/src/String/string.h"
#include "../../kerep/src/kprint/kprint_format.h"
#include "../../kerep/src/Array/Array.h" #include "../../kerep/src/Array/Array.h"
#include "../term/term.h" #include "../term/term.h"
#include "../encoding/encoding.h" #include "../encoding/encoding.h"
@ -43,17 +42,9 @@ STRUCT(UIBorder,
UIBorderThickness left; UIBorderThickness left;
UIBorderThickness top; UIBorderThickness top;
UIBorderThickness bottom; 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 // // Renderer //
@ -99,7 +90,7 @@ STRUCT(UIElement,
u16 min_height; u16 min_height;
u16 width_scaling; u16 width_scaling;
u16 height_scaling; u16 height_scaling;
kp_fmt color; termcolor color;
UIBorder border; UIBorder border;
UIElement_draw_t draw; UIElement_draw_t draw;
) )

View File

@ -15,11 +15,6 @@ typedef u32 utf32char;
///@returns <0 error code of fputc ///@returns <0 error code of fputc
int utf32char_fwrite(FILE* file, utf32char ch); 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 #if __cplusplus
} }
#endif #endif

8
src/term/TermCharInfo.c Normal file
View File

@ -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);
}

View File

@ -3,14 +3,17 @@
#include <unistd.h> #include <unistd.h>
#include IFWIN("windows.h", "sys/ioctl.h") #include IFWIN("windows.h", "sys/ioctl.h")
void term_moveCursor(u16 row, u16 column){ char* TerminalSize_toString(TerminalSize t){
printf("\e[%u;%uf",row,column); char buf[64];
sprintf_s(buf, sizeof(buf), "(%ux%u)", t.cols, t.rows);
return cptr_copy(buf);
} }
void term_clear() { char* __TerminalSize_toString(void* _t, u32 fmt){ return TerminalSize_toString(*(TerminalSize*)_t); }
printf("\e[2j");
} kt_define(TerminalSize, NULL, __TerminalSize_toString);
TerminalSize term_default_size={.cols=80, .rows=16};
bool term_getSize(TerminalSize* out) { bool term_getSize(TerminalSize* out) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
@ -35,4 +38,11 @@ bool term_getSize(TerminalSize* out) {
return true; 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");
}

View File

@ -5,13 +5,15 @@ extern "C" {
#endif #endif
#include "../../kerep/src/base/base.h" #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_moveCursor(u16 row, u16 column);
void term_clear(); void term_clear();
STRUCT(TerminalSize, STRUCT(TerminalSize,
u16 rows;
u16 cols; u16 cols;
u16 rows;
) )
///@return TRUE if have got terminal size, otherwise FALSE ///@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 /// can be used if term_getSize() fails
extern TerminalSize term_default_size; 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 #if __cplusplus
} }
#endif #endif