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.1 2006/06/01 12:27:39 marco
26 *#* Added utilities for protocols
30 #ifndef MWARE_READLINE_H
31 #define MWARE_READLINE_H
33 #include <cfg/compiler.h>
37 #define HISTORY_SIZE 1024
39 typedef int (*getc_hook)(void* user_data);
40 typedef void (*putc_hook)(char ch, void* user_data);
41 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
56 char real_history[HISTORY_SIZE];
61 INLINE void rl_init_ctx(struct RLContext *ctx)
63 memset(ctx, 0, sizeof(*ctx));
64 ctx->history = ctx->real_history;
67 INLINE void rl_clear_history(struct RLContext *ctx)
69 memset(ctx->real_history, 0, sizeof(ctx->real_history));
71 ctx->history = ctx->real_history;
74 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
75 { ctx->get = get; ctx->get_param = get_param; }
77 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
78 { ctx->put = put; ctx->put_param = put_param; }
80 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
81 { ctx->match = match; ctx->match_param = match_param; }
83 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
84 { ctx->prompt = prompt; }
86 const char* rl_readline(struct RLContext* ctx);
88 void rl_refresh(struct RLContext* ctx);
90 #endif /* MWARE_READLINE_H */