DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
prompt.h
Go to the documentation of this file.
1 #ifndef PROMPT_H_
2 #define PROMPT_H_
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 
7 #ifdef __cplusplus
8 #define PROMPT_DECL_BEGIN__ extern "C" {
9 #define PROMPT_DECL_END__ }
10 #else
11 #define PROMPT_DECL_BEGIN__
12 #define PROMPT_DECL_END__
13 #endif
14 
15 #define PROMPT_HIST_SIZE 64
16 #define PROMPT_LINE_SIZE 512
17 
19 
20 struct prompt {
21  unsigned int cursor; /* cursor position for current line */
22  unsigned int current; /* current history[] entry */
23  unsigned int entries; /* number of entries in history[] */
24  struct prompt_history {
25  unsigned int length; /* line length */
26  uint8_t line[PROMPT_LINE_SIZE]; /* line data */
28 };
29 
30 struct prompt_parse {
31  unsigned int index; /* current index in argv */
32  unsigned int cursor; /* cursor position for current index or ~0u */
33  unsigned int argc; /* number of elements in argv */
34  uint8_t **argv; /* NULL-terminated array of pointers to each word */
35  unsigned int *args; /* size of each argv[] element */
37  unsigned int pos;
38  unsigned int len;
39  } *argo; /* position and length of each element in original string */
40 };
41 
42 extern void prompt_init(struct prompt *p);
43 extern void prompt_push(struct prompt *p);
44 extern void prompt_older(struct prompt *p);
45 extern void prompt_newer(struct prompt *p);
46 extern void prompt_left(struct prompt *p);
47 extern void prompt_right(struct prompt *p);
48 extern void prompt_begin(struct prompt *p);
49 extern void prompt_end(struct prompt *p);
50 extern void prompt_clear(struct prompt *p);
51 extern void prompt_put(struct prompt *p, uint8_t c);
52 extern void prompt_delete(struct prompt *p);
53 extern void prompt_backspace(struct prompt *p);
54 extern void prompt_replace(struct prompt *p, unsigned int pos,
55  unsigned int len, const uint8_t *with,
56  unsigned int with_len);
57 extern struct prompt_parse *prompt_parse(struct prompt *p,
58  struct prompt_parse *pp);
59 extern void prompt_parse_clean(struct prompt_parse *pp);
60 
62 
63 #endif /* PROMPT_H_ */