summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-08-28 15:26:28 +0200
committersalad <fmoenne-@student.le-101.fr>2020-08-28 15:26:28 +0200
commitd128cc2c7ba227590155468712052cd416d4e831 (patch)
treec1b24e0b6149ca5ccedd2ad5924c52570e0f737f
parentadded init, samarche pas, peutetre go GNL (diff)
download42-minishell-d128cc2c7ba227590155468712052cd416d4e831.tar.gz
42-minishell-d128cc2c7ba227590155468712052cd416d4e831.tar.bz2
42-minishell-d128cc2c7ba227590155468712052cd416d4e831.tar.xz
42-minishell-d128cc2c7ba227590155468712052cd416d4e831.tar.zst
42-minishell-d128cc2c7ba227590155468712052cd416d4e831.zip
pourquoi seul nd foncitonne ?????????????????????????
-rw-r--r--src/c_init.c39
-rw-r--r--src/c_init.h2
2 files changed, 39 insertions, 2 deletions
diff --git a/src/c_init.c b/src/c_init.c
index bbf8f22..0c77224 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -32,6 +32,38 @@ t_caps
return (caps);
}
+void c_process_key(t_caps *tcaps) {
+ char nread[64] = {0};
+ int bread;
+
+ while ((bread = read(STDIN_FILENO, nread, sizeof(nread)) != 1)) {
+ if (bread == -1)
+ {
+ printf("error on read");
+ return ;
+ }
+ }
+ /* printf("read : [%s] size : [%lu]\n", nread, strlen(nread)); */
+ /* printf("cap : [%s] size : [%lu]\n", tcaps->kl, strlen(tcaps->kl)); */
+
+ if (*nread == 'q')
+ exit(0);
+ else if (strncmp(nread, "l", 1) == 0)
+ {
+ tputs(tgoto(tcaps->nd, 1, 1), 1, putchar);
+ /* write(1, tcaps->nd, strlen(tcaps->nd)); */
+ }
+ else if (strncmp(nread, tcaps->cl, strlen(tcaps->cl)) == 0)
+ write(1, tcaps->cl, strlen(tcaps->cl));
+ else if (strncmp(nread, "k", 1) == 0)
+ {
+ write(1, tcaps->bc, strlen(tcaps->nd));
+ /* tputs(tgoto(tcaps->bc, 1, 1), 1, putchar); */
+ }
+ else
+ write(1, nread, 1);
+}
+
int16_t c_init_tcaps(void)
{
t_caps tcaps;
@@ -42,7 +74,8 @@ int16_t c_init_tcaps(void)
term = getenv("TERM");
if (!tgetent(bp, term))
return (-1);
- tcaps.lc = tgetstr("lc", &term);
+ tcaps.cl = tgetstr("cl", &term);
+ tcaps.ks = tgetstr("ks", &term);
tcaps.kl = tgetstr("kl", &term);
tcaps.kr = tgetstr("kr", &term);
tcaps.pc = tgetstr("pc", &term);
@@ -56,5 +89,9 @@ int16_t c_init_tcaps(void)
tcaps.tios.c_cc[VTIME] = 1;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &tcaps.tios);
c_get_struct(1, &tcaps);
+ while (1)
+ {
+ c_process_key(&tcaps);
+ }
return (1);
}
diff --git a/src/c_init.h b/src/c_init.h
index 69d626a..8cf43ec 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -26,7 +26,7 @@ typedef struct s_caps {
char *bc; /*left one char*/
char *up; /*up one line*/
char *nd; /*right one char*/
- char *lc; /*line clear*/
+ char *cl; /*line clear*/
} t_caps;