Skip to content

Commit a191084

Browse files
committed
Hint generator in progress
A trie parser and generator has been made to generate tool tips. It is currently under test.
1 parent 424bca9 commit a191084

File tree

12 files changed

+1575
-15
lines changed

12 files changed

+1575
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ set( SOURCES
5151
src/Commander-DefaultSettings.hpp
5252
src/Commander-Caller-Interface.hpp
5353
src/Commander-Caller-Interface.cpp
54+
src/Commander-Autocomplete.hpp
55+
src/Commander-Autocomplete.cpp
5456

5557
extras/simulator/Arduino.h
5658
extras/simulator/Print.cpp

extras/examples_desktop/Desktop/Memory/Memory.cpp

Lines changed: 144 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// Necessary includes
3030
#include "Commander-API.hpp"
3131
#include "Commander-API-Commands.hpp"
32+
#include "Commander-Autocomplete.hpp"
33+
3234

3335

3436
// Use stdio as Channel.
@@ -43,18 +45,120 @@ bool cat_func( char *args, CommandCaller* caller );
4345
bool dog_func( char *args, CommandCaller* caller );
4446
bool sum_func( char *args, CommandCaller* caller );
4547

46-
// Add echo and env commands to the API tree.
47-
Commander::systemCommand_t API_tree[] = {
48-
systemCommand( "cat", "Description for cat command.", cat_func ),
49-
systemCommand( "dog", "Description for dog command.", dog_func ),
50-
systemCommand( "sum", "This function sums two number from the argument list.", sum_func )
51-
};
52-
5348
char commandBuffer[ COMMAND_SIZE ];
5449

5550
char pipeBuffer[ COMMANDER_PIPE_BUFFER_SIZE ];
5651
commanderPipeChannel pipeChannel;
52+
/*
53+
AutoComplete::TrieElement_t trie[ 9 ];
54+
uint16_t trie_indexes_element_0[] = { 1, 2 };
55+
uint16_t trie_indexes_element_1[] = { 3 };
56+
uint16_t trie_indexes_element_2[] = { 4, 5 };
57+
uint16_t trie_indexes_element_3[] = { 6, 7 };
58+
uint16_t trie_indexes_element_4[] = { 8 };
59+
*/
60+
61+
// Generated with Commander Trie Generator
62+
// Trie name: trie
63+
uint16_t trie_element_0_indexes[] = { 1 };
64+
uint16_t trie_element_1_indexes[] = { 2 };
65+
uint16_t trie_element_2_indexes[] = { 3, 4, 33, 38 };
66+
uint16_t trie_element_4_indexes[] = { 5, 9, 19 };
67+
uint16_t trie_element_5_indexes[] = { 6 };
68+
uint16_t trie_element_6_indexes[] = { 7 };
69+
uint16_t trie_element_7_indexes[] = { 8 };
70+
uint16_t trie_element_9_indexes[] = { 10 };
71+
uint16_t trie_element_10_indexes[] = { 11 };
72+
uint16_t trie_element_11_indexes[] = { 12 };
73+
uint16_t trie_element_12_indexes[] = { 13 };
74+
uint16_t trie_element_13_indexes[] = { 14 };
75+
uint16_t trie_element_14_indexes[] = { 15 };
76+
uint16_t trie_element_15_indexes[] = { 16 };
77+
uint16_t trie_element_16_indexes[] = { 17 };
78+
uint16_t trie_element_17_indexes[] = { 18 };
79+
uint16_t trie_element_19_indexes[] = { 20 };
80+
uint16_t trie_element_20_indexes[] = { 21 };
81+
uint16_t trie_element_21_indexes[] = { 22 };
82+
uint16_t trie_element_22_indexes[] = { 23 };
83+
uint16_t trie_element_23_indexes[] = { 24 };
84+
uint16_t trie_element_24_indexes[] = { 25 };
85+
uint16_t trie_element_25_indexes[] = { 26 };
86+
uint16_t trie_element_26_indexes[] = { 27 };
87+
uint16_t trie_element_27_indexes[] = { 28 };
88+
uint16_t trie_element_28_indexes[] = { 29 };
89+
uint16_t trie_element_29_indexes[] = { 30 };
90+
uint16_t trie_element_30_indexes[] = { 31 };
91+
uint16_t trie_element_31_indexes[] = { 32 };
92+
uint16_t trie_element_33_indexes[] = { 34 };
93+
uint16_t trie_element_34_indexes[] = { 35 };
94+
uint16_t trie_element_35_indexes[] = { 36 };
95+
uint16_t trie_element_36_indexes[] = { 37 };
96+
uint16_t trie_element_38_indexes[] = { 39 };
97+
uint16_t trie_element_39_indexes[] = { 40 };
98+
uint16_t trie_element_40_indexes[] = { 41 };
99+
uint16_t trie_element_41_indexes[] = { 42 };
100+
uint16_t trie_element_42_indexes[] = { 43 };
101+
uint16_t trie_element_43_indexes[] = { 44 };
102+
uint16_t trie_element_44_indexes[] = { 45 };
103+
104+
AutoComplete::TrieElement_t trie[] = {
105+
{ '\0', false, 1, trie_element_0_indexes },
106+
{ ' ', false, 1, trie_element_1_indexes },
107+
{ '-', false, 4, trie_element_2_indexes },
108+
{ 'h', true, 0, NULL },
109+
{ '-', false, 3, trie_element_4_indexes },
110+
{ 'h', false, 1, trie_element_5_indexes },
111+
{ 'e', false, 1, trie_element_6_indexes },
112+
{ 'l', false, 1, trie_element_7_indexes },
113+
{ 'p', true, 0, NULL },
114+
{ 'r', false, 1, trie_element_9_indexes },
115+
{ 'e', false, 1, trie_element_10_indexes },
116+
{ 'b', false, 1, trie_element_11_indexes },
117+
{ 'o', false, 1, trie_element_12_indexes },
118+
{ 'o', false, 1, trie_element_13_indexes },
119+
{ 't', true, 1, trie_element_14_indexes },
120+
{ ' ', false, 1, trie_element_15_indexes },
121+
{ 'n', false, 1, trie_element_16_indexes },
122+
{ 'o', false, 1, trie_element_17_indexes },
123+
{ 'w', true, 0, NULL },
124+
{ 'd', false, 1, trie_element_19_indexes },
125+
{ 'i', false, 1, trie_element_20_indexes },
126+
{ 's', false, 1, trie_element_21_indexes },
127+
{ 'p', false, 1, trie_element_22_indexes },
128+
{ 'l', false, 1, trie_element_23_indexes },
129+
{ 'a', false, 1, trie_element_24_indexes },
130+
{ 'y', false, 1, trie_element_25_indexes },
131+
{ ' ', false, 1, trie_element_26_indexes },
132+
{ '"', false, 1, trie_element_27_indexes },
133+
{ 'T', false, 1, trie_element_28_indexes },
134+
{ 'e', false, 1, trie_element_29_indexes },
135+
{ 'x', false, 1, trie_element_30_indexes },
136+
{ 't', false, 1, trie_element_31_indexes },
137+
{ '"', true, 0, NULL },
138+
{ 'r', true, 1, trie_element_33_indexes },
139+
{ ' ', false, 1, trie_element_34_indexes },
140+
{ 'n', false, 1, trie_element_35_indexes },
141+
{ 'o', false, 1, trie_element_36_indexes },
142+
{ 'w', true, 0, NULL },
143+
{ 'd', false, 1, trie_element_38_indexes },
144+
{ ' ', false, 1, trie_element_39_indexes },
145+
{ '"', false, 1, trie_element_40_indexes },
146+
{ 'T', false, 1, trie_element_41_indexes },
147+
{ 'e', false, 1, trie_element_42_indexes },
148+
{ 'x', false, 1, trie_element_43_indexes },
149+
{ 't', false, 1, trie_element_44_indexes },
150+
{ '"', true, 0, NULL }
151+
};
57152

153+
AutoComplete help_test( trie );
154+
155+
156+
// Add echo and env commands to the API tree.
157+
Commander::systemCommand_t API_tree[] = {
158+
systemCommandWithHelp( "cat", "Description for cat command.", cat_func, &help_test ),
159+
systemCommandWithHelp( "dog", "Description for dog command.", dog_func, &help_test ),
160+
systemCommandWithHelp( "sum", "This function sums two number from the argument list.", sum_func, &help_test )
161+
};
58162

59163

60164
// Main program.
@@ -67,7 +171,6 @@ int main(){
67171

68172
}
69173

70-
71174
// There is an option to attach a debug channel to Commander.
72175
// It can be handy to find any problems during the initialization
73176
// phase. In this example, we will use stdioChannel for this.
@@ -86,22 +189,51 @@ int main(){
86189
// Commander at the beginning of your code to prevent stack-overlow.
87190
commander.init();
88191

89-
commander.enablePipeModule( pipeBuffer, &pipeChannel );
192+
// commander.enablePipeModule( pipeBuffer, &pipeChannel );
90193

91194
stdioChannel.println();
92195
stdioChannel.println( "---- Init Finished ----" );
93196
stdioChannel.println();
94197

95-
stdioChannel.println( "Type something" );
96-
stdioChannel.print( "$: " );
198+
char buffer[ 200 ];
199+
int buffer_size = sizeof( buffer );
200+
int num_of_hints;
201+
int i;
202+
203+
num_of_hints = commander.generateHint( "cat --reboot ", buffer, buffer_size );
204+
stdioChannel.print( "number of hints: " );
205+
stdioChannel.println( num_of_hints );
206+
for( i = 0; i < num_of_hints; i++ ){
207+
stdioChannel.print( "\t" );
208+
stdioChannel.println( commander.getHint( i ) );
209+
}
210+
211+
num_of_hints = commander.generateHint( "cat --rebo", buffer, buffer_size );
212+
stdioChannel.print( "number of hints: " );
213+
stdioChannel.println( num_of_hints );
214+
for( i = 0; i < num_of_hints; i++ ){
215+
stdioChannel.print( "\t" );
216+
stdioChannel.println( commander.getHint( i, true ) );
217+
}
218+
219+
num_of_hints = commander.generateHint( "c", buffer, buffer_size );
220+
stdioChannel.print( "number of hints: " );
221+
stdioChannel.println( num_of_hints );
222+
for( i = 0; i < num_of_hints; i++ ){
223+
stdioChannel.print( "\t" );
224+
stdioChannel.println( commander.getHint( i, true ) );
225+
}
226+
227+
// stdioChannel.println( "Type something" );
228+
// stdioChannel.print( "$: " );
97229

98230

99231

100232
// Infinite loop.
101233
while( 1 ){
102234

103235

104-
commander.update( commandBuffer, COMMAND_SIZE, &stdioChannel );
236+
// commander.update( commandBuffer, COMMAND_SIZE, &stdioChannel );
105237

106238

107239

0 commit comments

Comments
 (0)