From 9ca75e7eb366800b3c602fb948167bcb185bed37 Mon Sep 17 00:00:00 2001
From: salad <fmoenne-@student.le-101.fr>
Date: Thu, 27 Aug 2020 23:29:07 +0200
Subject: added init, samarche pas, peutetre go GNL

---
 src/c_init.c | 42 +++++++++++++++++++++++++++++++++++-------
 src/c_init.h | 20 ++++++++++++++++++--
 src/m_loop.c |  1 -
 3 files changed, 53 insertions(+), 10 deletions(-)

(limited to 'src')

diff --git a/src/c_init.c b/src/c_init.c
index 5cf46f3..bbf8f22 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -10,23 +10,51 @@
 /*                                                                            */
 /* ************************************************************************** */
 
+#include <unistd.h>
+#include <stdio.h>
+#include <termios.h>
+#include <stdlib.h>
+#include <string.h>
 #include <term.h>
 #include <curses.h>
 
-void u_handle_sigwinch(int dummy_signal)
+#include "c_init.h"
+
+t_caps
+    *c_get_struct(int mode, t_caps *src)
 {
-	(void)dummy_signal;
-	tputs(LC, 1, ft_putchar);
-	fflush(stdout);
+    static t_caps *caps;
+
+    if (mode == 1)
+    {
+        caps = src;
+    }
+    return (caps);
 }
 
 int16_t c_init_tcaps(void)
 {
+    t_caps tcaps;
     char *bp;
     char *term;
-    char *LC;
 
+    bp = NULL;
     term = getenv("TERM");
-    tgetent(bp, term);
-    LC = tgetstr("lc", &term);
+    if (!tgetent(bp, term))
+        return (-1);
+    tcaps.lc = tgetstr("lc", &term);
+    tcaps.kl = tgetstr("kl", &term);
+    tcaps.kr = tgetstr("kr", &term);
+    tcaps.pc = tgetstr("pc", &term);
+    tcaps.bc = tgetstr("bc", &term);
+    tcaps.up = tgetstr("up", &term);
+    tcaps.nd = tgetstr("nd", &term);
+    tcgetattr(STDIN_FILENO, &tcaps.tios);
+
+    tcaps.tios.c_lflag &= ~(ECHO | ICANON);
+    tcaps.tios.c_cc[VMIN] = 0;
+    tcaps.tios.c_cc[VTIME] = 1;
+    tcsetattr(STDIN_FILENO, TCSAFLUSH, &tcaps.tios);
+    c_get_struct(1, &tcaps);
+    return (1);
 }
diff --git a/src/c_init.h b/src/c_init.h
index da3d549..69d626a 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -13,7 +13,23 @@
 #ifndef U_INIT_H
 #define U_INIT_H
 
-int c_init_tcaps(void);
-void u_handle_sigwinch(int dummy_signal);
+#include <termios.h>
+
+typedef struct s_caps {
+    struct termios tios;
+    char  *cm_str; /*cursor mobility*/
+    char  *nl;     /*newline, returned by tgoto()*/
+    char  *ks;     /*indicate that keys transmit from now on*/
+    char  *kl;     /*Key Left Key Right*/
+    char  *kr;
+    char  *pc;     /*padding char --> do not touch (default 0)*/
+    char  *bc;     /*left  one char*/
+    char  *up;     /*up one line*/
+    char  *nd;     /*right one char*/
+    char  *lc;     /*line clear*/
+
+} t_caps;
+
+int16_t c_init_tcaps(void);
 
 #endif
diff --git a/src/m_loop.c b/src/m_loop.c
index ed92fd5..75b8e3e 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -39,7 +39,6 @@ uint8_t
 	int8_t	gnl;
 
 	c_init_tcaps();
-	signal(SIGWINCH, u_handle_sigwinch);
 	gnl = 1;
 	while (gnl > 0)
 	{
-- 
cgit v1.2.3