replxx.hxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * Copyright (c) 2017-2018, Marcin Konarski (amok at codestation.org)
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Redis nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without
  16. * specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef HAVE_REPLXX_HXX_INCLUDED
  31. #define HAVE_REPLXX_HXX_INCLUDED 1
  32. #include <memory>
  33. #include <vector>
  34. #include <string>
  35. #include <functional>
  36. #include <iosfwd>
  37. /*
  38. * For use in Windows DLLs:
  39. *
  40. * If you are building replxx into a DLL,
  41. * unless you are using supplied CMake based build,
  42. * ensure that 'REPLXX_BUILDING_DLL' is defined when
  43. * building the DLL so that proper symbols are exported.
  44. */
  45. #if defined( _WIN32 ) && ! defined( REPLXX_STATIC )
  46. # ifdef REPLXX_BUILDING_DLL
  47. # define REPLXX_IMPEXP __declspec( dllexport )
  48. # else
  49. # define REPLXX_IMPEXP __declspec( dllimport )
  50. # endif
  51. #else
  52. # define REPLXX_IMPEXP /**/
  53. #endif
  54. #ifdef ERROR
  55. enum { ERROR_BB1CA97EC761FC37101737BA0AA2E7C5 = ERROR };
  56. #undef ERROR
  57. enum { ERROR = ERROR_BB1CA97EC761FC37101737BA0AA2E7C5 };
  58. #endif
  59. #ifdef ABORT
  60. enum { ABORT_8D12A2CA7E5A64036D7251A3EDA51A38 = ABORT };
  61. #undef ABORT
  62. enum { ABORT = ABORT_8D12A2CA7E5A64036D7251A3EDA51A38 };
  63. #endif
  64. #ifdef DELETE
  65. enum { DELETE_32F68A60CEF40FAEDBC6AF20298C1A1E = DELETE };
  66. #undef DELETE
  67. enum { DELETE = DELETE_32F68A60CEF40FAEDBC6AF20298C1A1E };
  68. #endif
  69. namespace replxx {
  70. class REPLXX_IMPEXP Replxx {
  71. public:
  72. enum class Color : int {
  73. BLACK = 0,
  74. RED = 1,
  75. GREEN = 2,
  76. BROWN = 3,
  77. BLUE = 4,
  78. MAGENTA = 5,
  79. CYAN = 6,
  80. LIGHTGRAY = 7,
  81. GRAY = 8,
  82. BRIGHTRED = 9,
  83. BRIGHTGREEN = 10,
  84. YELLOW = 11,
  85. BRIGHTBLUE = 12,
  86. BRIGHTMAGENTA = 13,
  87. BRIGHTCYAN = 14,
  88. WHITE = 15,
  89. DEFAULT = 1u << 16u
  90. };
  91. struct KEY {
  92. static char32_t const BASE = 0x0010ffff + 1;
  93. static char32_t const BASE_SHIFT = 0x01000000;
  94. static char32_t const BASE_CONTROL = 0x02000000;
  95. static char32_t const BASE_META = 0x04000000;
  96. static char32_t const ESCAPE = 27;
  97. static char32_t const PAGE_UP = BASE + 1;
  98. static char32_t const PAGE_DOWN = PAGE_UP + 1;
  99. static char32_t const DOWN = PAGE_DOWN + 1;
  100. static char32_t const UP = DOWN + 1;
  101. static char32_t const LEFT = UP + 1;
  102. static char32_t const RIGHT = LEFT + 1;
  103. static char32_t const HOME = RIGHT + 1;
  104. static char32_t const END = HOME + 1;
  105. static char32_t const DELETE = END + 1;
  106. static char32_t const INSERT = DELETE + 1;
  107. static char32_t const F1 = INSERT + 1;
  108. static char32_t const F2 = F1 + 1;
  109. static char32_t const F3 = F2 + 1;
  110. static char32_t const F4 = F3 + 1;
  111. static char32_t const F5 = F4 + 1;
  112. static char32_t const F6 = F5 + 1;
  113. static char32_t const F7 = F6 + 1;
  114. static char32_t const F8 = F7 + 1;
  115. static char32_t const F9 = F8 + 1;
  116. static char32_t const F10 = F9 + 1;
  117. static char32_t const F11 = F10 + 1;
  118. static char32_t const F12 = F11 + 1;
  119. static char32_t const F13 = F12 + 1;
  120. static char32_t const F14 = F13 + 1;
  121. static char32_t const F15 = F14 + 1;
  122. static char32_t const F16 = F15 + 1;
  123. static char32_t const F17 = F16 + 1;
  124. static char32_t const F18 = F17 + 1;
  125. static char32_t const F19 = F18 + 1;
  126. static char32_t const F20 = F19 + 1;
  127. static char32_t const F21 = F20 + 1;
  128. static char32_t const F22 = F21 + 1;
  129. static char32_t const F23 = F22 + 1;
  130. static char32_t const F24 = F23 + 1;
  131. static char32_t const MOUSE = F24 + 1;
  132. static char32_t const PASTE_START = MOUSE + 1;
  133. static char32_t const PASTE_FINISH = PASTE_START + 1;
  134. static constexpr char32_t shift( char32_t key_ ) {
  135. return ( key_ | BASE_SHIFT );
  136. }
  137. static constexpr char32_t control( char32_t key_ ) {
  138. return ( key_ | BASE_CONTROL );
  139. }
  140. static constexpr char32_t meta( char32_t key_ ) {
  141. return ( key_ | BASE_META );
  142. }
  143. static char32_t const BACKSPACE = 'H' | BASE_CONTROL;
  144. static char32_t const TAB = 'I' | BASE_CONTROL;
  145. static char32_t const ENTER = 'M' | BASE_CONTROL;
  146. static char32_t const ABORT = 'C' | BASE_CONTROL | BASE_META;
  147. };
  148. /*! \brief List of built-in actions that act upon user input.
  149. */
  150. enum class ACTION {
  151. INSERT_CHARACTER,
  152. NEW_LINE,
  153. DELETE_CHARACTER_UNDER_CURSOR,
  154. DELETE_CHARACTER_LEFT_OF_CURSOR,
  155. KILL_TO_END_OF_LINE,
  156. KILL_TO_BEGINING_OF_LINE,
  157. KILL_TO_END_OF_WORD,
  158. KILL_TO_BEGINING_OF_WORD,
  159. KILL_TO_END_OF_SUBWORD,
  160. KILL_TO_BEGINING_OF_SUBWORD,
  161. KILL_TO_WHITESPACE_ON_LEFT,
  162. YANK,
  163. YANK_CYCLE,
  164. YANK_LAST_ARG,
  165. MOVE_CURSOR_TO_BEGINING_OF_LINE,
  166. MOVE_CURSOR_TO_END_OF_LINE,
  167. MOVE_CURSOR_ONE_WORD_LEFT,
  168. MOVE_CURSOR_ONE_WORD_RIGHT,
  169. MOVE_CURSOR_ONE_SUBWORD_LEFT,
  170. MOVE_CURSOR_ONE_SUBWORD_RIGHT,
  171. MOVE_CURSOR_LEFT,
  172. MOVE_CURSOR_RIGHT,
  173. LINE_NEXT,
  174. LINE_PREVIOUS,
  175. HISTORY_NEXT,
  176. HISTORY_PREVIOUS,
  177. HISTORY_FIRST,
  178. HISTORY_LAST,
  179. HISTORY_RESTORE,
  180. HISTORY_RESTORE_CURRENT,
  181. HISTORY_INCREMENTAL_SEARCH,
  182. HISTORY_COMMON_PREFIX_SEARCH,
  183. HINT_NEXT,
  184. HINT_PREVIOUS,
  185. CAPITALIZE_WORD,
  186. LOWERCASE_WORD,
  187. UPPERCASE_WORD,
  188. CAPITALIZE_SUBWORD,
  189. LOWERCASE_SUBWORD,
  190. UPPERCASE_SUBWORD,
  191. TRANSPOSE_CHARACTERS,
  192. TOGGLE_OVERWRITE_MODE,
  193. #ifndef _WIN32
  194. VERBATIM_INSERT,
  195. SUSPEND,
  196. #endif
  197. BRACKETED_PASTE,
  198. CLEAR_SCREEN,
  199. CLEAR_SELF,
  200. REPAINT,
  201. COMPLETE_LINE,
  202. COMPLETE_NEXT,
  203. COMPLETE_PREVIOUS,
  204. COMMIT_LINE,
  205. ABORT_LINE,
  206. SEND_EOF
  207. };
  208. /*! \brief Possible results of key-press handler actions.
  209. */
  210. enum class ACTION_RESULT {
  211. CONTINUE, /*!< Continue processing user input. */
  212. RETURN, /*!< Return user input entered so far. */
  213. BAIL /*!< Stop processing user input, returns nullptr from the \e input() call. */
  214. };
  215. typedef std::vector<Color> colors_t;
  216. class Completion {
  217. std::string _text;
  218. Color _color;
  219. public:
  220. Completion( char const* text_ )
  221. : _text( text_ )
  222. , _color( Color::DEFAULT ) {
  223. }
  224. Completion( std::string const& text_ )
  225. : _text( text_ )
  226. , _color( Color::DEFAULT ) {
  227. }
  228. Completion( std::string const& text_, Color color_ )
  229. : _text( text_ )
  230. , _color( color_ ) {
  231. }
  232. std::string const& text( void ) const {
  233. return ( _text );
  234. }
  235. Color color( void ) const {
  236. return ( _color );
  237. }
  238. };
  239. typedef std::vector<Completion> completions_t;
  240. class HistoryEntry {
  241. std::string _timestamp;
  242. std::string _text;
  243. public:
  244. HistoryEntry( std::string const& timestamp_, std::string const& text_ )
  245. : _timestamp( timestamp_ )
  246. , _text( text_ ) {
  247. }
  248. std::string const& timestamp( void ) const {
  249. return ( _timestamp );
  250. }
  251. std::string const& text( void ) const {
  252. return ( _text );
  253. }
  254. };
  255. class HistoryScanImpl;
  256. class HistoryScan {
  257. public:
  258. typedef std::unique_ptr<HistoryScanImpl, void (*)( HistoryScanImpl* )> impl_t;
  259. private:
  260. #ifdef _MSC_VER
  261. #pragma warning(push)
  262. #pragma warning(disable:4251)
  263. #endif
  264. impl_t _impl;
  265. #ifdef _MSC_VER
  266. #pragma warning(pop)
  267. #endif
  268. public:
  269. HistoryScan( impl_t );
  270. HistoryScan( HistoryScan&& ) = default;
  271. HistoryScan& operator = ( HistoryScan&& ) = default;
  272. bool next( void );
  273. HistoryEntry const& get( void ) const;
  274. private:
  275. HistoryScan( HistoryScan const& ) = delete;
  276. HistoryScan& operator = ( HistoryScan const& ) = delete;
  277. };
  278. typedef std::vector<std::string> hints_t;
  279. /*! \brief Line modification callback type definition.
  280. *
  281. * User can observe and modify line contents (and cursor position)
  282. * in response to changes to both introduced by the user through
  283. * normal interactions.
  284. *
  285. * When callback returns Replxx updates current line content
  286. * and current cursor position to the ones updated by the callback.
  287. *
  288. * \param line[in,out] - a R/W reference to an UTF-8 encoded input entered by the user so far.
  289. * \param cursorPosition[in,out] - a R/W reference to current cursor position.
  290. */
  291. typedef std::function<void ( std::string& line, int& cursorPosition )> modify_callback_t;
  292. /*! \brief Completions callback type definition.
  293. *
  294. * \e contextLen is counted in Unicode code points (not in bytes!).
  295. *
  296. * For user input:
  297. * if ( obj.me
  298. *
  299. * input == "if ( obj.me"
  300. * contextLen == 2 (depending on \e set_word_break_characters())
  301. *
  302. * Client application is free to update \e contextLen to be 6 (or any other non-negative
  303. * number not greater than the number of code points in input) if it makes better sense
  304. * for given client application semantics.
  305. *
  306. * \param input - UTF-8 encoded input entered by the user until current cursor position.
  307. * \param[in,out] contextLen - length of the additional context to provide while displaying completions.
  308. * \return A list of user completions.
  309. */
  310. typedef std::function<completions_t ( std::string const& input, int& contextLen )> completion_callback_t;
  311. /*! \brief Highlighter callback type definition.
  312. *
  313. * If user want to have colorful input she must simply install highlighter callback.
  314. * The callback would be invoked by the library after each change to the input done by
  315. * the user. After callback returns library uses data from colors buffer to colorize
  316. * displayed user input.
  317. *
  318. * Size of \e colors buffer is equal to number of code points in user \e input
  319. * which will be different from simple `input.length()`!
  320. *
  321. * \param input - an UTF-8 encoded input entered by the user so far.
  322. * \param colors - output buffer for color information.
  323. */
  324. typedef std::function<void ( std::string const& input, colors_t& colors )> highlighter_callback_t;
  325. /*! \brief Hints callback type definition.
  326. *
  327. * \e contextLen is counted in Unicode code points (not in bytes!).
  328. *
  329. * For user input:
  330. * if ( obj.me
  331. *
  332. * input == "if ( obj.me"
  333. * contextLen == 2 (depending on \e set_word_break_characters())
  334. *
  335. * Client application is free to update \e contextLen to be 6 (or any other non-negative
  336. * number not greater than the number of code points in input) if it makes better sense
  337. * for given client application semantics.
  338. *
  339. * \param input - UTF-8 encoded input entered by the user until current cursor position.
  340. * \param contextLen[in,out] - length of the additional context to provide while displaying hints.
  341. * \param color - a color used for displaying hints.
  342. * \return A list of possible hints.
  343. */
  344. typedef std::function<hints_t ( std::string const& input, int& contextLen, Color& color )> hint_callback_t;
  345. /*! \brief Key press handler type definition.
  346. *
  347. * \param code - the key code replxx got from terminal.
  348. * \return Decision on how should input() behave after this key handler returns.
  349. */
  350. typedef std::function<ACTION_RESULT ( char32_t code )> key_press_handler_t;
  351. struct State {
  352. char const* _text;
  353. int _cursorPosition;
  354. State( char const* text_, int cursorPosition_ = -1 )
  355. : _text( text_ )
  356. , _cursorPosition( cursorPosition_ ) {
  357. }
  358. State( State const& ) = default;
  359. State& operator = ( State const& ) = default;
  360. char const* text( void ) const {
  361. return ( _text );
  362. }
  363. int cursor_position( void ) const {
  364. return ( _cursorPosition );
  365. }
  366. };
  367. class ReplxxImpl;
  368. private:
  369. typedef std::unique_ptr<ReplxxImpl, void (*)( ReplxxImpl* )> impl_t;
  370. #ifdef _MSC_VER
  371. #pragma warning(push)
  372. #pragma warning(disable:4251)
  373. #endif
  374. impl_t _impl;
  375. #ifdef _MSC_VER
  376. #pragma warning(pop)
  377. #endif
  378. public:
  379. Replxx( void );
  380. Replxx( Replxx&& ) = default;
  381. Replxx& operator = ( Replxx&& ) = default;
  382. /*! \brief Register modify callback.
  383. *
  384. * \param fn - user defined callback function.
  385. */
  386. void set_modify_callback( modify_callback_t const& fn );
  387. /*! \brief Register completion callback.
  388. *
  389. * \param fn - user defined callback function.
  390. */
  391. void set_completion_callback( completion_callback_t const& fn );
  392. /*! \brief Register highlighter callback.
  393. *
  394. * \param fn - user defined callback function.
  395. */
  396. void set_highlighter_callback( highlighter_callback_t const& fn );
  397. /*! \brief Register hints callback.
  398. *
  399. * \param fn - user defined callback function.
  400. */
  401. void set_hint_callback( hint_callback_t const& fn );
  402. /*! \brief Read line of user input.
  403. *
  404. * Returned pointer is managed by the library and is not to be freed in the client.
  405. *
  406. * \param prompt - prompt to be displayed before getting user input.
  407. * \return An UTF-8 encoded input given by the user (or nullptr on EOF).
  408. */
  409. char const* input( std::string const& prompt );
  410. /*! \brief Get current state data.
  411. *
  412. * This call is intended to be used in handlers.
  413. *
  414. * \return Current state of the model.
  415. */
  416. State get_state( void ) const;
  417. /*! \brief Set new state data.
  418. *
  419. * This call is intended to be used in handlers.
  420. *
  421. * \param state - new state of the model.
  422. */
  423. void set_state( State const& state );
  424. /*! \brief Enable/disable case insensitive history search and completion.
  425. *
  426. * \param val - if set to non-zero then history search and completion will be case insensitive.
  427. */
  428. void set_ignore_case( bool val );
  429. /*! \brief Print formatted string to standard output.
  430. *
  431. * This function ensures proper handling of ANSI escape sequences
  432. * contained in printed data, which is especially useful on Windows
  433. * since Unixes handle them correctly out of the box.
  434. *
  435. * \param fmt - printf style format.
  436. */
  437. void print( char const* fmt, ... );
  438. /*! \brief Prints a char array with the given length to standard output.
  439. *
  440. * \copydetails print
  441. *
  442. * \param str - The char array to print.
  443. * \param length - The length of the array.
  444. */
  445. void write( char const* str, int length );
  446. /*! \brief Asynchronously change the prompt while replxx_input() call is in efect.
  447. *
  448. * Can be used to change the prompt from callbacks or other threads.
  449. *
  450. * \param prompt - The prompt string to change to.
  451. */
  452. void set_prompt( std::string prompt );
  453. /*! \brief Schedule an emulated key press event.
  454. *
  455. * \param code - key press code to be emulated.
  456. */
  457. void emulate_key_press( char32_t code );
  458. /*! \brief Invoke built-in action handler.
  459. *
  460. * \pre This method can be called only from key-press handler.
  461. *
  462. * \param action - a built-in action to invoke.
  463. * \param code - a supplementary key-code to consume by built-in action handler.
  464. * \return The action result informing the replxx what shall happen next.
  465. */
  466. ACTION_RESULT invoke( ACTION action, char32_t code );
  467. /*! \brief Bind user defined action to handle given key-press event.
  468. *
  469. * \param code - handle this key-press event with following handler.
  470. * \param handle - use this handler to handle key-press event.
  471. */
  472. void bind_key( char32_t code, key_press_handler_t handler );
  473. /*! \brief Bind internal `replxx` action (by name) to handle given key-press event.
  474. *
  475. * Action names are the same as names of Replxx::ACTION enumerations
  476. * but in lower case, e.g.: an action for recalling previous history line
  477. * is \e Replxx::ACTION::LINE_PREVIOUS so action name to be used in this
  478. * interface for the same effect is "line_previous".
  479. *
  480. * \param code - handle this key-press event with following handler.
  481. * \param actionName - name of internal action to be invoked on key press.
  482. */
  483. void bind_key_internal( char32_t code, char const* actionName );
  484. void history_add( std::string const& line );
  485. /*! \brief Synchronize REPL's history with given file.
  486. *
  487. * Synchronizing means loading existing history from given file,
  488. * merging it with current history sorted by timestamps,
  489. * saving merged version to given file,
  490. * keeping merged version as current REPL's history.
  491. *
  492. * This call is an equivalent of calling:
  493. * history_save( "some-file" );
  494. * history_load( "some-file" );
  495. *
  496. * \param filename - a path to the file with which REPL's current history should be synchronized.
  497. * \return True iff history file was successfully created.
  498. */
  499. bool history_sync( std::string const& filename );
  500. /*! \brief Save REPL's history into given file.
  501. *
  502. * Saving means loading existing history from given file,
  503. * merging it with current history sorted by timestamps,
  504. * saving merged version to given file,
  505. * keeping original (NOT merged) version as current REPL's history.
  506. *
  507. * \param filename - a path to the file where REPL's history should be saved.
  508. * \return True iff history file was successfully created.
  509. */
  510. bool history_save( std::string const& filename );
  511. /*!
  512. * \copydoc history_save
  513. */
  514. void history_save( std::ostream& out );
  515. /*! \brief Load REPL's history from given file.
  516. *
  517. * \param filename - a path to the file which contains REPL's history that should be loaded.
  518. * \return True iff history file was successfully opened.
  519. */
  520. bool history_load( std::string const& filename );
  521. /*!
  522. * \copydoc history_load
  523. */
  524. void history_load( std::istream& in );
  525. /*! \brief Clear REPL's in-memory history.
  526. */
  527. void history_clear( void );
  528. int history_size( void ) const;
  529. HistoryScan history_scan( void ) const;
  530. void set_preload_buffer( std::string const& preloadText );
  531. /*! \brief Set set of word break characters.
  532. *
  533. * This setting influences word based cursor movement and line editing capabilities.
  534. *
  535. * \param wordBreakers - 7-bit ASCII set of word breaking characters.
  536. */
  537. void set_word_break_characters( char const* wordBreakers );
  538. /*! \brief How many completions should trigger pagination.
  539. */
  540. void set_completion_count_cutoff( int count );
  541. /*! \brief Set maximum number of displayed hint rows.
  542. */
  543. void set_max_hint_rows( int count );
  544. /*! \brief Set a delay before hint are shown after user stopped typing..
  545. *
  546. * \param milliseconds - a number of milliseconds to wait before showing hints.
  547. */
  548. void set_hint_delay( int milliseconds );
  549. /*! \brief Set tab completion behavior.
  550. *
  551. * \param val - use double tab to invoke completions.
  552. */
  553. void set_double_tab_completion( bool val );
  554. /*! \brief Set tab completion behavior.
  555. *
  556. * \param val - invoke completion even if user input is empty.
  557. */
  558. void set_complete_on_empty( bool val );
  559. /*! \brief Set tab completion behavior.
  560. *
  561. * \param val - beep if completion is ambiguous.
  562. */
  563. void set_beep_on_ambiguous_completion( bool val );
  564. /*! \brief Set complete next/complete previous behavior.
  565. *
  566. * COMPLETE_NEXT/COMPLETE_PREVIOUS actions have two modes of operations,
  567. * in case when a partial completion is possible complete only partial part (`false` setting)
  568. * or complete first proposed completion fully (`true` setting).
  569. * The default is to complete fully (a `true` setting - complete immediately).
  570. *
  571. * \param val - complete immediately.
  572. */
  573. void set_immediate_completion( bool val );
  574. /*! \brief Set history duplicate entries behaviour.
  575. *
  576. * \param val - should history contain only unique entries?
  577. */
  578. void set_unique_history( bool val );
  579. /*! \brief Disable output coloring.
  580. *
  581. * \param val - if set to non-zero disable output colors.
  582. */
  583. void set_no_color( bool val );
  584. /*! \brief Enable/disable (prompt width) indent for multiline entry.
  585. *
  586. * \param val - if set to true then multiline indent will be enabled.
  587. */
  588. void set_indent_multiline( bool val );
  589. /*! \brief Set maximum number of entries in history list.
  590. */
  591. void set_max_history_size( int len );
  592. void clear_screen( void );
  593. int install_window_change_handler( void );
  594. void enable_bracketed_paste( void );
  595. void disable_bracketed_paste( void );
  596. private:
  597. Replxx( Replxx const& ) = delete;
  598. Replxx& operator = ( Replxx const& ) = delete;
  599. };
  600. /*! \brief Color definition related helper function.
  601. *
  602. * To be used to leverage 256 color terminal capabilities.
  603. */
  604. namespace color {
  605. /*! \brief Combine two color definitions to get encompassing color definition.
  606. *
  607. * To be used only for combining foreground and background colors.
  608. *
  609. * \param color1 - first input color.
  610. * \param color2 - second input color.
  611. * \return A new color definition that represent combined input colors.
  612. */
  613. Replxx::Color operator | ( Replxx::Color color1, Replxx::Color color2 );
  614. /*! \brief Transform foreground color definition into a background color definition.
  615. *
  616. * \param color - an input foreground color definition.
  617. * \return A background color definition that is a transformed input \e color.
  618. */
  619. Replxx::Color bg( Replxx::Color color );
  620. /*! \brief Add `bold` attribute to color definition.
  621. *
  622. * \param color - an input color definition.
  623. * \return A new color definition with bold attribute set.
  624. */
  625. Replxx::Color bold( Replxx::Color color );
  626. /*! \brief Add `underline` attribute to color definition.
  627. *
  628. * \param color - an input color definition.
  629. * \return A new color definition with underline attribute set.
  630. */
  631. Replxx::Color underline( Replxx::Color color );
  632. /*! \brief Create a new grayscale color of given brightness level.
  633. *
  634. * \param level - a brightness level for new color, must be between 0 (darkest) and 23 (brightest).
  635. * \return A new grayscale color of a given brightest \e level.
  636. */
  637. Replxx::Color grayscale( int level );
  638. /*! \brief Create a new color in 6×6×6 RGB color space from base component levels.
  639. *
  640. * \param red - a red (of RGB) component level, must be 0 and 5.
  641. * \param green - a green (of RGB) component level, must be 0 and 5.
  642. * \param blue - a blue (of RGB) component level, must be 0 and 5.
  643. * \return A new color in 6×6×6 RGB color space.
  644. */
  645. Replxx::Color rgb666( int red, int green, int blue );
  646. }
  647. }
  648. #endif /* HAVE_REPLXX_HXX_INCLUDED */