keys.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <faux/faux.h>
  9. #include <faux/str.h>
  10. #include "private.h"
  11. bool_t tinyrl_key_default(tinyrl_t * tinyrl, char key)
  12. {
  13. if (key > 31) {
  14. // Inject new char to the line
  15. tinyrl_line_insert(tinyrl, &key, 1);
  16. } else {
  17. // Call the external hotkey analyzer
  18. if (tinyrl->hotkey_fn)
  19. tinyrl->hotkey_fn(tinyrl, key);
  20. }
  21. return BOOL_TRUE;
  22. }
  23. bool_t tinyrl_key_interrupt(tinyrl_t * tinyrl, char key)
  24. {
  25. /*
  26. tinyrl_crlf(tinyrl);
  27. tinyrl_delete_text(tinyrl, 0, tinyrl->end);
  28. tinyrl->done = BOOL_TRUE;
  29. // keep the compiler happy
  30. key = key;
  31. */
  32. return BOOL_TRUE;
  33. }
  34. bool_t tinyrl_key_start_of_line(tinyrl_t * tinyrl, char key)
  35. {
  36. /*
  37. // set the insertion point to the start of the line
  38. tinyrl->point = 0;
  39. // keep the compiler happy
  40. key = key;
  41. */
  42. return BOOL_TRUE;
  43. }
  44. bool_t tinyrl_key_end_of_line(tinyrl_t * tinyrl, char key)
  45. {
  46. /*
  47. // set the insertion point to the end of the line
  48. tinyrl->point = tinyrl->end;
  49. // keep the compiler happy
  50. key = key;
  51. */
  52. return BOOL_TRUE;
  53. }
  54. bool_t tinyrl_key_kill(tinyrl_t * tinyrl, char key)
  55. {
  56. /*
  57. // release any old kill string
  58. lub_string_free(tinyrl->kill_string);
  59. // store the killed string
  60. tinyrl->kill_string = lub_string_dup(&tinyrl->buffer[tinyrl->point]);
  61. // delete the text to the end of the line
  62. tinyrl_delete_text(tinyrl, tinyrl->point, tinyrl->end);
  63. // keep the compiler happy
  64. key = key;
  65. */
  66. return BOOL_TRUE;
  67. }
  68. bool_t tinyrl_key_yank(tinyrl_t * tinyrl, char key)
  69. {
  70. bool_t result = BOOL_FALSE;
  71. /*
  72. if (tinyrl->kill_string) {
  73. // insert the kill string at the current insertion point
  74. result = tinyrl_insert_text(tinyrl, tinyrl->kill_string);
  75. }
  76. // keep the compiler happy
  77. key = key;
  78. */
  79. return result;
  80. }
  81. bool_t tinyrl_key_crlf(tinyrl_t * tinyrl, char key)
  82. {
  83. /*
  84. tinyrl_crlf(tinyrl);
  85. tinyrl->done = BOOL_TRUE;
  86. // keep the compiler happy
  87. key = key;
  88. */
  89. return BOOL_TRUE;
  90. }
  91. bool_t tinyrl_key_up(tinyrl_t * tinyrl, char key)
  92. {
  93. bool_t result = BOOL_FALSE;
  94. /*
  95. tinyrl_history_entry_t *entry = NULL;
  96. if (tinyrl->line == tinyrl->buffer) {
  97. // go to the last history entry
  98. entry = tinyrl_history_getlast(tinyrl->history, &tinyrl->hist_iter);
  99. } else {
  100. // already traversing the history list so get previous
  101. entry = tinyrl_history_getprevious(&tinyrl->hist_iter);
  102. }
  103. if (entry) {
  104. // display the entry moving the insertion point
  105. * to the end of the line
  106. tinyrl->line = tinyrl_history_entry__get_line(entry);
  107. tinyrl->point = tinyrl->end = strlen(tinyrl->line);
  108. result = BOOL_TRUE;
  109. }
  110. // keep the compiler happy
  111. key = key;
  112. */
  113. return result;
  114. }
  115. bool_t tinyrl_key_down(tinyrl_t * tinyrl, char key)
  116. {
  117. bool_t result = BOOL_FALSE;
  118. /*
  119. if (tinyrl->line != tinyrl->buffer) {
  120. // we are not already at the bottom
  121. // the iterator will have been set up by the key_up() function
  122. tinyrl_history_entry_t *entry =
  123. tinyrl_history_getnext(&tinyrl->hist_iter);
  124. if (!entry) {
  125. // nothing more in the history list
  126. tinyrl->line = tinyrl->buffer;
  127. } else {
  128. tinyrl->line = tinyrl_history_entry__get_line(entry);
  129. }
  130. // display the entry moving the insertion point
  131. // to the end of the line
  132. tinyrl->point = tinyrl->end = strlen(tinyrl->line);
  133. result = BOOL_TRUE;
  134. }
  135. // keep the compiler happy
  136. key = key;
  137. */
  138. return result;
  139. }
  140. bool_t tinyrl_key_left(tinyrl_t * tinyrl, char key)
  141. {
  142. bool_t result = BOOL_FALSE;
  143. /*
  144. if (tinyrl->point > 0) {
  145. tinyrl->point--;
  146. utf8_point_left(tinyrl);
  147. result = BOOL_TRUE;
  148. }
  149. // keep the compiler happy
  150. key = key;
  151. */
  152. return result;
  153. }
  154. bool_t tinyrl_key_right(tinyrl_t * tinyrl, char key)
  155. {
  156. bool_t result = BOOL_FALSE;
  157. /*
  158. if (tinyrl->point < tinyrl->end) {
  159. tinyrl->point++;
  160. utf8_point_right(tinyrl);
  161. result = BOOL_TRUE;
  162. }
  163. // keep the compiler happy
  164. key = key;
  165. */
  166. return result;
  167. }
  168. bool_t tinyrl_key_backspace(tinyrl_t *tinyrl, char key)
  169. {
  170. bool_t result = BOOL_FALSE;
  171. /*
  172. if (tinyrl->point) {
  173. unsigned int end = --tinyrl->point;
  174. utf8_point_left(tinyrl);
  175. tinyrl_delete_text(tinyrl, tinyrl->point, end);
  176. result = BOOL_TRUE;
  177. }
  178. // keep the compiler happy
  179. key = key;
  180. */
  181. return result;
  182. }
  183. bool_t tinyrl_key_backword(tinyrl_t *tinyrl, char key)
  184. {
  185. bool_t result = BOOL_FALSE;
  186. /*
  187. // remove current whitespace before cursor
  188. while (tinyrl->point > 0 && isspace(tinyrl->line[tinyrl->point - 1]))
  189. tinyrl_key_backspace(tinyrl, KEY_BS);
  190. // delete word before cusor
  191. while (tinyrl->point > 0 && !isspace(tinyrl->line[tinyrl->point - 1]))
  192. tinyrl_key_backspace(tinyrl, KEY_BS);
  193. result = BOOL_TRUE;
  194. // keep the compiler happy
  195. key = key;
  196. */
  197. return result;
  198. }
  199. bool_t tinyrl_key_delete(tinyrl_t * tinyrl, char key)
  200. {
  201. bool_t result = BOOL_FALSE;
  202. /*
  203. if (tinyrl->point < tinyrl->end) {
  204. unsigned int begin = tinyrl->point++;
  205. utf8_point_right(tinyrl);
  206. tinyrl_delete_text(tinyrl, begin, tinyrl->point - 1);
  207. result = BOOL_TRUE;
  208. }
  209. // keep the compiler happy
  210. key = key;
  211. */
  212. return result;
  213. }
  214. bool_t tinyrl_key_clear_screen(tinyrl_t * tinyrl, char key)
  215. {
  216. /*
  217. tinyrl_vt100_clear_screen(tinyrl->term);
  218. tinyrl_vt100_cursor_home(tinyrl->term);
  219. tinyrl_reset_line_state(tinyrl);
  220. // keep the compiler happy
  221. key = key;
  222. tinyrl = tinyrl;
  223. */
  224. return BOOL_TRUE;
  225. }
  226. bool_t tinyrl_key_erase_line(tinyrl_t * tinyrl, char key)
  227. {
  228. /* unsigned int end;
  229. // release any old kill string
  230. lub_string_free(tinyrl->kill_string);
  231. if (!tinyrl->point) {
  232. tinyrl->kill_string = NULL;
  233. return BOOL_TRUE;
  234. }
  235. end = tinyrl->point - 1;
  236. // store the killed string
  237. tinyrl->kill_string = malloc(tinyrl->point + 1);
  238. memcpy(tinyrl->kill_string, tinyrl->buffer, tinyrl->point);
  239. tinyrl->kill_string[tinyrl->point] = '\0';
  240. // delete the text from the start of the line
  241. tinyrl_delete_text(tinyrl, 0, end);
  242. tinyrl->point = 0;
  243. // keep the compiler happy
  244. key = key;
  245. tinyrl = tinyrl;
  246. */
  247. return BOOL_TRUE;
  248. }
  249. bool_t tinyrl_key_tab(tinyrl_t * tinyrl, char key)
  250. {
  251. bool_t result = BOOL_FALSE;
  252. /*
  253. tinyrl_match_e status = tinyrl_complete_with_extensions(tinyrl);
  254. switch (status) {
  255. case TINYRL_COMPLETED_MATCH:
  256. case TINYRL_MATCH:
  257. // everything is OK with the world...
  258. result = tinyrl_insert_text(tinyrl, " ");
  259. break;
  260. case TINYRL_NO_MATCH:
  261. case TINYRL_MATCH_WITH_EXTENSIONS:
  262. case TINYRL_AMBIGUOUS:
  263. case TINYRL_COMPLETED_AMBIGUOUS:
  264. // oops don't change the result and let the bell ring
  265. break;
  266. }
  267. // keep the compiler happy
  268. key = key;
  269. */
  270. return result;
  271. }