keys.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "sh.h"
  2. /*
  3. ** clear: ctrl + L
  4. ** left suppr
  5. ** right suppr
  6. ** begin: ctrl + A
  7. ** end: ctrl + E
  8. */
  9. void handle_keys(t_e *e, int all)
  10. {
  11. if (e->key[0] == 12 && all == 1)
  12. clear_l(e);
  13. else if (e->key[0] == 127)
  14. {
  15. if (e->pos > 0)
  16. suppr(e, e->pos, -1);
  17. e->pos = e->pos <= 0 ? e->pos : e->pos - 1;
  18. }
  19. else if (e->key[0] == 27 && e->key[1] == 91 && e->key[2] == 51\
  20. && e->len > e->pos)
  21. suppr(e, e->pos + 1, 1);
  22. else if (e->key[0] == 9 && e->key[1] == 91 && e->key[2] == 51)
  23. ft_printf("Tab\n");
  24. else if (e->key[0] == 1)
  25. begin(e);
  26. else if (e->key[0] == 5)
  27. end(e);
  28. else
  29. handle_keys2(e, all);
  30. }
  31. /*
  32. ** previous word: ctrl + U
  33. ** next word: ctrl + I
  34. ** upper line: ctrl + T
  35. ** bottom line: ctrl + G
  36. ** copy: ctrl + K
  37. ** paste: ctrl + P
  38. ** exit: ctrl + D
  39. */
  40. void handle_keys2(t_e *e, int all)
  41. {
  42. if (e->key[0] == 21)
  43. words_move(-1, e);
  44. else if (e->key[0] == 9)
  45. words_move(1, e);
  46. else if (e->key[0] == 20)
  47. up_down_line(1, e);
  48. else if (e->key[0] == 7)
  49. up_down_line(-1, e);
  50. else if (e->key[0] == 11)
  51. term_action("ps");
  52. else if (e->key[0] == 16)
  53. term_action("po");
  54. else if (e->key[0] == 27 && e->key[1] == 91)
  55. handle_key_arrows(e, all);
  56. else if (e->key[0] == 4)
  57. {
  58. if (e->len == 0 || e->d == 1)
  59. {
  60. set_term_modes(1);
  61. error_message("", "exit", "exit");
  62. }
  63. else if (e->d == 0)
  64. e->d = 1;
  65. }
  66. }
  67. /*
  68. ** Upper arrow, down arrow
  69. ** Right arrow, left arrow
  70. ** End, Begin
  71. */
  72. void handle_key_arrows(t_e *e, int all)
  73. {
  74. if (e->key[2] == 65 && all == 1)
  75. move_history(e, UP);
  76. else if (e->key[2] == 66 && all == 1)
  77. move_history(e, DOWN);
  78. else if (e->key[2] == 67)
  79. move_right(e);
  80. else if (e->key[2] == 68)
  81. move_left(e);
  82. else if (e->key[2] == 70)
  83. end(e);
  84. else if (e->key[2] == 72)
  85. begin(e);
  86. }