Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 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 | * ------------------------------------------------------------------------ |
| 7 | * |
| 8 | * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com> |
| 9 | * Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com> |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without |
| 14 | * modification, are permitted provided that the following conditions are |
| 15 | * met: |
| 16 | * |
| 17 | * * Redistributions of source code must retain the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer. |
| 19 | * |
| 20 | * * Redistributions in binary form must reproduce the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer in the |
| 22 | * documentation and/or other materials provided with the distribution. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 28 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 29 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #ifndef __LINENOISE_H |
| 38 | #define __LINENOISE_H |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | typedef struct linenoiseSessionIO |
| 45 | { |
| 46 | long fd_in; |
| 47 | long fd_out; |
| 48 | int (*read_char)(long fd_in, char *c); |
| 49 | int (*write)(long fd_out, const char *buf, size_t len); |
| 50 | int dumb_terminal; /* 1=dumb terminal. do not use escape sequences */ |
| 51 | } linenoiseSessionIO; |
| 52 | |
| 53 | typedef struct linenoiseSession linenoiseSession; |
| 54 | |
| 55 | typedef int (linenoiseCompletionCallback)(linenoiseSession *session, const char *, int pos); |
| 56 | int linenoiseSessionOpen(const linenoiseSessionIO *io, void *session_data, linenoiseSession **session); |
| 57 | void linenoiseSessionClose(linenoiseSession *session); |
| 58 | void *linenoiseSessionData(linenoiseSession *session); |
| 59 | void linenoiseSetCompletionCallback(linenoiseSession *session, linenoiseCompletionCallback *); |
| 60 | void linenoiseSetBuffer(linenoiseSession *session, const char *buf, int pos); |
| 61 | |
| 62 | char *linenoise(linenoiseSession *session, const char *prompt, char *buf, size_t size); |
| 63 | int linenoiseHistoryAdd(linenoiseSession *session, const char *line); |
| 64 | int linenoiseHistorySetMaxLen(linenoiseSession *session, int len); |
| 65 | int linenoiseHistorySave(linenoiseSession *session, const char *filename); |
| 66 | int linenoiseHistoryLoad(linenoiseSession *session, const char *filename); |
| 67 | void linenoiseClearScreen(linenoiseSession *session); |
| 68 | void linenoiseSetMultiLine(linenoiseSession *session, int ml); |
| 69 | void linenoiseSetDumbTerminal(linenoiseSession *session, int dumb); |
| 70 | int linenoiseGetMultiLine(linenoiseSession *session); |
| 71 | int linenoiseGetDumbTerminal(linenoiseSession *session); |
| 72 | int linenoiseSetRaw(linenoiseSession *session, int raw); |
| 73 | int linenoiseGetRaw(linenoiseSession *session); |
| 74 | |
| 75 | #ifdef __cplusplus |
| 76 | } |
| 77 | #endif |
| 78 | |
| 79 | #endif /* __LINENOISE_H */ |