diff --git a/cbuild b/cbuild index 9711d8f..5e23ef8 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 9711d8fbb1bf947101f475c8cf918009a4d39110 +Subproject commit 5e23ef8156a85a981d60152990bde53d6e8eefe9 diff --git a/default.config b/default.config index ed5e313..d49a3e4 100644 --- a/default.config +++ b/default.config @@ -42,8 +42,7 @@ case "$TASK" in # -flto=auto is needed to multithreaded copilation # -fuse-linker-plugin is required to use static libs with lto, it strips away all # -fdata-sections -ffunction-sections -Wl,--gc-sections removes unused code - C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects \ --fdata-sections -ffunction-sections -Wl,--gc-sections" + C_ARGS="-O2 -flto=auto -fuse-linker-plugin -fprofile-use -fprofile-prefix-path=$(realpath $OBJDIR)/objects -fdata-sections -ffunction-sections -Wl,--gc-sections" CPP_ARGS="$C_ARGS" LINKER_ARGS="$CPP_ARGS" PRE_TASK_SCRIPT=tasks/pre_build.sh @@ -65,7 +64,7 @@ case "$TASK" in ;; # executes $EXEC_FILE with valgrind memory checker valgrind) - VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all" + VALGRIND_ARGS="-s --read-var-info=yes --track-origins=yes --fullpath-after=$PROJECT/ --leak-check=full --show-leak-kinds=all" TASK_SCRIPT=cbuild/default_tasks/valgrind.sh ;; # generates profiling info diff --git a/kerep b/kerep index ededa87..d713605 160000 --- a/kerep +++ b/kerep @@ -1 +1 @@ -Subproject commit ededa875d6d1b5947e4516588489b1c8c64e940f +Subproject commit d7136055d92e90070b947f1662b3fa6981eecdc0 diff --git a/src/main.c b/src/main.c index 0a2e17d..cfc3092 100644 --- a/src/main.c +++ b/src/main.c @@ -20,39 +20,54 @@ Maybe tryReadFile(char* filePath){ i32 main(const i32 argc, const char* const* argv){ #if _WIN32 || _WIN64 if(!SetConsoleOutputCP(CP_UTF8)){ - kprintf("\e[93mcan't set console codepage to utf8"); + kprintf("\e[91mcan't set console codepage to utf8"); + return 1; } #endif if(setlocale(LC_ALL, "C.UTF8")==0){ // doesn't work on windows - kprintf("\e[93msetlocale failed! (%i)\n", errno); + kprintf("\e[91msetlocale failed! (%i)\n", errno); + return 1; } + // term_cursorHide(true); + // term_clear(); + + // kerep type system kt_beginInit(); kt_initKerepTypes(); kt_initScolteTypes(); kt_endInit(); + // print command line arguments kprintf("\e[37margs:"); for(i32 i=0; i1 ? argv[argc-1] : "new_file.txt"; tryLast(tryReadFile(filePath), _m_text); char* text=(char*)_m_text.value.VoidPtr; fputs(text,stdout); */ + // render ui Renderer* renderer=Renderer_create(); TextBlock* testTextBlock=TextBlock_create(string_fromCptr("some example text")); Autoarr(UIElement_Ptr)* grid_content=Autoarr_create(UIElement_Ptr, 1, 64); Autoarr_add(grid_content, (UIElement_Ptr)testTextBlock); Grid* mainGrid=Grid_create(1,1, Autoarr_toArray(grid_content)); + Autoarr_free(grid_content, true); tryLast(UIElement_draw(renderer, (UIElement_Ptr)mainGrid, ((DrawingArea){.x=10, .y=4, .h=7, .w=24})),_); tryLast(Renderer_drawFrame(renderer),_2); - + // free ui memory UIElement_destroy((UIElement_Ptr)mainGrid); Renderer_destroy(renderer); + // TODO signal( SIGWINCH, redraw ); + + // exit kt_free(); + term_resetColors(); + term_cursorHide(false); return 0; } diff --git a/src/term/term.c b/src/term/term.c index 7e32e31..01c5b24 100644 --- a/src/term/term.c +++ b/src/term/term.c @@ -15,6 +15,13 @@ kt_define(TerminalSize, NULL, __TerminalSize_toString); TerminalSize term_default_size={.cols=80, .rows=16}; +int getenv_int(const char* var_name){ + char* str=getenv(var_name); + if(str==NULL) + return -1; + return strtol(str, NULL, 0); +} + bool term_getSize(TerminalSize* out) { #if defined(_WIN64) || defined(_WIN32) // helps when STD_OUT is redirected to a file @@ -27,22 +34,30 @@ bool term_getSize(TerminalSize* out) { .rows=consoleInfo.srWindow.Bottom-consoleInfo.srWindow.Top+1 }; #else - struct winsize w={0,0,0,0}; - if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w)!=0) - return false; - *out=(TerminalSize){ - .cols=w.ws_col, - .rows=w.ws_row - }; + struct winsize ws={0,0,0,0}; + // tries to get terminal size from stdin, stdout, stderr + if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)==0 || + ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)==0 || + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws)==0 ){ + out->cols=ws.ws_col; + out->rows=ws.ws_row; + } + // tries to get size from environtent variables + else{ + out->cols=getenv_int("COLUMNS"); + out->rows=getenv_int("LINES"); + } #endif - return true; + return out->cols > 0 && out->cols < 720 && out->rows > 0 && out->rows < 480; } +/* +Most of escape sequences can be found at: +https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 +*/ -void term_moveCursor(u16 row, u16 column){ - printf("\e[%u;%uf",row,column); -} - -void term_clear() { - printf("\e[2j"); -} +void term_resetCursor() { printf("\e[H"); } +void term_resetColors() { printf("\e[0m"); } +void term_clear() { printf("\e[0m\e[H\e[2J"); } +void term_cursorMove(u16 row, u16 column) { printf("\e[%u;%uH",row,column); } +void term_cursorHide(bool hide) { printf( hide ? "\e[?25l" : "\e[?25h"); } \ No newline at end of file diff --git a/src/term/term.h b/src/term/term.h index 2a71424..d5a8166 100644 --- a/src/term/term.h +++ b/src/term/term.h @@ -8,8 +8,11 @@ extern "C" { #include "../../kerep/src/kprint/kprint_format.h" #include "../encoding/encoding.h" -void term_moveCursor(u16 row, u16 column); +void term_resetCursor(); +void term_resetColors(); void term_clear(); +void term_cursorMove(u16 row, u16 column); +void term_cursorHide(bool hide); STRUCT(TerminalSize, u16 cols;