From 151ad138532a7d913c53770de1ea5365036c1759 Mon Sep 17 00:00:00 2001 From: Timerix Date: Fri, 9 Jan 2026 06:12:17 +0500 Subject: [PATCH] added dependency: tim --- .gitmodules | 3 +++ .vscode/c_cpp_properties.json | 1 + .vscode/launch.json | 4 ++-- dependencies/tim | 1 + dependencies/tim.config | 19 +++++++++++++++++++ dependencies/tlibc | 2 +- project.config | 5 +++-- src/cli/ClientCLI/ClientCLI.c | 29 ++++++++++++++++++++++++++++- 8 files changed, 58 insertions(+), 6 deletions(-) create mode 160000 dependencies/tim create mode 100644 dependencies/tim.config diff --git a/.gitmodules b/.gitmodules index 63dc7d7..0175a6e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "dependencies/tsqlite"] path = dependencies/tsqlite url = https://timerix.ddns.net/git/Timerix/tsqlite.git +[submodule "dependencies/tim"] + path = dependencies/tim + url = https://timerix.ddns.net/git/Timerix/tim.git diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index c817fd8..028292c 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -10,6 +10,7 @@ "dependencies/tlibc/include", "dependencies/tlibtoml/include", "dependencies/tsqlite/include", + "dependencies/tim/include", "${default}" ], "cStandard": "c99" diff --git a/.vscode/launch.json b/.vscode/launch.json index 92b24fb..7eb0427 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}/bin", - "externalConsole": false, + "externalConsole": true, "internalConsoleOptions": "neverOpen", "MIMode": "gdb", "miDebuggerPath": "gdb" @@ -25,7 +25,7 @@ "stopAtEntry": false, "cwd": "${workspaceFolder}/bin", - "externalConsole": false, + "externalConsole": true, "internalConsoleOptions": "neverOpen", "MIMode": "gdb", "miDebuggerPath": "gdb" diff --git a/dependencies/tim b/dependencies/tim new file mode 160000 index 0000000..161f655 --- /dev/null +++ b/dependencies/tim @@ -0,0 +1 @@ +Subproject commit 161f6554927e254369333051fa942d3a432fb2b0 diff --git a/dependencies/tim.config b/dependencies/tim.config new file mode 100644 index 0000000..a19d45d --- /dev/null +++ b/dependencies/tim.config @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# This is a dependency config. +# You can copy it to another cbuild project to add this lib as dependency. + +DEP_WORKING_DIR="$DEPENDENCIES_DIR/tim" +if [[ "$TASK" = *_dbg ]]; then + dep_build_target="build_static_lib_dbg" +else + dep_build_target="build_static_lib" +fi +DEP_PRE_BUILD_COMMAND="" +DEP_BUILD_COMMAND="cbuild $dep_build_target" +DEP_POST_BUILD_COMMAND="" +DEP_CLEAN_COMMAND="cbuild clean" +DEP_DYNAMIC_OUT_FILES="" +DEP_STATIC_OUT_FILES="bin/tim.a" +DEP_OTHER_OUT_FILES="" +PRESERVE_OUT_DIRECTORY_STRUCTURE=false diff --git a/dependencies/tlibc b/dependencies/tlibc index de88e9f..4cfed24 160000 --- a/dependencies/tlibc +++ b/dependencies/tlibc @@ -1 +1 @@ -Subproject commit de88e9ff168cbb71d4ab4c48df949b2e25d1b23d +Subproject commit 4cfed24ec3f56a6709fc2c53e8aef8bd70da1b58 diff --git a/project.config b/project.config index fde2540..039b2b2 100644 --- a/project.config +++ b/project.config @@ -24,7 +24,7 @@ SRC_CPP="$(find src -name '*.cpp')" # See cbuild/example_dependency_configs DEPENDENCY_CONFIGS_DIR='dependencies' # List of dependency config files in DEPENDENCY_CONFIGS_DIR separated by space. -ENABLED_DEPENDENCIES='bearssl tlibc tlibtoml tsqlite' +ENABLED_DEPENDENCIES='bearssl tlibc tlibtoml tsqlite tim' # OBJDIR structure: # ├── objects/ - Compiled object files. Cleans on each call of build task @@ -39,7 +39,8 @@ INCLUDE="-Isrc -Iinclude -I$DEPENDENCIES_DIR/BearSSL/inc -I$DEPENDENCIES_DIR/tlibc/include -I$DEPENDENCIES_DIR/tlibtoml/include - -I$DEPENDENCIES_DIR/tsqlite/include" + -I$DEPENDENCIES_DIR/tsqlite/include + -I$DEPENDENCIES_DIR/tim/include" # OS-specific options case "$OS" in diff --git a/src/cli/ClientCLI/ClientCLI.c b/src/cli/ClientCLI/ClientCLI.c index d81923f..a5282d6 100644 --- a/src/cli/ClientCLI/ClientCLI.c +++ b/src/cli/ClientCLI/ClientCLI.c @@ -2,6 +2,7 @@ #include "tlibc/filesystem.h" #include "tlibc/term.h" #include "network/tcp-chat-protocol/v1.h" +#include "tim.h" static const str greeting_art = STR( " ^,,^ ╱|\n" @@ -48,7 +49,33 @@ void ClientCLI_construct(ClientCLI* self){ Result(void) ClientCLI_run(ClientCLI* self) { Deferral(16); - try_void(term_init()); + TimEditState e; + TimEditState_init(&e, 32, "Greetings!"); + bool edit_enabled = false; + while(tim_run(0)){ + uint64_t c = 0x0f040f; + tim_frame(0, 0, ~0, ~0, c); + + tim_label(e.s, A, 2, A, A, c); + + if(edit_enabled){ + TimKey key = tim_edit(&e, A, 5, tim->scopes[tim->scope].w - 4, c); + + if(key == TimKey_Escape || key == TimKey_Enter) + edit_enabled = false; + } + else { + if(tim_button("[Enter] Edit text", A, 5, tim->scopes[tim->scope].w - 4, A, c) || tim_is_key_press(TimKey_Enter)){ + edit_enabled = true; + tim->focus = &e; + tim->event.type = TimEvent_Void; // consume key event + } + } + + if(tim_button("[Q] Quit", A, ~1, 10, A, c) || tim_is_key_press('q')) + break; + } + term_clear(); printf(FMT_str"\n", greeting_art.len, greeting_art.data);