4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright (C) 2004 Giovanni Bajo
30 * Copyright (C) 2004 Develer S.r.l. (http://www.develer.com/)
31 * All Rights Reserved.
34 * \brief Line editing support with history
36 * This file implements a kernel for line editing through a terminal, with history of the typed lines.
37 * Basic feature of this module:
39 * \li Abstracted from I/O. The user must provide hooks for getc and putc functions.
40 * \li Basic support for ANSI escape sequences for input of special codes.
41 * \li Support for command name completion (through a hook).
44 * \author Giovanni Bajo <rasky@develer.com>
46 * $WIZ$ module_name = "readline"
47 * $WIZ$ module_depends = "sprintf"
51 #ifndef MWARE_READLINE_H
52 #define MWARE_READLINE_H
54 #include <cfg/compiler.h>
58 #define HISTORY_SIZE 32
60 typedef int (*getc_hook)(void* user_data);
61 typedef void (*putc_hook)(char ch, void* user_data);
62 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
63 typedef void (*clear_hook)(void* user_data);
81 char real_history[HISTORY_SIZE];
87 INLINE void rl_init_ctx(struct RLContext *ctx)
89 memset(ctx, 0, sizeof(*ctx));
90 ctx->history = ctx->real_history;
93 INLINE void rl_clear_history(struct RLContext *ctx)
95 memset(ctx->real_history, 0, sizeof(ctx->real_history));
97 ctx->line_pos = ctx->history_pos;
98 ctx->history = ctx->real_history;
101 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
102 { ctx->get = get; ctx->get_param = get_param; }
104 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
105 { ctx->put = put; ctx->put_param = put_param; }
107 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
108 { ctx->match = match; ctx->match_param = match_param; }
110 INLINE void rl_sethook_clear(struct RLContext* ctx, clear_hook clear, void* clear_param)
111 { ctx->clear = clear; ctx->clear_param = clear_param; }
113 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
114 { ctx->prompt = prompt; }
116 const char* rl_readline(struct RLContext* ctx);
118 void rl_refresh(struct RLContext* ctx);
120 #endif /* MWARE_READLINE_H */