tinyrl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef _tinyrl_tinyrl_h
  2. #define _tinyrl_tinyrl_h
  3. #include <stdio.h>
  4. #include <faux/faux.h>
  5. #include "tinyrl/vt100.h"
  6. C_DECL_BEGIN
  7. typedef struct tinyrl_s tinyrl_t;
  8. typedef enum {
  9. /**
  10. * no possible completions were found
  11. */
  12. TINYRL_NO_MATCH = 0,
  13. /**
  14. * the provided string was already an exact match
  15. */
  16. TINYRL_MATCH,
  17. /**
  18. * the provided string was ambiguous and produced
  19. * more than one possible completion
  20. */
  21. TINYRL_AMBIGUOUS,
  22. /**
  23. * the provided string was unambiguous and a
  24. * completion was performed
  25. */
  26. TINYRL_COMPLETED_MATCH,
  27. /**
  28. * the provided string was ambiguous but a partial
  29. * completion was performed.
  30. */
  31. TINYRL_COMPLETED_AMBIGUOUS,
  32. /**
  33. * the provided string was an exact match for one
  34. * possible value but there are other exetensions
  35. * of the string available.
  36. */
  37. TINYRL_MATCH_WITH_EXTENSIONS
  38. } tinyrl_match_e;
  39. /* virtual methods */
  40. typedef char *tinyrl_compentry_func_t(tinyrl_t * instance,
  41. const char *text, unsigned offset, unsigned state);
  42. typedef int tinyrl_hook_func_t(tinyrl_t * instance);
  43. typedef char **tinyrl_completion_func_t(tinyrl_t * instance,
  44. const char *text, unsigned start, unsigned end);
  45. typedef int tinyrl_timeout_fn_t(tinyrl_t *instance);
  46. /**
  47. * \return
  48. * - BOOL_TRUE if the action associated with the key has
  49. * been performed successfully
  50. * - BOOL_FALSE if the action was not successful
  51. */
  52. typedef bool_t tinyrl_key_func_t(tinyrl_t *instance, unsigned char key);
  53. tinyrl_t *tinyrl_new(FILE *istream, FILE *ostream,
  54. const char *hist_fname, size_t hist_stifle);
  55. void tinyrl_free(tinyrl_t *tinyrl);
  56. bool_t tinyrl_bind_key(tinyrl_t *tinyrl, int key, tinyrl_key_func_t *fn);
  57. void tinyrl_set_hotkey_fn(tinyrl_t *tinyrl, tinyrl_key_func_t *fn);
  58. void tinyrl_set_istream(tinyrl_t *tinyrl, FILE *istream);
  59. FILE *tinyrl_istream(const tinyrl_t *tinyrl);
  60. void tinyrl_set_ostream(tinyrl_t *tinyrl, FILE *ostream);
  61. FILE *tinyrl_ostream(const tinyrl_t *tinyrl);
  62. void tinyrl_set_utf8(tinyrl_t *tinyrl, bool_t utf8);
  63. bool_t tinyrl_utf8(const tinyrl_t *tinyrl);
  64. bool_t tinyrl_busy(const tinyrl_t *tinyrl);
  65. void tinyrl_set_busy(tinyrl_t *tinyrl, bool_t busy);
  66. void tinyrl_set_prompt(tinyrl_t *tinyrl, const char *prompt);
  67. const char *tinyrl_prompt(const tinyrl_t *tinyrl);
  68. const char *tinyrl_line(const tinyrl_t *tinyrl);
  69. bool_t tinyrl_hist_save(const tinyrl_t *tinyrl);
  70. bool_t tinyrl_hist_restore(tinyrl_t *tinyrl);
  71. void tinyrl_line_to_hist(tinyrl_t *tinyrl);
  72. void tinyrl_reset_hist_pos(tinyrl_t *tinyrl);
  73. void *tinyrl_udata(const tinyrl_t *tinyrl);
  74. void tinyrl_set_udata(tinyrl_t *tinyrl, void *udata);
  75. void tty_raw_mode(tinyrl_t *tinyrl);
  76. void tty_restore_mode(tinyrl_t *tinyrl);
  77. int tinyrl_read(tinyrl_t *tinyrl);
  78. void tinyrl_redisplay(tinyrl_t *tinyrl);
  79. void tinyrl_save_last(tinyrl_t *tinyrl);
  80. void tinyrl_reset_line_state(tinyrl_t *tinyrl);
  81. void tinyrl_reset_line(tinyrl_t *tinyrl);
  82. void tinyrl_crlf(const tinyrl_t *tinyrl);
  83. void tinyrl_multi_crlf(const tinyrl_t *tinyrl);
  84. void tinyrl_winsize(const tinyrl_t *tinyrl, size_t *width, size_t *height);
  85. size_t tinyrl_width(const tinyrl_t *tinyrl);
  86. size_t tinyrl_height(const tinyrl_t *tinyrl);
  87. int tinyrl_printf(const tinyrl_t *tinyrl, const char *fmt, ...);
  88. size_t tinyrl_equal_part(const tinyrl_t *tinyrl,
  89. const char *s1, const char *s2);
  90. bool_t tinyrl_line_insert(tinyrl_t *tinyrl, const char *text, size_t len);
  91. bool_t tinyrl_line_delete(tinyrl_t *tinyrl, size_t start, size_t len);
  92. bool_t tinyrl_line_replace(tinyrl_t *tinyrl, const char *text);
  93. extern void tinyrl_done(tinyrl_t * instance);
  94. extern void tinyrl_completion_over(tinyrl_t * instance);
  95. extern void tinyrl_completion_error_over(tinyrl_t * instance);
  96. extern bool_t tinyrl_is_completion_error_over(const tinyrl_t * instance);
  97. /**
  98. * This operation returns the current line in use by the tinyrl instance
  99. * NB. the pointer will become invalid after any further operation on the
  100. * instance.
  101. */
  102. extern void tinyrl_delete_matches(char **instance);
  103. extern char **tinyrl_completion(tinyrl_t *instance,
  104. const char *line, unsigned start, unsigned end,
  105. tinyrl_compentry_func_t *generator);
  106. extern void tinyrl_ding(const tinyrl_t * instance);
  107. extern void
  108. tinyrl_replace_line(tinyrl_t * instance, const char *text, int clear_undo);
  109. /**
  110. * Complete the current word in the input buffer, displaying
  111. * a prompt to clarify any abiguity if necessary.
  112. *
  113. * \return
  114. * - the type of match performed.
  115. * \post
  116. * - If the current word is ambiguous then a list of
  117. * possible completions will be displayed.
  118. */
  119. extern tinyrl_match_e tinyrl_complete(tinyrl_t * instance);
  120. /**
  121. * Complete the current word in the input buffer, displaying
  122. * a prompt to clarify any abiguity or extra extensions if necessary.
  123. *
  124. * \return
  125. * - the type of match performed.
  126. * \post
  127. * - If the current word is ambiguous then a list of
  128. * possible completions will be displayed.
  129. * - If the current word is complete but there are extra
  130. * completions which are an extension of that word then
  131. * a list of these will be displayed.
  132. */
  133. extern tinyrl_match_e tinyrl_complete_with_extensions(tinyrl_t * instance);
  134. /**
  135. * Disable echoing of input characters when a line in input.
  136. *
  137. */
  138. extern void tinyrl_disable_echo(
  139. /**
  140. * The instance on which to operate
  141. */
  142. tinyrl_t * instance,
  143. /**
  144. * The character to display instead of a key press.
  145. *
  146. * If this has the special value '/0' then the insertion point will not
  147. * be moved when keys are pressed.
  148. */
  149. char echo_char);
  150. /**
  151. * Enable key echoing for this instance. (This is the default behaviour)
  152. */
  153. extern void tinyrl_enable_echo(
  154. /**
  155. * The instance on which to operate
  156. */
  157. tinyrl_t * instance);
  158. /**
  159. * Indicate whether the current insertion point is quoting or not
  160. */
  161. extern bool_t tinyrl_is_quoting(
  162. /**
  163. * The instance on which to operate
  164. */
  165. const tinyrl_t * instance);
  166. /**
  167. * Indicate whether the current insertion is empty or not
  168. */
  169. extern bool_t
  170. tinyrl_is_empty(
  171. /**
  172. * The instance on which to operate
  173. */
  174. const tinyrl_t *instance
  175. );
  176. /**
  177. * Limit maximum line length
  178. */
  179. extern void tinyrl_limit_line_length(
  180. /**
  181. * The instance on which to operate
  182. */
  183. tinyrl_t * instance,
  184. /**
  185. * The length to limit to (0) is unlimited
  186. */
  187. unsigned length);
  188. C_DECL_END
  189. #endif /* _tinyrl_tinyrl_h */