summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-09-18 14:51:08 +0200
committersalad <fmoenne-@student.le-101.fr>2020-09-18 14:51:08 +0200
commit3ab54c00fd08f02f246488629442866c8eb604b1 (patch)
treeab4bca754ad2220ef2f704d6dc9f721606dc9b33
parentnorm, new file, ctrl + c (diff)
download42-minishell-3ab54c00fd08f02f246488629442866c8eb604b1.tar.gz
42-minishell-3ab54c00fd08f02f246488629442866c8eb604b1.tar.bz2
42-minishell-3ab54c00fd08f02f246488629442866c8eb604b1.tar.xz
42-minishell-3ab54c00fd08f02f246488629442866c8eb604b1.tar.zst
42-minishell-3ab54c00fd08f02f246488629442866c8eb604b1.zip
full bugged, mais full features
Diffstat (limited to '')
-rw-r--r--src/c_init.c12
-rw-r--r--src/c_init.h2
-rw-r--r--src/c_keys.c20
-rw-r--r--src/c_keys.h4
-rw-r--r--src/c_utils.c8
5 files changed, 35 insertions, 11 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 8870b27..a196708 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <term.h>
#include <libft.h>
+#include <signal.h>
#include "c_init.h"
#include "c_input.h"
@@ -82,9 +83,9 @@ int16_t
else
{
if (ft_strncmp(buf, tcaps->KL, 4) == 0)
- return (c_key_left(ft_strlen(line), tcaps));
+ return (c_key_left(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
else if (ft_strncmp(buf, tcaps->KR, 4) == 0)
- return (c_key_right(ft_strlen(line), tcaps));
+ return (c_key_right(ft_strlen(line), ft_strlen(msh->ps[0]), tcaps));
else if (ft_strncmp(buf, tcaps->HM, 4) == 0)
return (c_home_key(tcaps));
else if (ft_strncmp(buf, tcaps->ND, 4) == 0)
@@ -94,7 +95,11 @@ int16_t
else if (ft_strncmp(buf, tcaps->CL, 4) == 0)
return (c_ctrl_l(line, tcaps, msh));
else if (ft_strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
- return (c_back_slash(&line, tcaps));
+ {
+ c_back_slash(&line, tcaps);
+ c_redraw_line(line, tcaps, msh);
+ return (1);
+ }
else if (buf[0] == '\n')
{
c_new_line(ft_strdup(line), msh, tcaps);
@@ -123,6 +128,7 @@ int16_t
c_get_struct(1, &tcaps);
c_init_keys(&tcaps);
m_prompt_psx(1, msh);
+ signal(SIGINT, SIG_IGN);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
while (1)
diff --git a/src/c_init.h b/src/c_init.h
index 2f93a00..798abb1 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -28,7 +28,7 @@ typedef struct s_caps
char ND[4];
struct termios tios;
struct winsize ws;
- uint8_t cpos; /*cursor position (column)*/
+ uint32_t cpos; /*cursor position (column)*/
char *cm_str; /*cursor mobility*/
char *nl; /*newline, returned by tgoto()*/
char *ks; /*indicate that keys transmit from now on*/
diff --git a/src/c_keys.c b/src/c_keys.c
index d388d60..7874932 100644
--- a/src/c_keys.c
+++ b/src/c_keys.c
@@ -60,9 +60,16 @@ int16_t
int16_t
c_key_right(uint32_t len,
+ uint32_t plen,
t_caps *tcaps)
{
- if (tcaps->cpos < len)
+ if (((tcaps->cpos + 1) % (tcaps->ws.ws_col - plen)) == 0 && tcaps->cpos < len)
+ {
+ tputs(tgetstr("do", NULL), 1, ft_putchar);
+ tputs(tgetstr("cr", NULL), 1, ft_putchar);
+ tcaps->cpos++;
+ }
+ else if (tcaps->cpos < len)
{
tputs(tgetstr("nd", NULL), 1, ft_putchar);
tcaps->cpos++;
@@ -72,9 +79,20 @@ int16_t
int16_t
c_key_left(uint32_t len,
+ uint32_t plen,
t_caps *tcaps)
{
+ int32_t pos;
(void)len;
+
+ pos = -1;
+ if (((tcaps->cpos) % (tcaps->ws.ws_col - plen)) == 0 && tcaps->cpos >= 1)
+ {
+ tputs(tgetstr("up", NULL), 1, ft_putchar);
+ while(++pos <= (tcaps->ws.ws_col))
+ tputs(tgetstr("nd", NULL), 1, ft_putchar);
+ tcaps->cpos--;
+ }
if (tcaps->cpos >= 1)
{
tputs(tgetstr("le", NULL), 1, ft_putchar);
diff --git a/src/c_keys.h b/src/c_keys.h
index e492499..d261824 100644
--- a/src/c_keys.h
+++ b/src/c_keys.h
@@ -13,8 +13,8 @@
#ifndef C_KEYS_H
#define C_KEYS_H
-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_key_right(uint32_t len, uint32_t plen, t_caps *tcaps);
+int16_t c_key_left(uint32_t len, uint32_t plen, t_caps *tcaps);
int16_t c_home_key(t_caps *tcaps);
int16_t c_end_key(uint16_t size, t_caps *tcaps);
int16_t c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh);
diff --git a/src/c_utils.c b/src/c_utils.c
index 1890192..f96d0b3 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include <term.h>
#include <unistd.h>
-#include <sys/ioctl.h>
#include "c_init.h"
#include "m_prompt.h"
@@ -25,10 +24,11 @@
/*
** TODO:
** MULTILIGHNE
+** FLECHES UP DOWN
** quotes
-** C-c
+** unknown chars
+** C-c globul pid
** NORME
-** leaks on line ??? GONE ?
*/
uint16_t
@@ -138,7 +138,7 @@ int16_t
tputs(tgetstr("cr", NULL), 1, ft_putchar);
if (len >= (tcaps->ws.ws_col - ft_strlen(msh->ps[0])))
{
- if (len == (tcaps->ws.ws_col - ft_strlen(msh->ps[0])))
+ if (len % (tcaps->ws.ws_col - ft_strlen(msh->ps[0])) == 0)
{
tputs(tgetstr("sf", NULL), 1, ft_putchar);
return (1);