summaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_terminal.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_terminal.c')
-rw-r--r--quantum/process_keycode/process_terminal.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/quantum/process_keycode/process_terminal.c b/quantum/process_keycode/process_terminal.c
index a059f3a521..da1c4d506f 100644
--- a/quantum/process_keycode/process_terminal.c
+++ b/quantum/process_keycode/process_terminal.c
@@ -27,12 +27,12 @@
27bool terminal_enabled = false; 27bool terminal_enabled = false;
28char buffer[80] = ""; 28char buffer[80] = "";
29char cmd_buffer[CMD_BUFF_SIZE][80]; 29char cmd_buffer[CMD_BUFF_SIZE][80];
30bool cmd_buffer_enabled = true; // replace with ifdef? 30bool cmd_buffer_enabled = true; // replace with ifdef?
31char newline[2] = "\n"; 31char newline[2] = "\n";
32char arguments[6][20]; 32char arguments[6][20];
33bool firstTime = true; 33bool firstTime = true;
34 34
35short int current_cmd_buffer_pos = 0; // used for up/down arrows - keeps track of where you are in the command buffer 35short int current_cmd_buffer_pos = 0; // used for up/down arrows - keeps track of where you are in the command buffer
36 36
37__attribute__((weak)) const char terminal_prompt[8] = "> "; 37__attribute__((weak)) const char terminal_prompt[8] = "> ";
38 38
@@ -59,7 +59,8 @@ void enable_terminal(void) {
59 terminal_enabled = true; 59 terminal_enabled = true;
60 strcpy(buffer, ""); 60 strcpy(buffer, "");
61 memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); 61 memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80);
62 for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); 62 for (int i = 0; i < 6; i++)
63 strcpy(arguments[i], "");
63 // select all text to start over 64 // select all text to start over
64 // SEND_STRING(SS_LCTL("a")); 65 // SEND_STRING(SS_LCTL("a"));
65 send_string(terminal_prompt); 66 send_string(terminal_prompt);
@@ -160,7 +161,7 @@ void print_cmd_buff(void) {
160 for (int i = 0; i < CMD_BUFF_SIZE; i++) { 161 for (int i = 0; i < CMD_BUFF_SIZE; i++) {
161 char tmpChar = ' '; 162 char tmpChar = ' ';
162 itoa(i, &tmpChar, 10); 163 itoa(i, &tmpChar, 10);
163 const char *tmpCnstCharStr = &tmpChar; // because sned_string wont take a normal char * 164 const char *tmpCnstCharStr = &tmpChar; // because sned_string wont take a normal char *
164 send_string(tmpCnstCharStr); 165 send_string(tmpCnstCharStr);
165 SEND_STRING(". "); 166 SEND_STRING(". ");
166 send_string(cmd_buffer[i]); 167 send_string(cmd_buffer[i]);
@@ -185,7 +186,7 @@ void terminal_help(void) {
185} 186}
186 187
187void command_not_found(void) { 188void command_not_found(void) {
188 wait_ms(50); // sometimes buffer isnt grabbed quick enough 189 wait_ms(50); // sometimes buffer isnt grabbed quick enough
189 SEND_STRING("command \""); 190 SEND_STRING("command \"");
190 send_string(buffer); 191 send_string(buffer);
191 SEND_STRING("\" not found\n"); 192 SEND_STRING("\" not found\n");
@@ -217,15 +218,16 @@ void process_terminal_command(void) {
217 218
218 if (terminal_enabled) { 219 if (terminal_enabled) {
219 strcpy(buffer, ""); 220 strcpy(buffer, "");
220 for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); 221 for (int i = 0; i < 6; i++)
222 strcpy(arguments[i], "");
221 SEND_STRING(SS_TAP(X_HOME)); 223 SEND_STRING(SS_TAP(X_HOME));
222 send_string(terminal_prompt); 224 send_string(terminal_prompt);
223 } 225 }
224} 226}
225void check_pos(void) { 227void check_pos(void) {
226 if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { // if over the top, move it back down to the top of the buffer so you can climb back down... 228 if (current_cmd_buffer_pos >= CMD_BUFF_SIZE) { // if over the top, move it back down to the top of the buffer so you can climb back down...
227 current_cmd_buffer_pos = CMD_BUFF_SIZE - 1; 229 current_cmd_buffer_pos = CMD_BUFF_SIZE - 1;
228 } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up 230 } else if (current_cmd_buffer_pos < 0) { //...and if you fall under the bottom of the buffer, reset back to 0 so you can climb back up
229 current_cmd_buffer_pos = 0; 231 current_cmd_buffer_pos = 0;
230 } 232 }
231} 233}
@@ -278,33 +280,33 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) {
278 case KC_RIGHT: 280 case KC_RIGHT:
279 return false; 281 return false;
280 break; 282 break;
281 case KC_UP: // 0 = recent 283 case KC_UP: // 0 = recent
282 check_pos(); // check our current buffer position is valid 284 check_pos(); // check our current buffer position is valid
283 if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { // once we get to the top, dont do anything 285 if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { // once we get to the top, dont do anything
284 str_len = strlen(buffer); 286 str_len = strlen(buffer);
285 for (int i = 0; i < str_len; ++i) { 287 for (int i = 0; i < str_len; ++i) {
286 send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already 288 send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already
287 // process_terminal(KC_BACKSPACE,record); 289 // process_terminal(KC_BACKSPACE,record);
288 } 290 }
289 strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 80); 291 strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 80);
290 292
291 send_string(buffer); 293 send_string(buffer);
292 ++current_cmd_buffer_pos; // get ready to access the above cmd if up/down is pressed again 294 ++current_cmd_buffer_pos; // get ready to access the above cmd if up/down is pressed again
293 } 295 }
294 return false; 296 return false;
295 break; 297 break;
296 case KC_DOWN: 298 case KC_DOWN:
297 check_pos(); 299 check_pos();
298 if (current_cmd_buffer_pos >= 0) { // once we get to the bottom, dont do anything 300 if (current_cmd_buffer_pos >= 0) { // once we get to the bottom, dont do anything
299 str_len = strlen(buffer); 301 str_len = strlen(buffer);
300 for (int i = 0; i < str_len; ++i) { 302 for (int i = 0; i < str_len; ++i) {
301 send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already 303 send_string(SS_TAP(X_BSPACE)); // clear w/e is on the line already
302 // process_terminal(KC_BACKSPACE,record); 304 // process_terminal(KC_BACKSPACE,record);
303 } 305 }
304 strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 79); 306 strncpy(buffer, cmd_buffer[current_cmd_buffer_pos], 79);
305 307
306 send_string(buffer); 308 send_string(buffer);
307 --current_cmd_buffer_pos; // get ready to access the above cmd if down/up is pressed again 309 --current_cmd_buffer_pos; // get ready to access the above cmd if down/up is pressed again
308 } 310 }
309 return false; 311 return false;
310 break; 312 break;