Permalink
Browse files

Big cleanups to linenoise

- Use a structure (current) to hold the state.
- Add fd_printf() to simplify output
- Add has_room(), insert_char(), remove_char(), fd_read()
- Use ctrl(X) instead of magic numbers
- Escape special chars in the history file
- Provide access to the history lines
- Completion support is optional

Signed-off-by: Steve Bennett <steveb@workware.net.au>
  • Loading branch information...
1 parent e50556d commit 70fc7e0dc53624cac9389d2f67521256829cc288 @msteveb committed Apr 7, 2011
Showing with 396 additions and 256 deletions.
  1. +4 −1 example.c
  2. +388 −253 linenoise.c
  3. +4 −2 linenoise.h
View
@@ -2,18 +2,21 @@
#include <stdlib.h>
#include "linenoise.h"
-
+#ifndef NO_COMPLETION
void completion(const char *buf, linenoiseCompletions *lc) {
if (buf[0] == 'h') {
linenoiseAddCompletion(lc,"hello");
linenoiseAddCompletion(lc,"hello there");
}
}
+#endif
int main(void) {
char *line;
+#ifndef NO_COMPLETION
linenoiseSetCompletionCallback(completion);
+#endif
linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
while((line = linenoise("hello> ")) != NULL) {
if (line[0] != '\0') {
Oops, something went wrong. Retry.

0 comments on commit 70fc7e0

Please sign in to comment.