tcltest: do a better job of cleanup up after tests
[jimtcl.git] / linenoise.h
blobba1b041eae45484911e16aa7e53084ad72cf5fef
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.
4 * See linenoise.c for more information.
6 * ------------------------------------------------------------------------
8 * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
9 * Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
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.
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.
37 #ifndef __LINENOISE_H
38 #define __LINENOISE_H
40 #ifndef NO_COMPLETION
41 typedef struct linenoiseCompletions {
42 size_t len;
43 char **cvec;
44 } linenoiseCompletions;
47 * The callback type for tab completion handlers.
49 typedef void(linenoiseCompletionCallback)(const char *prefix, linenoiseCompletions *comp, void *userdata);
52 * Sets the current tab completion handler and returns the previous one, or NULL
53 * if no prior one has been set.
55 linenoiseCompletionCallback * linenoiseSetCompletionCallback(linenoiseCompletionCallback *comp, void *userdata);
58 * Adds a copy of the given string to the given completion list. The copy is owned
59 * by the linenoiseCompletions object.
61 void linenoiseAddCompletion(linenoiseCompletions *comp, const char *str);
62 #endif
65 * Prompts for input using the given string as the input
66 * prompt. Returns when the user has tapped ENTER or (on an empty
67 * line) EOF (Ctrl-D on Unix, Ctrl-Z on Windows). Returns either
68 * a copy of the entered string (for ENTER) or NULL (on EOF). The
69 * caller owns the returned string and must eventually free() it.
71 char *linenoise(const char *prompt);
73 /**
74 * Clear the screen.
76 void linenoiseClearScreen(void);
79 * Adds a copy of the given line of the command history.
81 int linenoiseHistoryAdd(const char *line);
84 * Sets the maximum length of the command history, in lines.
85 * If the history is currently longer, it will be trimmed,
86 * retaining only the most recent entries. If len is 0 or less
87 * then this function does nothing.
89 int linenoiseHistorySetMaxLen(int len);
92 * Returns the current maximum length of the history, in lines.
94 int linenoiseHistoryGetMaxLen(void);
97 * Saves the current contents of the history to the given file.
98 * Returns 0 on success.
100 int linenoiseHistorySave(const char *filename);
103 * Replaces the current history with the contents
104 * of the given file. Returns 0 on success.
106 int linenoiseHistoryLoad(const char *filename);
109 * Frees all history entries, clearing the history.
111 void linenoiseHistoryFree(void);
114 * Returns a pointer to the list of history entries, writing its
115 * length to *len if len is not NULL. The memory is owned by linenoise
116 * and must not be freed.
118 char **linenoiseHistory(int *len);
121 * Returns the number of display columns in the current terminal.
123 int linenoiseColumns(void);
125 #endif /* __LINENOISE_H */