4 * Copyright (C) 2004 Giovanni Bajo
5 * Copyright (C) 2004 Develer S.r.l. (http://www.develer.com/)
9 * \brief Line editing support with history
11 * This file implements a kernel for line editing through a terminal, with history of the typed lines.
12 * Basic feature of this module:
14 * \li Abstracted from I/O. The user must provide hooks for getc and putc functions.
15 * \li Basic support for ANSI escape sequences for input of special codes.
16 * \li Support for command name completion (through a hook).
20 * \author Giovanni Bajo <rasky@develer.com>
25 *#* Revision 1.2 2006/07/19 12:56:28 bernie
26 *#* Convert to new Doxygen style.
28 *#* Revision 1.1 2006/06/01 12:27:39 marco
29 *#* Added utilities for protocols
33 #ifndef MWARE_READLINE_H
34 #define MWARE_READLINE_H
36 #include <cfg/compiler.h>
40 #define HISTORY_SIZE 1024
42 typedef int (*getc_hook)(void* user_data);
43 typedef void (*putc_hook)(char ch, void* user_data);
44 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
59 char real_history[HISTORY_SIZE];
64 INLINE void rl_init_ctx(struct RLContext *ctx)
66 memset(ctx, 0, sizeof(*ctx));
67 ctx->history = ctx->real_history;
70 INLINE void rl_clear_history(struct RLContext *ctx)
72 memset(ctx->real_history, 0, sizeof(ctx->real_history));
74 ctx->history = ctx->real_history;
77 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
78 { ctx->get = get; ctx->get_param = get_param; }
80 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
81 { ctx->put = put; ctx->put_param = put_param; }
83 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
84 { ctx->match = match; ctx->match_param = match_param; }
86 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
87 { ctx->prompt = prompt; }
89 const char* rl_readline(struct RLContext* ctx);
91 void rl_refresh(struct RLContext* ctx);
93 #endif /* MWARE_READLINE_H */