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,8 +3,10 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "ansi.h"
#include "term.h" #include "term.h"
#include "termio.h" #include "termio.h"
#include "pgetppid.h"
int main(void) { int main(void) {
struct ct_term *term; struct ct_term *term;
@ -12,34 +14,44 @@ int main(void) {
if (ct_stashterm(&term)) { if (ct_stashterm(&term)) {
perror("saveterm"); perror("saveterm");
exit(ERR); return ERR;
} }
if (ct_termsize(term)) { if (ct_termsize(term)) {
perror("termsize"); perror("termsize");
retv = ERR; goto fail;
goto end;
} }
if (termmode_raw(term)) { if (termmode_raw(term)) {
perror("termmode_raw"); perror("termmode_raw");
retv = ERR; goto fail;
goto end; }
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;
} }
printf("%d - %d (%d)\n", term->rows, term->cols, term->fd); 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);
}
// 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: end:
printf(ANSI_REGBUF);
ct_resetterm(term); ct_resetterm(term);
return retv; return retv;
fail:
retv = ERR;
goto end;
} }