From c9645b1f19d64bae04de71ea7686528320e27b18 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Sun, 28 Sep 2025 22:37:50 +1000 Subject: [PATCH] progress ct_test.c with ANSI seqs & recursive pgetppid --- src/ct_test.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/ct_test.c b/src/ct_test.c index 639928d..2cb65e7 100644 --- a/src/ct_test.c +++ b/src/ct_test.c @@ -3,43 +3,55 @@ #include #include +#include "ansi.h" #include "term.h" #include "termio.h" +#include "pgetppid.h" int main(void) { struct ct_term *term; int retv = OK; - + if (ct_stashterm(&term)) { perror("saveterm"); - exit(ERR); + return ERR; } if (ct_termsize(term)) { perror("termsize"); - retv = ERR; - goto end; + goto fail; } if (termmode_raw(term)) { perror("termmode_raw"); - retv = ERR; - goto end; + goto fail; + } + printf(ANSI_ALTBUF ANSI_HOME); + + pid_t pid = getpid(); + pid_t ppid; + char name[CT_PROC_NAME_MAX]; + while (pgetppid(pid, &ppid, name) != -1) { + printf("%s (%d)\r\n", name, ppid); + pid = ppid; + } + + int i; + for (i = 0; i < 10; i++) { + printf( "%d" ANSI_CMR "\n", i); + sleep(1); + } + for (; i-- >= 0;) { + printf("%d" ANSI_CMLN(2) "\n", i); + sleep(1); } - printf("%d - %d (%d)\n", term->rows, term->cols, term->fd); - - // char *line = (char *)malloc(sizeof(char) * (term->cols + 1)); - // memset(line, 'X', term->cols); - // line[term->cols] = '\0'; - - // for (int i=0; i < term->rows; i++) { - // printf("%s", line); - // } - // printf("\n"); - while (1) - sleep(3); end: + printf(ANSI_REGBUF); ct_resetterm(term); return retv; + +fail: + retv = ERR; + goto end; }