1 /*
2 * vim: filetype=c:tabstop=4:ai:expandtab
3 * SPDX-License-Identifier: BSD-2-Clause
4 * scspell-id: 736ea385-f62a-11ec-9ef9-80ee73e9b8e7
5 *
6 * -------------------------------------------------------------------------
7 *
8 * linehistory.h
9 *
10 * linehistory is forked from linenoise; the original version
11 * is available from https://github.com/antirez/linenoise
12 *
13 * ------------------------------------------------------------------------
14 *
15 * Copyright (c) 2010-2014 Salvatore Sanfilippo <antirez@gmail.com>
16 * Copyright (c) 2010-2013 Pieter Noordhuis <pcnoordhuis@gmail.com>
17 * Copyright (c) 2020-2021 Jeffrey H. Johnson <trnsz@pobox.com>
18 * Copyright (c) 2021-2023 The DPS8M Development Team
19 *
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are
24 * met:
25 *
26 * * Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 *
29 * * Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *
45 * -------------------------------------------------------------------------
46 */
47
48 #ifndef _POSIX_C_SOURCE
49 # define _POSIX_C_SOURCE 200809L
50 #endif /* ifndef _POSIX_C_SOURCE */
51
52 #ifndef __LINENOISE_H
53 # define __LINENOISE_H
54
55 # if !defined ( __MINGW32__ ) && !defined ( CROSS_MINGW32 ) && !defined ( CROSS_MINGW64 ) && !defined ( __MINGW64__ ) && !defined ( _MSC_VER ) && !defined ( _MSC_BUILD )
56
57 # ifndef HAVE_LINEHISTORY
58 # define HAVE_LINEHISTORY
59 # endif /* ifndef HAVE_LINEHISTORY */
60
61 # include <stddef.h>
62 # include <signal.h> /* raise */
63
64 # ifdef LH_COMPLETION
65 typedef struct linenoiseCompletions
66 {
67 size_t len;
68 char **cvec;
69 } linenoiseCompletions;
70
71 typedef void (linenoiseCompletionCallback) (const char *,
72 linenoiseCompletions *);
73 void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
74 void linenoiseAddCompletion(linenoiseCompletions *, const char *);
75 # endif /* ifdef LH_COMPLETION */
76
77 # ifdef LH_HINTS
78 typedef void (linenoiseFreeHintsCallback) (void *);
79 typedef char *(linenoiseHintsCallback)(const char *, int *color, int *bold);
80 void linenoiseSetHintsCallback(linenoiseHintsCallback *);
81 void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
82 # endif /* ifdef LH_HINTS */
83
84 char *linenoise(const char *prompt);
85 void linenoiseFree(void *ptr);
86 int linenoiseHistoryAdd(const char *line);
87 int linenoiseHistorySetMaxLen(int len);
88 int linenoiseHistorySave(const char *filename);
89 int linenoiseHistoryLoad(const char *filename);
90 void linenoiseClearScreen(void);
91 void linenoiseSetMultiLine(int ml);
92 void linenoisePrintKeyCodes(void);
93 # ifdef LH_MASKMODE
94 void linenoiseMaskModeEnable(void);
95 void linenoiseMaskModeDisable(void);
96 # endif /* ifdef LH_MASKMODE */
97
98 # endif /* if !defined (__MINGW32__) && !defined (__MINGW64__) && !defined (CROSS_MINGW32) && !defined (CROSS_MINGW64) && !defined (_MSC_VER) && !defined (_MSC_BUILD) */
99
100 #endif /* if __LINENOISE_H */