summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_init.c9
-rw-r--r--src/c_utils.c31
-rw-r--r--src/c_utils.h1
3 files changed, 40 insertions, 1 deletions
diff --git a/src/c_init.c b/src/c_init.c
index ad18d92..effcc7d 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -21,6 +21,7 @@
#include "c_input.h"
#include "c_utils.h"
#include "s_struct.h"
+#include "m_prompt.h"
static char
*ft_strjoin_m(char *s1,
@@ -84,6 +85,8 @@ int16_t
return (1);
}
+/* c_insert_char */
+
int16_t
c_process_key(char *buf,
t_caps *tcaps,
@@ -98,7 +101,10 @@ int16_t
return (0);
if (ft_isprint(buf[0]))
{
- line = ft_strjoin_m(line, buf);
+ if (tcaps->cpos == ft_strlen(line))
+ line = ft_strjoin_m(line, buf);
+ else
+ line = c_insert_char(line, buf[0], tcaps);
c_redraw_line(line, tcaps->cpos, msh);
tcaps->cpos++;
}
@@ -140,6 +146,7 @@ int16_t
tcaps.cpos = 0;
c_set_term_raw(1);
c_get_struct(1, &tcaps);
+ m_prompt_psx(1, msh);
if (!(c_get_win_size(&tcaps.ws)))
return (-1);
while (1)
diff --git a/src/c_utils.c b/src/c_utils.c
index 3eb7f4d..6621a1a 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -45,6 +45,37 @@ uint16_t
}
char
+*c_insert_char(char *str,
+ char c,
+ t_caps *tcaps)
+{
+ size_t i;
+ size_t j;
+ size_t len;
+ char *dst;
+
+ i = 0;
+ j = 0;
+ len = ft_strlen(str) + 2;
+ if (!(dst = (char*)malloc((len) * sizeof(char))))
+ return (NULL);
+ while (i < len)
+ {
+ if (i == tcaps->cpos)
+ dst[i++] = c;
+ else
+ {
+ dst[i] = str[j];
+ i++;
+ j++;
+ }
+ }
+ dst[len] = '\0';
+ ft_memdel((void*)&str);
+ return (dst);
+}
+
+char
*c_delchar(char *str,
uint16_t cpos)
{
diff --git a/src/c_utils.h b/src/c_utils.h
index 967939f..add7d34 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -19,5 +19,6 @@ int16_t c_redraw_line(char *line, uint16_t cpos, t_msh *msh);
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);
#endif