keys.c 6.4 KB

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