Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

replxx.h 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /* linenoise.h -- guerrilla line editing library against the idea that a
  2. * line editing lib needs to be 20,000 lines of C code.
  3. *
  4. * See linenoise.c for more information.
  5. *
  6. * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
  7. * Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of Redis nor the names of its contributors may be used
  20. * to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef __REPLXX_H
  36. #define __REPLXX_H
  37. #define REPLXX_VERSION "0.0.2"
  38. #define REPLXX_VERSION_MAJOR 0
  39. #define REPLXX_VERSION_MINOR 0
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /*
  44. * For use in Windows DLLs:
  45. *
  46. * If you are building replxx into a DLL,
  47. * unless you are using supplied CMake based build,
  48. * ensure that 'REPLXX_BUILDING_DLL' is defined when
  49. * building the DLL so that proper symbols are exported.
  50. */
  51. #if defined( _WIN32 ) && ! defined( REPLXX_STATIC )
  52. # ifdef REPLXX_BUILDING_DLL
  53. # define REPLXX_IMPEXP __declspec( dllexport )
  54. # else
  55. # define REPLXX_IMPEXP __declspec( dllimport )
  56. # endif
  57. #else
  58. # define REPLXX_IMPEXP /**/
  59. #endif
  60. /*! \brief Color definitions to use in highlighter callbacks.
  61. */
  62. typedef enum {
  63. REPLXX_COLOR_BLACK = 0,
  64. REPLXX_COLOR_RED = 1,
  65. REPLXX_COLOR_GREEN = 2,
  66. REPLXX_COLOR_BROWN = 3,
  67. REPLXX_COLOR_BLUE = 4,
  68. REPLXX_COLOR_MAGENTA = 5,
  69. REPLXX_COLOR_CYAN = 6,
  70. REPLXX_COLOR_LIGHTGRAY = 7,
  71. REPLXX_COLOR_GRAY = 8,
  72. REPLXX_COLOR_BRIGHTRED = 9,
  73. REPLXX_COLOR_BRIGHTGREEN = 10,
  74. REPLXX_COLOR_YELLOW = 11,
  75. REPLXX_COLOR_BRIGHTBLUE = 12,
  76. REPLXX_COLOR_BRIGHTMAGENTA = 13,
  77. REPLXX_COLOR_BRIGHTCYAN = 14,
  78. REPLXX_COLOR_WHITE = 15,
  79. REPLXX_COLOR_NORMAL = REPLXX_COLOR_LIGHTGRAY,
  80. REPLXX_COLOR_DEFAULT = -1,
  81. REPLXX_COLOR_ERROR = -2
  82. } ReplxxColor;
  83. enum { REPLXX_KEY_BASE = 0x0010ffff + 1 };
  84. enum { REPLXX_KEY_BASE_SHIFT = 0x01000000 };
  85. enum { REPLXX_KEY_BASE_CONTROL = 0x02000000 };
  86. enum { REPLXX_KEY_BASE_META = 0x04000000 };
  87. enum { REPLXX_KEY_ESCAPE = 27 };
  88. enum { REPLXX_KEY_PAGE_UP = REPLXX_KEY_BASE + 1 };
  89. enum { REPLXX_KEY_PAGE_DOWN = REPLXX_KEY_PAGE_UP + 1 };
  90. enum { REPLXX_KEY_DOWN = REPLXX_KEY_PAGE_DOWN + 1 };
  91. enum { REPLXX_KEY_UP = REPLXX_KEY_DOWN + 1 };
  92. enum { REPLXX_KEY_LEFT = REPLXX_KEY_UP + 1 };
  93. enum { REPLXX_KEY_RIGHT = REPLXX_KEY_LEFT + 1 };
  94. enum { REPLXX_KEY_HOME = REPLXX_KEY_RIGHT + 1 };
  95. enum { REPLXX_KEY_END = REPLXX_KEY_HOME + 1 };
  96. enum { REPLXX_KEY_DELETE = REPLXX_KEY_END + 1 };
  97. enum { REPLXX_KEY_INSERT = REPLXX_KEY_DELETE + 1 };
  98. enum { REPLXX_KEY_F1 = REPLXX_KEY_INSERT + 1 };
  99. enum { REPLXX_KEY_F2 = REPLXX_KEY_F1 + 1 };
  100. enum { REPLXX_KEY_F3 = REPLXX_KEY_F2 + 1 };
  101. enum { REPLXX_KEY_F4 = REPLXX_KEY_F3 + 1 };
  102. enum { REPLXX_KEY_F5 = REPLXX_KEY_F4 + 1 };
  103. enum { REPLXX_KEY_F6 = REPLXX_KEY_F5 + 1 };
  104. enum { REPLXX_KEY_F7 = REPLXX_KEY_F6 + 1 };
  105. enum { REPLXX_KEY_F8 = REPLXX_KEY_F7 + 1 };
  106. enum { REPLXX_KEY_F9 = REPLXX_KEY_F8 + 1 };
  107. enum { REPLXX_KEY_F10 = REPLXX_KEY_F9 + 1 };
  108. enum { REPLXX_KEY_F11 = REPLXX_KEY_F10 + 1 };
  109. enum { REPLXX_KEY_F12 = REPLXX_KEY_F11 + 1 };
  110. enum { REPLXX_KEY_F13 = REPLXX_KEY_F12 + 1 };
  111. enum { REPLXX_KEY_F14 = REPLXX_KEY_F13 + 1 };
  112. enum { REPLXX_KEY_F15 = REPLXX_KEY_F14 + 1 };
  113. enum { REPLXX_KEY_F16 = REPLXX_KEY_F15 + 1 };
  114. enum { REPLXX_KEY_F17 = REPLXX_KEY_F16 + 1 };
  115. enum { REPLXX_KEY_F18 = REPLXX_KEY_F17 + 1 };
  116. enum { REPLXX_KEY_F19 = REPLXX_KEY_F18 + 1 };
  117. enum { REPLXX_KEY_F20 = REPLXX_KEY_F19 + 1 };
  118. enum { REPLXX_KEY_F21 = REPLXX_KEY_F20 + 1 };
  119. enum { REPLXX_KEY_F22 = REPLXX_KEY_F21 + 1 };
  120. enum { REPLXX_KEY_F23 = REPLXX_KEY_F22 + 1 };
  121. enum { REPLXX_KEY_F24 = REPLXX_KEY_F23 + 1 };
  122. enum { REPLXX_KEY_MOUSE = REPLXX_KEY_F24 + 1 };
  123. enum { REPLXX_KEY_PASTE_START = REPLXX_KEY_MOUSE + 1 };
  124. enum { REPLXX_KEY_PASTE_FINISH = REPLXX_KEY_PASTE_START + 1 };
  125. #define REPLXX_KEY_SHIFT( key ) ( ( key ) | REPLXX_KEY_BASE_SHIFT )
  126. #define REPLXX_KEY_CONTROL( key ) ( ( key ) | REPLXX_KEY_BASE_CONTROL )
  127. #define REPLXX_KEY_META( key ) ( ( key ) | REPLXX_KEY_BASE_META )
  128. enum { REPLXX_KEY_BACKSPACE = REPLXX_KEY_CONTROL( 'H' ) };
  129. enum { REPLXX_KEY_TAB = REPLXX_KEY_CONTROL( 'I' ) };
  130. enum { REPLXX_KEY_ENTER = REPLXX_KEY_CONTROL( 'M' ) };
  131. /*! \brief List of built-in actions that act upon user input.
  132. */
  133. typedef enum {
  134. REPLXX_ACTION_INSERT_CHARACTER,
  135. REPLXX_ACTION_NEW_LINE,
  136. REPLXX_ACTION_DELETE_CHARACTER_UNDER_CURSOR,
  137. REPLXX_ACTION_DELETE_CHARACTER_LEFT_OF_CURSOR,
  138. REPLXX_ACTION_KILL_TO_END_OF_LINE,
  139. REPLXX_ACTION_KILL_TO_BEGINING_OF_LINE,
  140. REPLXX_ACTION_KILL_TO_END_OF_WORD,
  141. REPLXX_ACTION_KILL_TO_BEGINING_OF_WORD,
  142. REPLXX_ACTION_KILL_TO_END_OF_SUBWORD,
  143. REPLXX_ACTION_KILL_TO_BEGINING_OF_SUBWORD,
  144. REPLXX_ACTION_KILL_TO_WHITESPACE_ON_LEFT,
  145. REPLXX_ACTION_YANK,
  146. REPLXX_ACTION_YANK_CYCLE,
  147. REPLXX_ACTION_YANK_LAST_ARG,
  148. REPLXX_ACTION_MOVE_CURSOR_TO_BEGINING_OF_LINE,
  149. REPLXX_ACTION_MOVE_CURSOR_TO_END_OF_LINE,
  150. REPLXX_ACTION_MOVE_CURSOR_ONE_WORD_LEFT,
  151. REPLXX_ACTION_MOVE_CURSOR_ONE_WORD_RIGHT,
  152. REPLXX_ACTION_MOVE_CURSOR_ONE_SUBWORD_LEFT,
  153. REPLXX_ACTION_MOVE_CURSOR_ONE_SUBWORD_RIGHT,
  154. REPLXX_ACTION_MOVE_CURSOR_LEFT,
  155. REPLXX_ACTION_MOVE_CURSOR_RIGHT,
  156. REPLXX_ACTION_HISTORY_NEXT,
  157. REPLXX_ACTION_HISTORY_PREVIOUS,
  158. REPLXX_ACTION_HISTORY_FIRST,
  159. REPLXX_ACTION_HISTORY_LAST,
  160. REPLXX_ACTION_HISTORY_INCREMENTAL_SEARCH,
  161. REPLXX_ACTION_HISTORY_COMMON_PREFIX_SEARCH,
  162. REPLXX_ACTION_HINT_NEXT,
  163. REPLXX_ACTION_HINT_PREVIOUS,
  164. REPLXX_ACTION_CAPITALIZE_WORD,
  165. REPLXX_ACTION_LOWERCASE_WORD,
  166. REPLXX_ACTION_UPPERCASE_WORD,
  167. REPLXX_ACTION_CAPITALIZE_SUBWORD,
  168. REPLXX_ACTION_LOWERCASE_SUBWORD,
  169. REPLXX_ACTION_UPPERCASE_SUBWORD,
  170. REPLXX_ACTION_TRANSPOSE_CHARACTERS,
  171. REPLXX_ACTION_TOGGLE_OVERWRITE_MODE,
  172. #ifndef _WIN32
  173. REPLXX_ACTION_VERBATIM_INSERT,
  174. REPLXX_ACTION_SUSPEND,
  175. #endif
  176. REPLXX_ACTION_BRACKETED_PASTE,
  177. REPLXX_ACTION_CLEAR_SCREEN,
  178. REPLXX_ACTION_CLEAR_SELF,
  179. REPLXX_ACTION_REPAINT,
  180. REPLXX_ACTION_COMPLETE_LINE,
  181. REPLXX_ACTION_COMPLETE_NEXT,
  182. REPLXX_ACTION_COMPLETE_PREVIOUS,
  183. REPLXX_ACTION_COMMIT_LINE,
  184. REPLXX_ACTION_ABORT_LINE,
  185. REPLXX_ACTION_SEND_EOF
  186. } ReplxxAction;
  187. /*! \brief Possible results of key-press handler actions.
  188. */
  189. typedef enum {
  190. REPLXX_ACTION_RESULT_CONTINUE, /*!< Continue processing user input. */
  191. REPLXX_ACTION_RESULT_RETURN, /*!< Return user input entered so far. */
  192. REPLXX_ACTION_RESULT_BAIL /*!< Stop processing user input, returns nullptr from the \e input() call. */
  193. } ReplxxActionResult;
  194. typedef struct ReplxxStateTag {
  195. char const* text;
  196. int cursorPosition;
  197. } ReplxxState;
  198. typedef struct Replxx Replxx;
  199. typedef struct ReplxxHistoryScan ReplxxHistoryScan;
  200. typedef struct ReplxxHistoryEntryTag {
  201. char const* timestamp;
  202. char const* text;
  203. } ReplxxHistoryEntry;
  204. /*! \brief Create Replxx library resource holder.
  205. *
  206. * Use replxx_end() to free resources acquired with this function.
  207. *
  208. * \return Replxx library resource holder.
  209. */
  210. REPLXX_IMPEXP Replxx* replxx_init( void );
  211. /*! \brief Cleanup resources used by Replxx library.
  212. *
  213. * \param replxx - a Replxx library resource holder.
  214. */
  215. REPLXX_IMPEXP void replxx_end( Replxx* replxx );
  216. /*! \brief Line modification callback type definition.
  217. *
  218. * User can observe and modify line contents (and cursor position)
  219. * in response to changes to both introduced by the user through
  220. * normal interactions.
  221. *
  222. * When callback returns Replxx updates current line content
  223. * and current cursor position to the ones updated by the callback.
  224. *
  225. * \param line[in,out] - a R/W reference to an UTF-8 encoded input entered by the user so far.
  226. * \param cursorPosition[in,out] - a R/W reference to current cursor position.
  227. * \param userData - pointer to opaque user data block.
  228. */
  229. typedef void (replxx_modify_callback_t)(char** input, int* contextLen, void* userData);
  230. /*! \brief Register modify callback.
  231. *
  232. * \param fn - user defined callback function.
  233. * \param userData - pointer to opaque user data block to be passed into each invocation of the callback.
  234. */
  235. REPLXX_IMPEXP void replxx_set_modify_callback( Replxx*, replxx_modify_callback_t* fn, void* userData );
  236. /*! \brief Highlighter callback type definition.
  237. *
  238. * If user want to have colorful input she must simply install highlighter callback.
  239. * The callback would be invoked by the library after each change to the input done by
  240. * the user. After callback returns library uses data from colors buffer to colorize
  241. * displayed user input.
  242. *
  243. * \e size of \e colors buffer is equal to number of code points in user \e input
  244. * which will be different from simple `strlen( input )`!
  245. *
  246. * \param input - an UTF-8 encoded input entered by the user so far.
  247. * \param colors - output buffer for color information.
  248. * \param size - size of output buffer for color information.
  249. * \param userData - pointer to opaque user data block.
  250. */
  251. typedef void (replxx_highlighter_callback_t)(char const* input, ReplxxColor* colors, int size, void* userData);
  252. /*! \brief Register highlighter callback.
  253. *
  254. * \param fn - user defined callback function.
  255. * \param userData - pointer to opaque user data block to be passed into each invocation of the callback.
  256. */
  257. REPLXX_IMPEXP void replxx_set_highlighter_callback( Replxx*, replxx_highlighter_callback_t* fn, void* userData );
  258. typedef struct replxx_completions replxx_completions;
  259. /*! \brief Completions callback type definition.
  260. *
  261. * \e contextLen is counted in Unicode code points (not in bytes!).
  262. *
  263. * For user input:
  264. * if ( obj.me
  265. *
  266. * input == "if ( obj.me"
  267. * contextLen == 2 (depending on \e replxx_set_word_break_characters())
  268. *
  269. * Client application is free to update \e contextLen to be 6 (or any other non-negative
  270. * number not greater than the number of code points in input) if it makes better sense
  271. * for given client application semantics.
  272. *
  273. * \param input - UTF-8 encoded input entered by the user until current cursor position.
  274. * \param completions - pointer to opaque list of user completions.
  275. * \param contextLen[in,out] - length of the additional context to provide while displaying completions.
  276. * \param userData - pointer to opaque user data block.
  277. */
  278. typedef void(replxx_completion_callback_t)(const char* input, replxx_completions* completions, int* contextLen, void* userData);
  279. /*! \brief Register completion callback.
  280. *
  281. * \param fn - user defined callback function.
  282. * \param userData - pointer to opaque user data block to be passed into each invocation of the callback.
  283. */
  284. REPLXX_IMPEXP void replxx_set_completion_callback( Replxx*, replxx_completion_callback_t* fn, void* userData );
  285. /*! \brief Add another possible completion for current user input.
  286. *
  287. * \param completions - pointer to opaque list of user completions.
  288. * \param str - UTF-8 encoded completion string.
  289. */
  290. REPLXX_IMPEXP void replxx_add_completion( replxx_completions* completions, const char* str );
  291. /*! \brief Add another possible completion for current user input.
  292. *
  293. * \param completions - pointer to opaque list of user completions.
  294. * \param str - UTF-8 encoded completion string.
  295. * \param color - a color for the completion.
  296. */
  297. REPLXX_IMPEXP void replxx_add_color_completion( replxx_completions* completions, const char* str, ReplxxColor color );
  298. typedef struct replxx_hints replxx_hints;
  299. /*! \brief Hints callback type definition.
  300. *
  301. * \e contextLen is counted in Unicode code points (not in bytes!).
  302. *
  303. * For user input:
  304. * if ( obj.me
  305. *
  306. * input == "if ( obj.me"
  307. * contextLen == 2 (depending on \e replxx_set_word_break_characters())
  308. *
  309. * Client application is free to update \e contextLen to be 6 (or any other non-negative
  310. * number not greater than the number of code points in input) if it makes better sense
  311. * for given client application semantics.
  312. *
  313. * \param input - UTF-8 encoded input entered by the user until current cursor position.
  314. * \param hints - pointer to opaque list of possible hints.
  315. * \param contextLen[in,out] - length of the additional context to provide while displaying hints.
  316. * \param color - a color used for displaying hints.
  317. * \param userData - pointer to opaque user data block.
  318. */
  319. typedef void(replxx_hint_callback_t)(const char* input, replxx_hints* hints, int* contextLen, ReplxxColor* color, void* userData);
  320. /*! \brief Register hints callback.
  321. *
  322. * \param fn - user defined callback function.
  323. * \param userData - pointer to opaque user data block to be passed into each invocation of the callback.
  324. */
  325. REPLXX_IMPEXP void replxx_set_hint_callback( Replxx*, replxx_hint_callback_t* fn, void* userData );
  326. /*! \brief Key press handler type definition.
  327. *
  328. * \param code - the key code replxx got from terminal.
  329. * \return Decision on how should input() behave after this key handler returns.
  330. */
  331. typedef ReplxxActionResult (key_press_handler_t)( int code, void* userData );
  332. /*! \brief Add another possible hint for current user input.
  333. *
  334. * \param hints - pointer to opaque list of hints.
  335. * \param str - UTF-8 encoded hint string.
  336. */
  337. REPLXX_IMPEXP void replxx_add_hint( replxx_hints* hints, const char* str );
  338. /*! \brief Read line of user input.
  339. *
  340. * Returned pointer is managed by the library and is not to be freed in the client.
  341. *
  342. * \param prompt - prompt to be displayed before getting user input.
  343. * \return An UTF-8 encoded input given by the user (or nullptr on EOF).
  344. */
  345. REPLXX_IMPEXP char const* replxx_input( Replxx*, const char* prompt );
  346. /*! \brief Get current state data.
  347. *
  348. * This call is intended to be used in handlers.
  349. *
  350. * \param state - buffer for current state of the model.
  351. */
  352. REPLXX_IMPEXP void replxx_get_state( Replxx*, ReplxxState* state );
  353. /*! \brief Set new state data.
  354. *
  355. * This call is intended to be used in handlers.
  356. *
  357. * \param state - new state of the model.
  358. */
  359. REPLXX_IMPEXP void replxx_set_state( Replxx*, ReplxxState* state );
  360. /*! \brief Print formatted string to standard output.
  361. *
  362. * This function ensures proper handling of ANSI escape sequences
  363. * contained in printed data, which is especially useful on Windows
  364. * since Unixes handle them correctly out of the box.
  365. *
  366. * \param fmt - printf style format.
  367. */
  368. REPLXX_IMPEXP int replxx_print( Replxx*, char const* fmt, ... );
  369. /*! \brief Prints a char array with the given length to standard output.
  370. *
  371. * \copydetails print
  372. *
  373. * \param str - The char array to print.
  374. * \param length - The length of the array.
  375. */
  376. REPLXX_IMPEXP int replxx_write( Replxx*, char const* str, int length );
  377. /*! \brief Schedule an emulated key press event.
  378. *
  379. * \param code - key press code to be emulated.
  380. */
  381. REPLXX_IMPEXP void replxx_emulate_key_press( Replxx*, int unsigned code );
  382. /*! \brief Invoke built-in action handler.
  383. *
  384. * \pre This function can be called only from key-press handler.
  385. *
  386. * \param action - a built-in action to invoke.
  387. * \param code - a supplementary key-code to consume by built-in action handler.
  388. * \return The action result informing the replxx what shall happen next.
  389. */
  390. REPLXX_IMPEXP ReplxxActionResult replxx_invoke( Replxx*, ReplxxAction action, int unsigned code );
  391. /*! \brief Bind user defined action to handle given key-press event.
  392. *
  393. * \param code - handle this key-press event with following handler.
  394. * \param handler - use this handler to handle key-press event.
  395. * \param userData - supplementary user data passed to invoked handlers.
  396. */
  397. REPLXX_IMPEXP void replxx_bind_key( Replxx*, int code, key_press_handler_t handler, void* userData );
  398. /*! \brief Bind internal `replxx` action (by name) to handle given key-press event.
  399. *
  400. * Action names are the same as unique part of names of ReplxxAction enumerations
  401. * but in lower case, e.g.: an action for recalling previous history line
  402. * is \e REPLXX_ACTION_HISTORY_PREVIOUS so action name to be used in this
  403. * interface for the same effect is "history_previous".
  404. *
  405. * \param code - handle this key-press event with following handler.
  406. * \param actionName - name of internal action to be invoked on key press.
  407. * \return -1 if invalid action name was used, 0 otherwise.
  408. */
  409. int replxx_bind_key_internal( Replxx*, int code, char const* actionName );
  410. REPLXX_IMPEXP void replxx_set_preload_buffer( Replxx*, const char* preloadText );
  411. REPLXX_IMPEXP void replxx_history_add( Replxx*, const char* line );
  412. REPLXX_IMPEXP int replxx_history_size( Replxx* );
  413. /*! \brief Set set of word break characters.
  414. *
  415. * This setting influences word based cursor movement and line editing capabilities.
  416. *
  417. * \param wordBreakers - 7-bit ASCII set of word breaking characters.
  418. */
  419. REPLXX_IMPEXP void replxx_set_word_break_characters( Replxx*, char const* wordBreakers );
  420. /*! \brief How many completions should trigger pagination.
  421. */
  422. REPLXX_IMPEXP void replxx_set_completion_count_cutoff( Replxx*, int count );
  423. /*! \brief Set maximum number of displayed hint rows.
  424. */
  425. REPLXX_IMPEXP void replxx_set_max_hint_rows( Replxx*, int count );
  426. /*! \brief Set a delay before hint are shown after user stopped typing..
  427. *
  428. * \param milliseconds - a number of milliseconds to wait before showing hints.
  429. */
  430. REPLXX_IMPEXP void replxx_set_hint_delay( Replxx*, int milliseconds );
  431. /*! \brief Set tab completion behavior.
  432. *
  433. * \param val - use double tab to invoke completions (if != 0).
  434. */
  435. REPLXX_IMPEXP void replxx_set_double_tab_completion( Replxx*, int val );
  436. /*! \brief Set tab completion behavior.
  437. *
  438. * \param val - invoke completion even if user input is empty (if != 0).
  439. */
  440. REPLXX_IMPEXP void replxx_set_complete_on_empty( Replxx*, int val );
  441. /*! \brief Set tab completion behavior.
  442. *
  443. * \param val - beep if completion is ambiguous (if != 0).
  444. */
  445. REPLXX_IMPEXP void replxx_set_beep_on_ambiguous_completion( Replxx*, int val );
  446. /*! \brief Set complete next/complete previous behavior.
  447. *
  448. * COMPLETE_NEXT/COMPLETE_PREVIOUS actions have two modes of operations,
  449. * in case when a partial completion is possible complete only partial part (`false` setting)
  450. * or complete first proposed completion fully (`true` setting).
  451. * The default is to complete fully (a `true` setting - complete immediately).
  452. *
  453. * \param val - complete immediately.
  454. */
  455. REPLXX_IMPEXP void replxx_set_immediate_completion( Replxx*, int val );
  456. /*! \brief Set history duplicate entries behaviour.
  457. *
  458. * \param val - should history contain only unique entries?
  459. */
  460. REPLXX_IMPEXP void replxx_set_unique_history( Replxx*, int val );
  461. /*! \brief Disable output coloring.
  462. *
  463. * \param val - if set to non-zero disable output colors.
  464. */
  465. REPLXX_IMPEXP void replxx_set_no_color( Replxx*, int val );
  466. /*! \brief Set maximum number of entries in history list.
  467. */
  468. REPLXX_IMPEXP void replxx_set_max_history_size( Replxx*, int len );
  469. REPLXX_IMPEXP ReplxxHistoryScan* replxx_history_scan_start( Replxx* );
  470. REPLXX_IMPEXP void replxx_history_scan_stop( Replxx*, ReplxxHistoryScan* );
  471. REPLXX_IMPEXP int replxx_history_scan_next( Replxx*, ReplxxHistoryScan*, ReplxxHistoryEntry* );
  472. /*! \brief Synchronize REPL's history with given file.
  473. *
  474. * Synchronizing means loading existing history from given file,
  475. * merging it with current history sorted by timestamps,
  476. * saving merged version to given file,
  477. * keeping merged version as current REPL's history.
  478. *
  479. * This call is an equivalent of calling:
  480. * replxx_history_save( rx, "some-file" );
  481. * replxx_history_load( rx, "some-file" );
  482. *
  483. * \param filename - a path to the file with which REPL's current history should be synchronized.
  484. * \return 0 iff history file was successfully created, -1 otherwise.
  485. */
  486. REPLXX_IMPEXP int replxx_history_sync( Replxx*, const char* filename );
  487. /*! \brief Save REPL's history into given file.
  488. *
  489. * Saving means loading existing history from given file,
  490. * merging it with current history sorted by timestamps,
  491. * saving merged version to given file,
  492. * keeping original (NOT merged) version as current REPL's history.
  493. *
  494. * \param filename - a path to the file where REPL's history should be saved.
  495. * \return 0 iff history file was successfully created, -1 otherwise.
  496. */
  497. REPLXX_IMPEXP int replxx_history_save( Replxx*, const char* filename );
  498. /*! \brief Load REPL's history from given file.
  499. *
  500. * \param filename - a path to the file which contains REPL's history that should be loaded.
  501. * \return 0 iff history file was successfully opened, -1 otherwise.
  502. */
  503. REPLXX_IMPEXP int replxx_history_load( Replxx*, const char* filename );
  504. /*! \brief Clear REPL's in-memory history.
  505. */
  506. REPLXX_IMPEXP void replxx_history_clear( Replxx* );
  507. REPLXX_IMPEXP void replxx_clear_screen( Replxx* );
  508. #ifdef __REPLXX_DEBUG__
  509. void replxx_debug_dump_print_codes(void);
  510. #endif
  511. /* the following is extension to the original linenoise API */
  512. REPLXX_IMPEXP int replxx_install_window_change_handler( Replxx* );
  513. REPLXX_IMPEXP void replxx_enable_bracketed_paste( Replxx* );
  514. REPLXX_IMPEXP void replxx_disable_bracketed_paste( Replxx* );
  515. #ifdef __cplusplus
  516. }
  517. #endif
  518. #endif /* __REPLXX_H */