summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-11 11:54:03 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-11 11:54:03 +0200
commit1692db53ad552b34db7f321e603c32ca7453b253 (patch)
treee214bc4fc9223e9287c726a32a8897940185dfbc
parentLITERALLY C89 (diff)
download42-minishell-1692db53ad552b34db7f321e603c32ca7453b253.tar.gz
42-minishell-1692db53ad552b34db7f321e603c32ca7453b253.tar.bz2
42-minishell-1692db53ad552b34db7f321e603c32ca7453b253.tar.xz
42-minishell-1692db53ad552b34db7f321e603c32ca7453b253.tar.zst
42-minishell-1692db53ad552b34db7f321e603c32ca7453b253.zip
might finish today, ctrl + a few bugs
-rw-r--r--Perruches-x1kgx6.m4abin0 -> 1527477 bytes
-rw-r--r--Perruches-x1kgx6.mp4bin0 -> 7984006 bytes
-rw-r--r--src/c_init.c19
-rw-r--r--src/c_init.h7
-rw-r--r--src/c_input.c10
-rw-r--r--src/c_input.h1
-rw-r--r--src/c_utils.c40
-rw-r--r--src/c_utils.h1
8 files changed, 59 insertions, 19 deletions
diff --git a/Perruches-x1kgx6.m4a b/Perruches-x1kgx6.m4a
new file mode 100644
index 0000000..f388bf3
--- /dev/null
+++ b/Perruches-x1kgx6.m4a
Binary files differ
diff --git a/Perruches-x1kgx6.mp4 b/Perruches-x1kgx6.mp4
new file mode 100644
index 0000000..b1d1b4f
--- /dev/null
+++ b/Perruches-x1kgx6.mp4
Binary files differ
diff --git a/src/c_init.c b/src/c_init.c
index 18482c1..8974007 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -9,8 +9,6 @@
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
-# define FT_KEY_LEFT (char[4]){ 27, 91, 68, 0 }
-# define FT_KEY_RIGHT (char[4]){ 27, 91, 67, 0 }
#include <unistd.h>
@@ -113,24 +111,26 @@ int16_t
}
else
{
- /* if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0) */
- /* if ((*((unsigned int*)buf)) == FT_KEY_RIGHT) */
- if (strncmp(buf, FT_KEY_LEFT, 4) == 0)
+ if (strncmp(buf, tcaps->KL, 4) == 0)
{
return (c_key_left(ft_strlen(line), tcaps));
}
- else if (buf[0] == '\n')
+ else if (strncmp(buf, tcaps->KR, 4) == 0)
{
- return (c_new_line(buf, &line, msh, tcaps));
+ return (c_key_right(ft_strlen(line), tcaps));
}
- else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0)
+ else if (strncmp(buf, tcaps->CL, ft_strlen(tgetstr("kb", NULL))) == 0)
{
- return (c_key_left(ft_strlen(line), tcaps));
+ return (c_ctrl_l(line, tcaps, msh));
}
else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
{
return (c_back_slash(&line, tcaps));
}
+ else if (buf[0] == '\n')
+ {
+ return (c_new_line(buf, &line, msh, tcaps));
+ }
}
return (0);
}
@@ -151,6 +151,7 @@ int16_t
tcaps.cpos = 0;
c_set_term_raw(1);
c_get_struct(1, &tcaps);
+ c_init_keys(&tcaps);
m_prompt_psx(1, msh);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
diff --git a/src/c_init.h b/src/c_init.h
index 1d298c4..9728c9a 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -18,7 +18,11 @@
#include "s_struct.h"
-typedef struct s_caps {
+typedef struct s_caps
+{
+ char KL[4];
+ char KR[4];
+ char CL[4];
struct termios tios;
struct winsize ws;
uint8_t cpos; /*cursor position (column)*/
@@ -26,7 +30,6 @@ typedef struct s_caps {
char *nl; /*newline, returned by tgoto()*/
char *ks; /*indicate that keys transmit from now on*/
char *ke; /*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*/
diff --git a/src/c_input.c b/src/c_input.c
index fa61c6a..f92a784 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -54,6 +54,16 @@ int16_t
}
int16_t
+ c_ctrl_l(char *line,
+ t_caps *tcaps,
+ t_msh *msh)
+{
+ tputs(tgetstr("cl", NULL), 1, ft_putchar);
+ c_redraw_line(line, tcaps->cpos, msh);
+ 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 f6fa54d..d008436 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -17,5 +17,6 @@ int16_t c_key_right(uint32_t len, t_caps *tcaps);
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);
#endif
diff --git a/src/c_utils.c b/src/c_utils.c
index 8433d40..09fda4f 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -24,15 +24,35 @@
/*
** TODO:
-** cursor on char insert
+** term(0) on exit
+** cursor on char insert DONE
** quotes
-** MAKE IT WORK ON XTERM FFS (arrows + reset term)
** leaks
-** cleanup DONE
-** prompt on beginning DONE
-** c_set_term(0) on command DONE
*/
+int16_t
+ c_init_keys(t_caps *tcaps)
+{
+ if (tcaps)
+ {
+ tcaps->KL[0] = 27;
+ tcaps->KL[1] = 91;
+ tcaps->KL[2] = 68;
+ tcaps->KL[3] = 0;
+ tcaps->KR[0] = 27;
+ tcaps->KR[1] = 91;
+ tcaps->KR[2] = 67;
+ tcaps->KR[3] = 0;
+ tcaps->CL[0] = 12;
+ tcaps->CL[1] = 0;
+ tcaps->CL[2] = 0;
+ tcaps->CL[3] = 0;
+ return (1);
+ }
+ else
+ return (-1);
+}
+
uint16_t
c_get_win_size(struct winsize *ws)
{
@@ -58,7 +78,7 @@ char
i = 0;
j = 0;
- len = ft_strlen(str) + 2;
+ len = (ft_strlen(str) + 2);
if (!(dst = (char*)malloc((len) * sizeof(char))))
return (NULL);
while (i < len)
@@ -72,8 +92,7 @@ char
j++;
}
}
- tcaps->cpos++;
- dst[len] = '\0';
+ dst[i] = '\0';
ft_memdel((void*)&str);
return (dst);
}
@@ -110,6 +129,7 @@ int16_t
t_msh *msh)
{
uint32_t i;
+ uint32_t len;
int16_t ret;
i = 0;
@@ -121,5 +141,9 @@ int16_t
i++;
}
ret = ft_printf("%s", line) + ft_strlen(msh->ps[0]);
+ len = ft_strlen(line);
+ if (cpos != len)
+ while (--len > cpos)
+ tputs(tgetstr("le", NULL), 1, ft_putchar);
return (ret);
}
diff --git a/src/c_utils.h b/src/c_utils.h
index add7d34..fc9a700 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -20,5 +20,6 @@ char *c_delchar(char *str, uint16_t cpos);
uint16_t c_get_win_size(struct winsize *ws);
int32_t c_catch_tcaps(char *buf, char **line, t_caps *tcaps, t_msh *msh);
char *c_insert_char(char *str, char c, t_caps *tcaps);
+int16_t c_init_keys(t_caps *tcaps);
#endif