Browse Source

[mod] history: split on two functions move on history and display.

Moul 3 years ago
parent
commit
82d2ec60c9
3 changed files with 10 additions and 5 deletions
  1. 8 3
      src/history.c
  2. 0 1
      src/term.c
  3. 2 1
      src/term.h

+ 8 - 3
src/history.c

@@ -42,7 +42,8 @@ t_hist	*new_hist(char *cmd)
 
 void	move_history(t_e *e, int side)
 {
-	get_history(e, side);
+	move_on_history(e, side);
+	display_history(e, side);
 	if (side == UP || e->hist->yng != NULL)
 	{
 		if (ft_strcmp(e->cmd, e->hist->cmd) != 0)
@@ -58,7 +59,7 @@ void	move_history(t_e *e, int side)
 ** If yng or old exist, move pointer to it, then display it
 */
 
-void	get_history(t_e *e, int side)
+void	move_on_history(t_e *e, int side)
 {
 	if (e->hist == NULL)
 		return ;
@@ -71,11 +72,15 @@ void	get_history(t_e *e, int side)
 		e->hist = e->hist->yng;
 	else if (side == DOWN && e->hist->yng == NULL)
 		e->first = 1;
+}
+
+void	display_history(t_e *e, int side)
+{
 	if (side == DOWN && e->first == 1)
 	{
 		print_history("");
 		ft_strdel(&e->cmd);
-		e->cmd = ft_strdup("");
+		e->cmd = ft_strnew(0);
 	}
 	else
 		print_history(e->hist->cmd);

+ 0 - 1
src/term.c

@@ -60,7 +60,6 @@ void	prompt_get_cmd_keys(t_e *e)
 		e->cmd = ft_strnew(0);
 		e->plen = ft_strlen(PROMPT);
 		ft_putstr(PROMPT);
-		go_to_young_hist(e);
 		e->first = 1;
 		set_term_modes(0);
 		herething = read_std(e);

+ 2 - 1
src/term.h

@@ -47,7 +47,8 @@ void	begin(t_e *e);
 void	save_history(t_e *e, t_hist *new);
 t_hist	*new_hist(char *cmd);
 void	move_history(t_e *e, int side);
-void	get_history(t_e *e, int side);
+void	move_on_history(t_e *e, int side);
+void	display_history(t_e *e, int side);
 void	print_history(char *cmd);
 /*
 ** history_tools.c