term_edition.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "sh.h"
  2. /*
  3. ** Increment position depending on number of added char
  4. ** Insert char everywhere in the cmd
  5. ** Go in insertion mode
  6. ** Get second and firt parts.
  7. ** If cursor at the end of cmd: snd = "" as it retrieve more.
  8. ** Join them with new char in the middle
  9. */
  10. void insert(t_e *e)
  11. {
  12. char *snd;
  13. e->pos += ft_strlen(e->key);
  14. term_action("im");
  15. snd = ft_strsub(e->cmd, e->pos - 1, e->len);
  16. if (e->pos == e->len + 1)
  17. {
  18. ft_strdel(&snd);
  19. snd = ft_strdup("");
  20. }
  21. e->cmd[e->pos - 1] = '\0';
  22. e->cmd = ft_strjoinf(ft_strjoinf(e->cmd, e->key, 1), snd, 3);
  23. if (e->col_nbr != 0)
  24. e->linep = (e->plen + e->pos) / e->col_nbr;
  25. }
  26. /*
  27. ** Suppr left and right
  28. ** Get right and left parts without taking the deleted char
  29. ** Join two strings
  30. ** If suppr_left, move cursor left
  31. ** Delete char at cursor position
  32. */
  33. void suppr(t_e *e, int pos, int side)
  34. {
  35. char *snd;
  36. snd = ft_strsub(e->cmd, pos, e->len);
  37. e->cmd[pos - 1] = '\0';
  38. e->cmd = ft_strjoinf(e->cmd, snd, 3);
  39. if (side == -1)
  40. term_action("le");
  41. term_action("dc");
  42. }