summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSalad <water_appreciator@protonmail.com>2020-10-21 18:23:04 +0200
committerSalad <water_appreciator@protonmail.com>2020-10-21 18:23:04 +0200
commita0c2a69d6c79e11c0eb25751d6c246bb164ebc31 (patch)
treec172bb09ebd52b262141aa4e5fabdbdf5e00e4f3
parentstuff (diff)
download42-minishell-a0c2a69d6c79e11c0eb25751d6c246bb164ebc31.tar.gz
42-minishell-a0c2a69d6c79e11c0eb25751d6c246bb164ebc31.tar.bz2
42-minishell-a0c2a69d6c79e11c0eb25751d6c246bb164ebc31.tar.xz
42-minishell-a0c2a69d6c79e11c0eb25751d6c246bb164ebc31.tar.zst
42-minishell-a0c2a69d6c79e11c0eb25751d6c246bb164ebc31.zip
makeshift
-rw-r--r--src/c_init.c22
-rw-r--r--src/c_init.h6
-rw-r--r--src/c_input.h9
-rw-r--r--src/c_keys.c4
-rw-r--r--src/c_utils.c2
-rw-r--r--src/c_utils.h2
6 files changed, 26 insertions, 19 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 1442fdb..844e4a6 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -61,18 +61,19 @@ int16_t
int16_t
c_read_cap(char *buf, char *line, t_caps *tcaps, t_msh *msh)
{
+ uint32_t plen;
+
+ plen = ft_strlen(msh->ps[tcaps->psx]);
if (((*((unsigned int *)buf)) == LEFT_K) ||
((*((unsigned int *)buf)) == CTRL_B))
- return (c_key_left(ft_strlen(msh->ps[tcaps->psx]), tcaps));
+ return (c_key_left(plen, tcaps));
else if (((*((unsigned int *)buf)) == RIGHT_K) ||
- ((*((unsigned int *)buf)) == CTRL_F))
- return (c_key_right(ft_strlen(line),
- ft_strlen(msh->ps[tcaps->psx]), tcaps));
+ ((*((unsigned int *)buf)) == CTRL_F))
+ return (c_key_right(ft_strlen(line), plen, tcaps));
else if ((*((unsigned int *)buf)) == HOME_K)
- return (c_key_left(ft_strlen(msh->ps[tcaps->psx]), c_home_key(tcaps));
+ return (c_home_key(plen, tcaps));
else if ((*((unsigned int *)buf)) == END_K)
- return (c_end_key(ft_strlen(line),
- ft_strlen(msh->ps[tcaps->psx]), tcaps));
+ return (c_end_key(ft_strlen(line), plen, tcaps));
else if ((*((unsigned int *)buf)) == CTRL_C)
return (c_ctrl_c(NULL, tcaps, msh));
else if ((*((unsigned int *)buf)) == CTRL_L)
@@ -98,7 +99,7 @@ static char
if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
tcaps->ws.ws_col) == 0)
{
- write(1, "\n", 1);
+ write(1, "\n\r", 2);
return (NULL);
}
c_redraw_line(line, tcaps, msh);
@@ -106,6 +107,11 @@ static char
else if ((*((unsigned int *)buf)) == DEL_K)
{
c_back_slash(&line, ft_strlen(msh->ps[tcaps->psx]), tcaps);
+ if ((((tcaps->cpos) + ft_strlen(msh->ps[tcaps->psx])) %
+ tcaps->ws.ws_col) == 0)
+ {
+ return (NULL);
+ }
c_redraw_line(line, tcaps, msh);
}
else
diff --git a/src/c_init.h b/src/c_init.h
index cb10864..9ffd1eb 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -37,10 +37,10 @@ typedef struct s_caps
uint32_t cpos;
uint32_t lpos;
uint32_t nlines;
- uint8_t psx;
+ uint8_t psx;
} t_caps;
-int16_t c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh);
-int16_t c_set_term_raw(uint8_t mode);
+int16_t c_gnl(int32_t fd, char **line, uint8_t psx, t_msh *msh);
+int16_t c_set_term_raw(uint8_t mode);
#endif
diff --git a/src/c_input.h b/src/c_input.h
index 541b712..f22166a 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -13,10 +13,11 @@
#ifndef C_INPUT_H
# define C_INPUT_H
-int16_t c_back_slash(char **line, uint32_t plen, t_caps *tcaps);
-int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
-uint32_ c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps);
-int16_t c_init_line(uint8_t psx, t_caps *tcaps);
+int16_t c_back_slash(char **line, uint32_t plen, t_caps *tcaps);
+int16_t c_ctrl_c(char *line, t_caps *tcaps, t_msh *msh);
+uint32_t c_get_line_num(char *line, uint32_t cpos, uint32_t plen,
+ t_caps *tcaps);
+int16_t c_init_line(uint8_t psx, t_caps *tcaps);
uint16_t c_get_win_size(struct winsize *ws);
#endif
diff --git a/src/c_keys.c b/src/c_keys.c
index 0c89391..e0f734c 100644
--- a/src/c_keys.c
+++ b/src/c_keys.c
@@ -40,10 +40,10 @@ int16_t
while (--j > 0)
tputs(tgetstr("up", NULL), 1, ft_putchar);
tputs(tgetstr("cr", NULL), 1, ft_putchar);
- while (++i <= 13)
+ while (++i <= plen)
tputs(tgetstr("nd", NULL), 1, ft_putchar);
}
- else
+ else if (i >= 1)
{
while (--i >= 0)
tputs(tgetstr("le", NULL), 1, ft_putchar);
diff --git a/src/c_utils.c b/src/c_utils.c
index de4e8d1..f879f34 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -150,7 +150,7 @@ int16_t
while (i++ < ft_strlen(msh->ps[tcaps->psx]))
tputs(tgetstr("nd", NULL), 1, ft_putchar);
ft_printf("%s", line);
- return (((tcaps->cpos) != ft_strlen(line)) ?
+ return ((tcaps->cpos != ft_strlen(line)) ?
c_redraw_next(ft_strlen(msh->ps[tcaps->psx]), ft_strlen(line), tcaps) :
ft_strlen(line));
}
diff --git a/src/c_utils.h b/src/c_utils.h
index 0cea972..730d29a 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -18,6 +18,6 @@
char *c_new_line(char *line, t_caps *tcaps);
char *c_insert_char(char *str, char c, t_caps *tcaps);
char *c_delchar(char *str, uint16_t cpos);
-int16_t c_redraw_line(char *line, t_caps *tcaps, t_msh *msh);
+int16_t c_redraw_line(char *line, t_caps *tcaps, t_msh *msh);
#endif