/* linenoise.h -- guerrilla line editing library against the idea that a1* line editing lib needs to be 20,000 lines of C code.2*3* See linenoise.c for more information.4*5* ------------------------------------------------------------------------6*7* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>8* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>9*10* All rights reserved.11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions are14* met:15*16* * Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18*19* * Redistributions in binary form must reproduce the above copyright20* notice, this list of conditions and the following disclaimer in the21* documentation and/or other materials provided with the distribution.22*23* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS24* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT25* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR26* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT27* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,28* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT29* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,30* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY31* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT32* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE33* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34*/3536#ifndef __LINENOISE_H37#define __LINENOISE_H3839#ifdef __cplusplus40extern "C" {41#endif4243#ifndef NO_COMPLETION44typedef struct linenoiseCompletions {45size_t len;46char **cvec;47} linenoiseCompletions;4849/*50* The callback type for tab completion handlers.51*/52typedef void(linenoiseCompletionCallback)(const char *prefix, linenoiseCompletions *comp, void *userdata);5354/*55* Sets the current tab completion handler and returns the previous one, or NULL56* if no prior one has been set.57*/58linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *comp, void *userdata);5960/*61* Adds a copy of the given string to the given completion list. The copy is owned62* by the linenoiseCompletions object.63*/64void linenoiseAddCompletion(linenoiseCompletions *comp, const char *str);6566typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold, void *userdata);67typedef void(linenoiseFreeHintsCallback)(void *hint, void *userdata);68void linenoiseSetHintsCallback(linenoiseHintsCallback *callback, void *userdata);69void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *callback);7071#endif7273/*74* Prompts for input using the given string as the input75* prompt. Returns when the user has tapped ENTER or (on an empty76* line) EOF (Ctrl-D on Unix, Ctrl-Z on Windows). Returns either77* a copy of the entered string (for ENTER) or NULL (on EOF). The78* caller owns the returned string and must eventually free() it.79*/80char *linenoise(const char *prompt);8182/**83* Like linenoise() but starts with an initial buffer.84*/85char *linenoiseWithInitial(const char *prompt, const char *initial);8687/**88* Clear the screen.89*/90void linenoiseClearScreen(void);9192/*93* Adds a copy of the given line of the command history.94*/95int linenoiseHistoryAdd(const char *line);9697/*98* Sets the maximum length of the command history, in lines.99* If the history is currently longer, it will be trimmed,100* retaining only the most recent entries. If len is 0 or less101* then this function does nothing.102*/103int linenoiseHistorySetMaxLen(int len);104105/*106* Returns the current maximum length of the history, in lines.107*/108int linenoiseHistoryGetMaxLen(void);109110/*111* Saves the current contents of the history to the given file.112* Returns 0 on success.113*/114int linenoiseHistorySave(const char *filename);115116/*117* Replaces the current history with the contents118* of the given file. Returns 0 on success.119*/120int linenoiseHistoryLoad(const char *filename);121122/*123* Frees all history entries, clearing the history.124*/125void linenoiseHistoryFree(void);126127/*128* Returns a pointer to the list of history entries, writing its129* length to *len if len is not NULL. The memory is owned by linenoise130* and must not be freed.131*/132char **linenoiseHistory(int *len);133134/*135* Returns the number of display columns in the current terminal.136*/137int linenoiseColumns(void);138139/**140* Enable or disable multiline mode (disabled by default)141*/142void linenoiseSetMultiLine(int enableml);143144#ifdef __cplusplus145}146#endif147148#endif /* __LINENOISE_H */149150151