00001 /* 00002 * $Id: linenoise.h,v 1.3 2020/05/22 05:53:27 johns Exp $ 00003 * 00004 * Modified linenoise from the standard distribution by adding 00005 * user context parameters for each of the callbacks, so that 00006 * the caller can pass in runtime-generated lists of command 00007 * completion strings without the use of global variables or 00008 * other undesirable methods. 00009 * 00010 * Further modifications were made to the linenoise Unix TTY handling code 00011 * to allow VMD to control TTY buffer flushes when switching between raw and 00012 * cooked TTY mode. This is required so that VMD can switch to raw mode 00013 * for character-at-a-time input, so that linenoise doesn't have 00014 * blocking behavior that prevents the VMD main loop from free-running. 00015 * With these changes, VMD free runs except when in actual command editing. 00016 * Correct handling of VMD console output is made more complex by entry 00017 * and return from raw TTY mode, but it is a much more usable scenario 00018 * for the end user. 00019 */ 00020 00021 /* linenoise.h -- VERSION 1.0 00022 * 00023 * Guerrilla line editing library against the idea that a line editing lib 00024 * needs to be 20,000 lines of C code. 00025 * 00026 * See linenoise.c for more information. 00027 * 00028 * ------------------------------------------------------------------------ 00029 * 00030 * Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com> 00031 * Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com> 00032 * 00033 * All rights reserved. 00034 * 00035 * Redistribution and use in source and binary forms, with or without 00036 * modification, are permitted provided that the following conditions are 00037 * met: 00038 * 00039 * * Redistributions of source code must retain the above copyright 00040 * notice, this list of conditions and the following disclaimer. 00041 * 00042 * * Redistributions in binary form must reproduce the above copyright 00043 * notice, this list of conditions and the following disclaimer in the 00044 * documentation and/or other materials provided with the distribution. 00045 * 00046 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00047 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00048 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00049 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00050 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00051 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00052 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00053 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00054 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00055 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00056 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00057 */ 00058 00059 #ifndef __LINENOISE_H 00060 #define __LINENOISE_H 00061 00062 #ifdef __cplusplus 00063 extern "C" { 00064 #endif 00065 00066 typedef struct linenoiseCompletions { 00067 size_t len; 00068 char **cvec; 00069 } linenoiseCompletions; 00070 00071 typedef void(linenoiseCompletionCallback)(void *, const char *, linenoiseCompletions *); 00072 typedef char*(linenoiseHintsCallback)(void *, const char *, int *color, int *bold); 00073 typedef void(linenoiseFreeHintsCallback)(void *, void *); 00074 void linenoiseSetCompletionCallback(void *, linenoiseCompletionCallback *); 00075 void linenoiseSetHintsCallback(void *, linenoiseHintsCallback *); 00076 void linenoiseSetFreeHintsCallback(void *, linenoiseFreeHintsCallback *); 00077 void linenoiseAddCompletion(linenoiseCompletions *, const char *); 00078 00079 char *linenoise(const char *prompt); 00080 void linenoiseFree(void *ptr); 00081 int linenoiseHistoryAdd(const char *line); 00082 int linenoiseHistorySetMaxLen(int len); 00083 int linenoiseHistorySave(const char *filename); 00084 int linenoiseHistoryLoad(const char *filename); 00085 void linenoiseClearScreen(void); 00086 void linenoiseSetMultiLine(int ml); 00087 void linenoisePrintKeyCodes(void); 00088 void linenoiseMaskModeEnable(void); 00089 void linenoiseMaskModeDisable(void); 00090 00091 int enableRawMode(int fd, int flush); 00092 void disableRawMode(int fd, int flush); 00093 00094 #ifdef __cplusplus 00095 } 00096 #endif 00097 00098 #endif /* __LINENOISE_H */