-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyacli.h
117 lines (103 loc) · 4.16 KB
/
yacli.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// $Id: yacli.h,v 1.31 2020/06/29 01:57:18 bbonev Exp $
//
// Copyright © 2015-2020 Boian Bonev ([email protected]) {{{
//
// This file is part of yacli - yet another command line interface library.
//
// yacli is free software: you can redistribute it and/or mowdify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// yacli is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with yacli. If not, see <http://www.gnu.org/licenses/>.
// }}}
#ifndef ___YACLI_H___
#define ___YACLI_H___
#include <yascreen.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
YACLI_LOOP,
YACLI_ENTER,
YACLI_ERROR,
YACLI_EOF,
} yacli_loop;
struct _yacli;
typedef struct _yacli yacli;
// allocate and initialize cli data
inline yacli *yacli_init(yascreen *s);
// get library version as static string
inline const char *yacli_ver(void);
// convenience to access screen
inline yascreen *yacli_get_screen(yacli *cli);
// set cli start banner
inline void yacli_set_banner(yacli *cli,const char *banner);
// set cli level prompt
inline void yacli_set_level(yacli *cli,const char *level);
// set cli hostname
inline void yacli_set_hostname(yacli *cli,const char *hostname);
// set showing terminal size on change
inline void yacli_set_showtermsize(yacli *cli,int v);
// set telnet mode
inline void yacli_set_telnet(yacli *cli,int on);
// enable more
inline void yacli_set_more(yacli *cli,int on);
// set more prompt behaviour after line/page/continue/quit/^C
inline void yacli_set_more_clear(yacli *cli,int ln,int pg,int co,int qu);
// enable ctrl-z handling (pops mode stack to top level)
inline void yacli_set_ctrlz(yacli *cli,int on);
inline void yacli_set_ctrlz_exec(yacli *cli,int on);
// get/set user hint
inline void yacli_set_hint_i(yacli *cli,int hint);
inline int yacli_get_hint_i(yacli *cli);
inline void yacli_set_hint_p(yacli *cli,void *hint);
inline void *yacli_get_hint_p(yacli *cli);
// start cli DFA
inline void yacli_start(yacli *cli);
// revert telnet setup, if needed
inline void yacli_stop(yacli *cli);
// send input key to cli DFA
inline yacli_loop yacli_key(yacli *cli,int key);
// signal terminal size change
inline void yacli_winch(yacli *cli);
// signal cli to exit
inline void yacli_exit(yacli *cli);
// filtered print, using print cb
inline int yacli_print(yacli *cli,const char *format,...) __attribute__((format(printf,2,3)));
inline int yacli_write(yacli *cli,const char *format,size_t len);
// unfiltered print for line messages (will clear the prompt, print the line and reprint prompt)
inline void yacli_message(yacli *cli,const char *line);
// add command to history buffer
inline int yacli_add_hist(yacli *cli,const char *buf);
// add part of command to command tree
inline void *yacli_add_cmd(yacli *cli,void *parent,const char *cmd,const char *help,void (*cb)(yacli *cli,int cnt,char **cmd));
// add item to dynamic list
inline void yacli_list(yacli *cli,void *ctx,const char *item);
// set list callback function
inline void yacli_set_list_cb(yacli *cli,void (*list_cb)(yacli *cli,void *ctx,int code));
// set command callback function
inline void yacli_set_cmd_cb(yacli *cli,void (*cmd_cb)(yacli *cli,const char *cmd,int code));
// set ctrl-z callback function
inline void yacli_set_ctrlz_cb(yacli *cli,void (*ctrlzcb)(yacli *cli));
// enter submode with shortname (all commands for the submode should be added after this call)
inline void yacli_enter_mode(yacli *cli,const char *mode,void *hint);
// exit submode (submode commands are deleted)
inline void yacli_exit_mode(yacli *cli);
// get/set user hint for the current mode
inline void yacli_set_mode_hint_p(yacli *cli,void *hint);
inline void *yacli_get_mode_hint_p(yacli *cli);
// get current buffer contents
inline const char *yacli_buf_get(yacli *cli);
// cleanup and free cli data
inline void yacli_free(yacli *cli);
#ifdef __cplusplus
}
#endif
#endif