From f9671485f8049fbc6909cc757eae851ac1b5e3b9 Mon Sep 17 00:00:00 2001
From: salad <fmoenne-@student.le-101.fr>
Date: Fri, 11 Sep 2020 14:29:48 +0200
Subject: home works, not END. lets go for a bit of norming

---
 src/b_exit.c  |  1 +
 src/c_init.c  | 10 +++++++++-
 src/c_init.h  |  2 ++
 src/c_input.c | 32 ++++++++++++++++++++++++++++++++
 src/c_input.h |  2 ++
 src/c_utils.c |  8 ++++++++
 6 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/b_exit.c b/src/b_exit.c
index cb8988f..0877d0c 100644
--- a/src/b_exit.c
+++ b/src/b_exit.c
@@ -37,6 +37,7 @@ uint8_t
 	{
 		ret = ft_atoi(args[0]);
 		 /* TODO: non numeric args[0] */
+		 /* TODO: return term to normal state (c_set_term_raw(0))*/
 	}
 	else
 		ret = msh->ret;
diff --git a/src/c_init.c b/src/c_init.c
index 8974007..3829a78 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -119,10 +119,18 @@ int16_t
 		{
 			return (c_key_right(ft_strlen(line), tcaps));
 		}
-		else if (strncmp(buf, tcaps->CL, ft_strlen(tgetstr("kb", NULL))) == 0)
+		else if (strncmp(buf, tcaps->CL, 4) == 0)
 		{
 			return (c_ctrl_l(line, tcaps, msh));
 		}
+		else if (strncmp(buf, tcaps->HM, 4) == 0)
+		{
+			return (c_home_key(tcaps));
+		}
+		else if (strncmp(buf, tcaps->ND, 4) == 0)
+		{
+			return (c_end_key(ft_strlen(line), tcaps));
+		}
 		else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
 		{
 			return (c_back_slash(&line, tcaps));
diff --git a/src/c_init.h b/src/c_init.h
index 9728c9a..af3756c 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -23,6 +23,8 @@ typedef struct s_caps
     char  KL[4];
     char  KR[4];
     char  CL[4];
+    char  HM[4];
+    char  ND[4];
     struct termios tios;
     struct winsize ws;
     uint8_t cpos;  /*cursor position (column)*/
diff --git a/src/c_input.c b/src/c_input.c
index f92a784..2435e4a 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -59,10 +59,42 @@ int16_t
 			 t_msh *msh)
 {
 	tputs(tgetstr("cl", NULL), 1, ft_putchar);
+	m_prompt_psx(1, msh);
 	c_redraw_line(line, tcaps->cpos, msh);
 	return (1);
 }
 
+int16_t
+	c_home_key(t_caps *tcaps)
+{
+	uint16_t i;
+
+	i = tcaps->cpos;
+	while (i > 0)
+	{
+		tputs(tgetstr("le", NULL), 1, ft_putchar);
+		i--;
+	}
+	tcaps->cpos = 0;
+	return (1);
+}
+
+int16_t
+	c_end_key(uint16_t size, t_caps *tcaps)
+{
+	uint16_t i;
+
+	i = tcaps->cpos;
+	while (i < size)
+	{
+		tputs(tgetstr("nd", NULL), 1, ft_putchar);
+		i++;
+	}
+	tcaps->cpos = size;
+	return (1);
+}
+
+
 int16_t
 	c_key_right(uint32_t len,
 			t_caps *tcaps)
diff --git a/src/c_input.h b/src/c_input.h
index d008436..be26a79 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -18,5 +18,7 @@ int16_t c_key_left(uint32_t len, t_caps *tcaps);
 int16_t c_new_line(char *buf, char **line, t_msh *msh, t_caps *tcaps);
 int16_t c_back_slash(char **line, t_caps *tcaps);
 int16_t c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
+int16_t c_home_key(t_caps *tcaps);
+int16_t c_end_key(uint16_t size, t_caps *tcaps);
 
 #endif
diff --git a/src/c_utils.c b/src/c_utils.c
index 09fda4f..2b2f8e4 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -47,6 +47,14 @@ int16_t
 		tcaps->CL[1] = 0;
 		tcaps->CL[2] = 0;
 		tcaps->CL[3] = 0;
+		tcaps->HM[0] = 27;
+		tcaps->HM[1] = 91;
+		tcaps->HM[2] = 72;
+		tcaps->HM[3] = 0;
+		tcaps->ND[0] = 27;
+		tcaps->ND[1] = 91;
+		tcaps->ND[2] = 70;
+		tcaps->ND[3] = 0;
 		return (1);
 	}
 	else
-- 
cgit v1.2.3