@@ -20,6 +20,41 @@ SimpleCLI::~SimpleCLI() {
20
20
cmd_error_destroy_rec (errorQueue);
21
21
}
22
22
23
+ void SimpleCLI::pause () {
24
+ pauseParsing = true ;
25
+ }
26
+
27
+ void SimpleCLI::unpause () {
28
+ pauseParsing = false ;
29
+
30
+ // Go through queued errors
31
+ while (onError && errored ()) {
32
+ onError (getError ().getPtr ());
33
+ }
34
+
35
+ // Go through queued commands
36
+ if (available ()) {
37
+ cmd* prev = NULL ;
38
+ cmd* current = cmdQueue;
39
+ cmd* next = NULL ;
40
+
41
+ while (current) {
42
+ next = current->next ;
43
+
44
+ // Has callback, then run it and remove from queue
45
+ if (current->callback ) {
46
+ current->callback (current);
47
+ if (prev) prev->next = next;
48
+ cmd_destroy (current);
49
+ } else {
50
+ prev = current;
51
+ }
52
+
53
+ current = next;
54
+ }
55
+ }
56
+ }
57
+
23
58
void SimpleCLI::parse (const String& input) {
24
59
parse (input.c_str (), input.length ());
25
60
}
@@ -45,15 +80,15 @@ void SimpleCLI::parse(const char* str, size_t len) {
45
80
46
81
// When parsing was successful
47
82
if (e->mode == CMD_PARSE_SUCCESS) {
48
- if (h->callback ) h->callback (h);
83
+ if (h->callback && !pauseParsing ) h->callback (h);
49
84
else cmdQueue = cmd_push (cmdQueue, cmd_move (h), commandQueueSize);
50
85
51
86
success = true ;
52
87
}
53
88
54
89
// When command name matches but something else went wrong, exit with error
55
90
else if (e->mode > CMD_NOT_FOUND) {
56
- if (onError) {
91
+ if (onError && !pauseParsing ) {
57
92
onError (e);
58
93
} else {
59
94
errorQueue = cmd_error_push (errorQueue, cmd_error_copy (e), errorQueueSize);
@@ -79,7 +114,7 @@ void SimpleCLI::parse(const char* str, size_t len) {
79
114
if (!errored && !success) {
80
115
cmd_error* e = cmd_error_create_not_found (NULL , n->words ->first );
81
116
82
- if (onError) {
117
+ if (onError && !pauseParsing ) {
83
118
onError (e);
84
119
} else {
85
120
errorQueue = cmd_error_push (errorQueue, cmd_error_copy (e), errorQueueSize);
@@ -104,6 +139,10 @@ bool SimpleCLI::errored() const {
104
139
return errorQueue;
105
140
}
106
141
142
+ bool SimpleCLI::paused () const {
143
+ return pauseParsing;
144
+ }
145
+
107
146
int SimpleCLI::countCmdQueue () const {
108
147
cmd* h = cmdQueue;
109
148
int i = 0 ;
0 commit comments