Tracer des diagrammes dans un terminal - retour accueil
git clone git://bebou.netlib.re/boxes
Log | Files | Refs | README |
commit 3efa499d8608a59ee80bf9cd755c471f5f9276ca parent 6d70bb451a6f8b07d3075e4d833e5f9eb4d7692a Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Mon, 16 Jun 2025 22:50:46 +0200 Si stdin est un term on lit pas stdin C'est mieux comme ça, soit on pipe des coords echo "box 1 1 4 4" | boxes Soit direct on édite boxes Diffstat:
M | boxes.c | | | 43 | ++++++++++++++++++++++++------------------- |
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/boxes.c b/boxes.c @@ -83,37 +83,42 @@ int main(int argc, char **argv) { char line[1000]; char **toparse; - while (fgets(line, sizeof(line), stdin)) { - if(strlen(line)==1) continue; - toparse=realloc(toparse,(toparsecount+1)*sizeof(void*)); - toparse[toparsecount] = malloc(1000); - strcpy(toparse[toparsecount], line); - toparsecount++; - } - struct boxpile boxes; boxes.list=malloc(MAX_BOX_NB*sizeof(struct box)); boxes.count=0; struct arrowpile arrows; arrows.list=malloc(MAX_BOX_NB*sizeof(struct arrow)); arrows.count=0; - char *delimiter=" "; - char* token; - for (int i=0;i<toparsecount;i++) { - token = strtok(toparse[i], delimiter); - char *type=token; - int args[4]; int j=0; - while (token) { - token = strtok(NULL, delimiter); - if(token!=NULL) args[j++]=(int)strtol(token, NULL, 10); + if(!isatty(fileno(stdin))) { + while (fgets(line, sizeof(line), stdin)) { + if(strlen(line)==1) continue; + toparse=realloc(toparse,(toparsecount+1)*sizeof(void*)); + toparse[toparsecount] = malloc(1000); + strcpy(toparse[toparsecount], line); + toparsecount++; + } + + char *delimiter=" "; + char* token; + for (int i=0;i<toparsecount;i++) { + token = strtok(toparse[i], delimiter); + char *type=token; + int args[4]; int j=0; + while (token) { + token = strtok(NULL, delimiter); + if(token!=NULL) args[j++]=(int)strtol(token, NULL, 10); + } + if(strcmp(type,"arrow")==0) addarrow(&arrows,createarrow(args[0],args[1],args[2],args[3])); + else if (strcmp(type,"box")==0) addbox(&boxes,createbox(args[0],args[1],args[2],args[3])); } - if(strcmp(type,"arrow")==0) addarrow(&arrows,createarrow(args[0],args[1],args[2],args[3])); - else if (strcmp(type,"box")==0) addbox(&boxes,createbox(args[0],args[1],args[2],args[3])); } + tb_init(); tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); int mode=0; struct tb_event ev; int curx; int cury; + + while(1) { tb_clear(); for (int i=0;i<boxes.count;i++) drawbox(boxes.list[i]);