history_tools.c 676 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "sh.h"
  2. void go_to_young_hist(t_e *e)
  3. {
  4. while (e->hist != NULL && e->hist->yng != NULL)
  5. e->hist = e->hist->yng;
  6. }
  7. /*
  8. ** DEBUG
  9. ** Display all stored history
  10. */
  11. void display_all_hist(t_e *e)
  12. {
  13. go_to_young_hist(e);
  14. while (e->hist != NULL && e->hist->old != NULL)
  15. {
  16. ft_printf("|%s|\n", e->hist->cmd);
  17. e->hist = e->hist->old;
  18. }
  19. }
  20. void display_history(t_e *e, int side)
  21. {
  22. if (side == DOWN && e->first == 1)
  23. {
  24. print_history("");
  25. e->cmd = ft_strnew(0);
  26. }
  27. else
  28. print_history(e->hist->cmd);
  29. }
  30. /*
  31. ** Hide current line, display prompt and cmd
  32. */
  33. void print_history(char *cmd)
  34. {
  35. term_action("dl");
  36. term_action("cr");
  37. ft_printf("%s%s", PROMPT, cmd);
  38. }