summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
authorjoe <rbousset@42lyon.fr>2020-12-01 18:36:35 +0100
committerjoe <rbousset@42lyon.fr>2020-12-01 18:36:35 +0100
commit4f3d3364de8f1c23819051cb9f392fc651565b95 (patch)
treed7574f821dc02a27dcc5a0b8b63cf40e60dd023e /src/c_init.c
parentBav (diff)
download42-minishell-4f3d3364de8f1c23819051cb9f392fc651565b95.tar.gz
42-minishell-4f3d3364de8f1c23819051cb9f392fc651565b95.tar.bz2
42-minishell-4f3d3364de8f1c23819051cb9f392fc651565b95.tar.xz
42-minishell-4f3d3364de8f1c23819051cb9f392fc651565b95.tar.zst
42-minishell-4f3d3364de8f1c23819051cb9f392fc651565b95.zip
commit
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 965af3f..b463830 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -23,6 +23,7 @@
#include "c_keys_next.h"
#include "c_input.h"
#include "c_utils.h"
+#include "d_define.h"
#include "b_exit.h"
#include "s_struct.h"
#include "s_com.h"
@@ -105,11 +106,36 @@ static short
return (0);
}
+char *c_set_ptr(t_bool reset, char key, t_msh *msh)
+{
+ static char *p = NULL;
+
+ if (reset == TRUE)
+ {
+ p = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr);
+ return (NULL);
+ }
+ if ((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1)
+ {
+ p += (key == -1) ? (2 * key) : (0);
+ while (((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1) && *p != C_LF && *p != C_NUL)
+ {
+ p += key;
+ }
+ if (p - msh->curr_hist_ptr != 0 && *p != C_NUL)
+ {
+ p += 1;
+ }
+ }
+ return (p);
+}
+
static char
*c_process_key(char *buf, t_caps *tcaps, t_msh *msh)
{
static char *line = NULL;
int i;
+ char *ptr;
i = -1;
if (line == NULL)
@@ -120,7 +146,15 @@ static char
else if (((*((unsigned int *)buf)) == UP_K) ||
((*((unsigned int *)buf)) == CTRL_P))
{
- c_key_up(&line, tcaps, msh);
+ ptr = c_set_ptr(FALSE, -1, msh);
+ c_key_up_down(&line, tcaps, ptr);
+ c_redraw_line(line, tcaps, msh);
+ }
+ else if (((*((unsigned int *)buf)) == DOWN_K) ||
+ ((*((unsigned int *)buf)) == CTRL_N))
+ {
+ ptr = c_set_ptr(FALSE, 1, msh);
+ c_key_up_down(&line, tcaps, ptr);
c_redraw_line(line, tcaps, msh);
}
else if ((*((unsigned int *)buf)) == DEL_K)