tinyrl.h 6.3 KB

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