From e99716457e6191fe31381ac4a314529ec412e1ab Mon Sep 17 00:00:00 2001 From: justuser-31 Date: Fri, 14 Feb 2025 21:11:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo.sh | 4 ++-- rtracker | Bin 19056 -> 19056 bytes rtracker.c | 24 +++++++++++++++--------- test | 0 4 files changed, 17 insertions(+), 11 deletions(-) delete mode 100644 test diff --git a/demo.sh b/demo.sh index 3b8398c..a154e03 100755 --- a/demo.sh +++ b/demo.sh @@ -4,8 +4,8 @@ shopt -s expand_aliases alias rt="./rtracker" rt Testing sleep... \ - % sleep 3 + %% sleep 3 rt Hello world? \ %o echo Hello world rt Producing some error \ - % rm not_exist + %% rm not_exist diff --git a/rtracker b/rtracker index 002bcbd6742cdd82d01f55c82f200f5f1d971cfc..156a024f5f5250181b7ae2fca9019f6b025378a6 100755 GIT binary patch delta 782 zcmew`h4I4_#tj^doJH&mU{JJKka0T;WB%rotQ)w6KCv<|xEh}H=;f{a_y4~~ukESL z-Gcv_vJyOcL%(=*yZ-QCyuiPWfq<pI%m39R>!EUeSJTAk}%X^N>d`YZsV(49MyL zvySfoS@I(JH_)(dRvt}|%HuDd0J-}Yv@tTg=mJSJyZ&JGXs-RiTsHG{@8ky}#;RMx zfC?EecyxkHl0`P@^{@Z`n_d4fcC#8zwh)cr*}w%d@*2og-^p`C^>``~0>YE8iRvmX z)q+^M7pN0x+B7KlABYQfbIW8^F)gJ?J&3YGh%zrIcN1Kh#pFUUrTXK4LE6Cf?FPBM zmz5c+((2Fu|1Aef0)V0P0puKZARj3G1nlR7Kvpm($Ocd-<$+lszvX~g&`{F+`Tu`I z?LUT+Xh^8t1={u6A7ED?prACb2+{hv{7=AVDj?VZ delta 726 zcmew`h4I4_#tj^doM!9{U|_acka0T;qw(gGtQ)w6wy`oWxEh}H=;f{a_y4~~ukE(Y z-Gcv_!hAe>L%(=*yZ-QCyuiPWfq<k6uw(9R`NZV;;S%z1$289-YT`fDC+5{u`*V zn^i#*EcW6Dkh_0D8zaMuc_4{q*B^`?&9y(6%htYLIQff+vFgb%phCtA9$=HSkxlyl z>;L~|*FTKitge%NL?d|iae<7y2DIr#;^YmYdOYn20rknRM0J&RYC$Z$2-FF5*D5Gi z2xN2TA)v^N$(CYTO1XLvWvvipaZv6t5Erb>XL75UQvL0}AU@c>^B@y?S;e6${r>#_ z-*TYD1{fkAK+cf{@`2JnzKW-l+U2b z0F^b${V;#}4um`xOu{ht!-SS5WC@UElY14OOXh)Cj(h@bOwPP)K&A{3{{Z5U$-Rp5 zA~Qb!|Nov5Nd@yO#?1#56L^3rNKucUnbCN%p`ksa$>u`C3J~X&Ni2}#VS1Md$WgOU zU^JOrXed8fkCkn6j)e^imy0OSEFgH#IC+ze9Z=0j8*|3I$(pwF86RvuY1_`m^q6&W ekc%F#u{cB_n4bL6Q+V #include #include +#include #include "c_cross_pack/libs/threads.h" +#define CL_RED "\033[1;31m" +#define CL_YELLOW "\033[1;33m" +#define CL_GREEN "\033[1;32m" +#define CL_NORMAL "\033[1;0m" + char comment[1000] = ""; char command[10000] = ""; -// Out of command execution +// Output of command execution char out[1000][100]; int out_i = 0; @@ -18,18 +24,18 @@ bool runCommand(char* command) { char path[1024]; int status; - // Combine stdout and stderr using 2>&1 + // Catch stdout and stderr char fullCommand[1024]; snprintf(fullCommand, sizeof(fullCommand), "%s 2>&1", command); - /* Open the command for reading. */ + // Open the command for reading fp = popen(fullCommand, "r"); if (fp == NULL) { printf("Failed to run command\n"); return false; } - /* Read the output a line at a time and store it in the out array */ + // Read the output a line at a time and store it in the out array while (fgets(path, sizeof(path), fp) != NULL) { strncpy(out[out_i], path, 100); out[out_i][99] = '\0'; // Ensure null termination @@ -59,7 +65,7 @@ void* loadAnim() { char anim[] = {'-', '\\', '|', '/'}; while (true) { for (size_t i = 0; i < sizeof(anim)/sizeof(anim[0]); i++) { - printf("\r[\033[1;33m%c\033[1;0m] %s", anim[i], comment); + printf("\r[%s%c%s] %s", CL_YELLOW, anim[i], CL_NORMAL, comment); fflush(stdout); usleep(100 * 1000); // 100 ms } @@ -73,14 +79,14 @@ void getOut() { } int main(int argc, char **argv) { - bool isCommand = false; + bool isCommand = false; // Flag for detect command section bool forceOut = false; for(int i = 1; i < argc; i++) { if (isCommand == false) { if (strcmp(argv[i], "%o") == 0) { isCommand = true; forceOut = true; - } else if (strcmp(argv[i], "%") == 0) { + } else if (strcmp(argv[i], "%%") == 0) { isCommand = true; } else { strcat(comment, argv[i]); @@ -96,13 +102,13 @@ int main(int argc, char **argv) { start_thread(&thread_handle, loadAnim); if (runCommand(command)) { kill_thread(thread_handle); - printf("\r[\033[1;32m🗸\033[1;0m] %s\n", comment); + printf("\r[%s🗸%s] %s\n", CL_GREEN, CL_NORMAL, comment); if (forceOut == true) { getOut(); } } else { kill_thread(thread_handle); - printf("\r[\033[1;31m𐄂\033[1;0m] %s\n", comment); + printf("\r[%s𐄂%s] %s\n", CL_RED, CL_NORMAL, comment); // Get out of failed command getOut(); return 1; diff --git a/test b/test deleted file mode 100644 index e69de29..0000000