term_tools.c 849 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "sh.h"
  2. /*
  3. ** Up and down lines
  4. ** add to e->pos
  5. ** block going up only for cmd pos > col_nbr
  6. */
  7. void up_down_line(int side, t_e *e)
  8. {
  9. int future_pos;
  10. if (side == -1 && e->pos + e->col_nbr <= e->len)
  11. {
  12. term_action("do");
  13. future_pos = e->pos + e->col_nbr;
  14. e->pos = e->col_nbr * ++e->linep - e->plen - 1;
  15. while (++e->pos < future_pos)
  16. term_action("nd");
  17. }
  18. if (side == 1 && e->pos >= e->col_nbr)
  19. {
  20. e->linep--;
  21. term_action("up");
  22. e->pos -= e->col_nbr;
  23. }
  24. }
  25. /*
  26. ** Clear screen, then display prompt and cmd
  27. */
  28. void clear_l(t_e *e)
  29. {
  30. term_action("cl");
  31. ft_printf("%s%s", PROMPT, e->cmd);
  32. }
  33. /*
  34. ** get special termcaps char
  35. ** display it
  36. */
  37. void term_action(char *str)
  38. {
  39. char *res;
  40. if ((res = tgetstr(str, NULL)) == NULL)
  41. return ;
  42. tputs(res, 0, *my_outc);
  43. }
  44. int my_outc(int c)
  45. {
  46. ft_putchar(c);
  47. return (1);
  48. }