tinyrl.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /**
  2. \ingroup tinyrl
  3. \defgroup tinyrl_class tinyrl
  4. @{
  5. \brief This class provides instances which are capable of handling user input
  6. from a CLI in a "readline" like fashion.
  7. */
  8. #ifndef _tinyrl_tinyrl_h
  9. #define _tinyrl_tinyrl_h
  10. #include <stdio.h>
  11. #include "lub/types.h"
  12. #include "lub/c_decl.h"
  13. #include "tinyrl/history.h"
  14. _BEGIN_C_DECL
  15. typedef struct _tinyrl tinyrl_t;
  16. typedef enum
  17. {
  18. /**
  19. * no possible completions were found
  20. */
  21. TINYRL_NO_MATCH = 0,
  22. /**
  23. * the provided string was already an exact match
  24. */
  25. TINYRL_MATCH,
  26. /**
  27. * the provided string was ambiguous and produced
  28. * more than one possible completion
  29. */
  30. TINYRL_AMBIGUOUS,
  31. /**
  32. * the provided string was unambiguous and a
  33. * completion was performed
  34. */
  35. TINYRL_COMPLETED_MATCH,
  36. /**
  37. * the provided string was ambiguous but a partial
  38. * completion was performed.
  39. */
  40. TINYRL_COMPLETED_AMBIGUOUS,
  41. /**
  42. * the provided string was an exact match for one
  43. * possible value but there are other exetensions
  44. * of the string available.
  45. */
  46. TINYRL_MATCH_WITH_EXTENSIONS
  47. } tinyrl_match_e;
  48. /* virtual methods */
  49. typedef char *
  50. tinyrl_compentry_func_t(tinyrl_t *instance,
  51. const char *text,
  52. unsigned offset,
  53. unsigned state);
  54. typedef int
  55. tinyrl_hook_func_t(tinyrl_t *instance);
  56. typedef char **
  57. tinyrl_completion_func_t(tinyrl_t *instance,
  58. const char *text,
  59. unsigned start,
  60. unsigned end);
  61. /**
  62. * \return
  63. * - BOOL_TRUE if the action associated with the key has
  64. * been performed successfully
  65. * - BOOL_FALSE if the action was not successful
  66. */
  67. typedef bool_t
  68. tinyrl_key_func_t(tinyrl_t *instance,
  69. int key);
  70. /* exported functions */
  71. extern tinyrl_t *
  72. tinyrl_new(FILE *instream,
  73. FILE *outstream,
  74. unsigned stifle,
  75. tinyrl_completion_func_t *complete_fn);
  76. /*lint -esym(534,tinyrl_printf) Ignoring return value of function */
  77. extern int
  78. tinyrl_printf(const tinyrl_t *instance,
  79. const char *fmt,
  80. ...);
  81. extern void
  82. tinyrl_delete(tinyrl_t *instance);
  83. extern tinyrl_history_t *
  84. tinyrl__get_history(const tinyrl_t *instance);
  85. extern const char *
  86. tinyrl__get_prompt(const tinyrl_t *instance);
  87. extern void
  88. tinyrl_done(tinyrl_t *instance);
  89. extern void
  90. tinyrl_completion_over(tinyrl_t *instance);
  91. extern void
  92. tinyrl_completion_error_over(tinyrl_t *instance);
  93. extern bool_t
  94. tinyrl_is_completion_error_over(const tinyrl_t *instance);
  95. extern void *
  96. tinyrl__get_context(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 const char *
  103. tinyrl__get_line(const tinyrl_t *instance);
  104. extern void
  105. tinyrl__set_istream(tinyrl_t *instance,
  106. FILE *istream);
  107. extern bool_t
  108. tinyrl__get_isatty(const tinyrl_t *instance);
  109. extern FILE *
  110. tinyrl__get_istream(const tinyrl_t *instance);
  111. extern FILE *
  112. tinyrl__get_ostream(const tinyrl_t *instance);
  113. extern bool_t
  114. tinyrl__get_utf8(const tinyrl_t *instance);
  115. extern void
  116. tinyrl__set_utf8(tinyrl_t *instance, bool_t utf8);
  117. extern char *
  118. tinyrl_readline(tinyrl_t *instance,
  119. const char *prompt,
  120. void *context);
  121. extern char *
  122. tinyrl_forceline(tinyrl_t *instance,
  123. const char *prompt,
  124. void *context,
  125. const char *line);
  126. extern bool_t
  127. tinyrl_bind_key(tinyrl_t *instance,
  128. int key,
  129. tinyrl_key_func_t *fn);
  130. extern void
  131. tinyrl_delete_matches(char **instance);
  132. extern char **
  133. tinyrl_completion(tinyrl_t *instance,
  134. const char *line,
  135. unsigned start,
  136. unsigned end,
  137. tinyrl_compentry_func_t *generator);
  138. extern void
  139. tinyrl_crlf(const tinyrl_t *instance);
  140. extern void
  141. tinyrl_ding(const tinyrl_t *instance);
  142. extern void
  143. tinyrl_reset_line_state(tinyrl_t *instance);
  144. extern bool_t
  145. tinyrl_insert_text(tinyrl_t *instance,
  146. const char *text);
  147. extern void
  148. tinyrl_delete_text(tinyrl_t *instance,
  149. unsigned start,
  150. unsigned end);
  151. extern void
  152. tinyrl_redisplay(tinyrl_t *instance);
  153. extern void
  154. tinyrl_replace_line(tinyrl_t *instance,
  155. const char *text,
  156. int clear_undo);
  157. /**
  158. * Complete the current word in the input buffer, displaying
  159. * a prompt to clarify any abiguity if necessary.
  160. *
  161. * \return
  162. * - the type of match performed.
  163. * \post
  164. * - If the current word is ambiguous then a list of
  165. * possible completions will be displayed.
  166. */
  167. extern tinyrl_match_e
  168. tinyrl_complete(tinyrl_t *instance);
  169. /**
  170. * Complete the current word in the input buffer, displaying
  171. * a prompt to clarify any abiguity or extra extensions if necessary.
  172. *
  173. * \return
  174. * - the type of match performed.
  175. * \post
  176. * - If the current word is ambiguous then a list of
  177. * possible completions will be displayed.
  178. * - If the current word is complete but there are extra
  179. * completions which are an extension of that word then
  180. * a list of these will be displayed.
  181. */
  182. extern tinyrl_match_e
  183. tinyrl_complete_with_extensions(tinyrl_t *instance);
  184. /**
  185. * Disable echoing of input characters when a line in input.
  186. *
  187. */
  188. extern void
  189. tinyrl_disable_echo(
  190. /**
  191. * The instance on which to operate
  192. */
  193. tinyrl_t *instance,
  194. /**
  195. * The character to display instead of a key press.
  196. *
  197. * If this has the special value '/0' then the insertion point will not
  198. * be moved when keys are pressed.
  199. */
  200. char echo_char
  201. );
  202. /**
  203. * Enable key echoing for this instance. (This is the default behaviour)
  204. */
  205. extern void
  206. tinyrl_enable_echo(
  207. /**
  208. * The instance on which to operate
  209. */
  210. tinyrl_t *instance
  211. );
  212. /**
  213. * Indicate whether the current insertion point is quoting or not
  214. */
  215. extern bool_t
  216. tinyrl_is_quoting(
  217. /**
  218. * The instance on which to operate
  219. */
  220. const tinyrl_t *instance
  221. );
  222. /**
  223. * Limit maximum line length
  224. */
  225. extern void
  226. tinyrl_limit_line_length(
  227. /**
  228. * The instance on which to operate
  229. */
  230. tinyrl_t *instance,
  231. /**
  232. * The length to limit to (0) is unlimited
  233. */
  234. unsigned length
  235. );
  236. _END_C_DECL
  237. #endif /* _tinyrl_tinyrl_h */
  238. /** @} tinyrl_tinyrl */