Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 1 | /* linenoise.h -- VERSION 1.0 |
| 2 | * |
| 3 | * Guerrilla line editing library against the idea that a line editing lib |
| 4 | * needs to be 20,000 lines of C code. |
| 5 | * |
| 6 | * See linenoise.c for more information. |
| 7 | * |
| 8 | * ------------------------------------------------------------------------ |
| 9 | * |
| 10 | * Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com> |
| 11 | * Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com> |
| 12 | * |
| 13 | * All rights reserved. |
| 14 | * |
| 15 | * Redistribution and use in source and binary forms, with or without |
| 16 | * modification, are permitted provided that the following conditions are |
| 17 | * met: |
| 18 | * |
| 19 | * * Redistributions of source code must retain the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer. |
| 21 | * |
| 22 | * * Redistributions in binary form must reproduce the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer in the |
| 24 | * documentation and/or other materials provided with the distribution. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 31 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | */ |
| 38 | |
| 39 | #ifndef __LINENOISE_H |
| 40 | #define __LINENOISE_H |
| 41 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 42 | #include <stddef.h> |
| 43 | |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | struct linenoiseState { |
| 49 | int ifd; /* Terminal stdin file descriptor. */ |
| 50 | int ofd; /* Terminal stdout file descriptor. */ |
| 51 | char *buf; /* Edited line buffer. */ |
| 52 | size_t buflen; /* Edited line buffer size. */ |
| 53 | const char *prompt; /* Prompt to display. */ |
| 54 | size_t plen; /* Prompt length. */ |
| 55 | size_t pos; /* Current cursor position. */ |
| 56 | size_t oldpos; /* Previous refresh cursor position. */ |
| 57 | size_t len; /* Current edited line length. */ |
| 58 | size_t cols; /* Number of columns in terminal. */ |
| 59 | size_t maxrows; /* Maximum num of rows used so far (multiline mode) */ |
| 60 | int rawmode; |
| 61 | int history_index; /* The history index we are currently editing. */ |
| 62 | }; |
| 63 | |
| 64 | extern struct linenoiseState ls; |
| 65 | |
| 66 | typedef struct linenoiseCompletions { |
| 67 | int path; |
| 68 | size_t len; |
| 69 | char **cvec; |
| 70 | } linenoiseCompletions; |
| 71 | |
| 72 | typedef void(linenoiseCompletionCallback)(const char *, const char *, linenoiseCompletions *); |
| 73 | void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); |
| 74 | void linenoiseAddCompletion(linenoiseCompletions *, const char *); |
| 75 | |
| 76 | char *linenoise(const char *prompt); |
| 77 | int linenoiseHistoryAdd(const char *line); |
| 78 | int linenoiseHistorySetMaxLen(int len); |
| 79 | int linenoiseHistorySave(const char *filename); |
| 80 | int linenoiseHistoryLoad(const char *filename); |
| 81 | void linenoiseClearScreen(void); |
| 82 | void linenoiseSetMultiLine(int ml); |
| 83 | void linenoisePrintKeyCodes(void); |
| 84 | |
| 85 | void linenoisePathCompletion(const char *, const char *, linenoiseCompletions *); |
| 86 | void linenoiseRefreshLine(void); |
| 87 | int linenoiseEnableRawMode(int fd); |
| 88 | void linenoiseDisableRawMode(int fd); |
| 89 | |
| 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | #endif /* __LINENOISE_H */ |