progress ct_test.c with ANSI seqs & recursive pgetppid

This commit is contained in:
Emile Clark-Boman 2025-09-28 22:37:50 +10:00
parent 25f1180429
commit c9645b1f19

View file

@ -3,43 +3,55 @@
#include <string.h>
#include <unistd.h>
#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;
}