|
|
@ -20,10 +20,20 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <math.h> |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CMD_BUFF_SIZE |
|
|
|
|
|
|
|
#define CMD_BUFF_SIZE 5 |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool terminal_enabled = false; |
|
|
|
bool terminal_enabled = false; |
|
|
|
char buffer[80] = ""; |
|
|
|
char buffer[80] = ""; |
|
|
|
|
|
|
|
char cmd_buffer[CMD_BUFF_SIZE][80]; |
|
|
|
|
|
|
|
bool cmd_buffer_enabled = true; //replace with ifdef?
|
|
|
|
char newline[2] = "\n"; |
|
|
|
char newline[2] = "\n"; |
|
|
|
char arguments[6][20]; |
|
|
|
char arguments[6][20]; |
|
|
|
|
|
|
|
bool firstTime = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
short int current_cmd_buffer_pos = 0; //used for up/down arrows - keeps track of where you are in the command buffer
|
|
|
|
|
|
|
|
|
|
|
|
__attribute__ ((weak)) |
|
|
|
__attribute__ ((weak)) |
|
|
|
const char terminal_prompt[8] = "> "; |
|
|
|
const char terminal_prompt[8] = "> "; |
|
|
@ -64,6 +74,7 @@ struct stringcase { |
|
|
|
void enable_terminal(void) { |
|
|
|
void enable_terminal(void) { |
|
|
|
terminal_enabled = true; |
|
|
|
terminal_enabled = true; |
|
|
|
strcpy(buffer, ""); |
|
|
|
strcpy(buffer, ""); |
|
|
|
|
|
|
|
memset(cmd_buffer,0,CMD_BUFF_SIZE * 80); |
|
|
|
for (int i = 0; i < 6; i++) |
|
|
|
for (int i = 0; i < 6; i++) |
|
|
|
strcpy(arguments[i], ""); |
|
|
|
strcpy(arguments[i], ""); |
|
|
|
// select all text to start over
|
|
|
|
// select all text to start over
|
|
|
@ -73,6 +84,29 @@ void enable_terminal(void) { |
|
|
|
|
|
|
|
|
|
|
|
void disable_terminal(void) { |
|
|
|
void disable_terminal(void) { |
|
|
|
terminal_enabled = false; |
|
|
|
terminal_enabled = false; |
|
|
|
|
|
|
|
SEND_STRING("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void push_to_cmd_buffer(void) { |
|
|
|
|
|
|
|
if (cmd_buffer_enabled) { |
|
|
|
|
|
|
|
if (cmd_buffer == NULL) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (firstTime) { |
|
|
|
|
|
|
|
firstTime = false; |
|
|
|
|
|
|
|
strcpy(cmd_buffer[0],buffer); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i= CMD_BUFF_SIZE - 1;i > 0 ;--i) { |
|
|
|
|
|
|
|
strncpy(cmd_buffer[i],cmd_buffer[i-1],80); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(cmd_buffer[0],buffer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void terminal_about(void) { |
|
|
|
void terminal_about(void) { |
|
|
@ -136,11 +170,34 @@ void terminal_keymap(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print_cmd_buff(void) { |
|
|
|
|
|
|
|
/* without the below wait, a race condition can occur wherein the
|
|
|
|
|
|
|
|
buffer can be printed before it has been fully moved */ |
|
|
|
|
|
|
|
wait_ms(250); |
|
|
|
|
|
|
|
for(int i=0;i<CMD_BUFF_SIZE;i++){ |
|
|
|
|
|
|
|
char tmpChar = ' '; |
|
|
|
|
|
|
|
itoa(i ,&tmpChar,10); |
|
|
|
|
|
|
|
const char * tmpCnstCharStr = &tmpChar; //because sned_string wont take a normal char *
|
|
|
|
|
|
|
|
send_string(tmpCnstCharStr); |
|
|
|
|
|
|
|
SEND_STRING(". "); |
|
|
|
|
|
|
|
send_string(cmd_buffer[i]); |
|
|
|
|
|
|
|
SEND_STRING("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void flush_cmd_buffer(void) { |
|
|
|
|
|
|
|
memset(cmd_buffer,0,CMD_BUFF_SIZE * 80); |
|
|
|
|
|
|
|
SEND_STRING("Buffer Cleared!\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stringcase terminal_cases[] = { |
|
|
|
stringcase terminal_cases[] = { |
|
|
|
{ "about", terminal_about }, |
|
|
|
{ "about", terminal_about }, |
|
|
|
{ "help", terminal_help }, |
|
|
|
{ "help", terminal_help }, |
|
|
|
{ "keycode", terminal_keycode }, |
|
|
|
{ "keycode", terminal_keycode }, |
|
|
|
{ "keymap", terminal_keymap }, |
|
|
|
{ "keymap", terminal_keymap }, |
|
|
|
|
|
|
|
{ "flush-buffer" , flush_cmd_buffer}, |
|
|
|
|
|
|
|
{ "print-buffer" , print_cmd_buff}, |
|
|
|
{ "exit", disable_terminal } |
|
|
|
{ "exit", disable_terminal } |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -154,6 +211,7 @@ void terminal_help(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void command_not_found(void) { |
|
|
|
void command_not_found(void) { |
|
|
|
|
|
|
|
wait_ms(50); //sometimes buffer isnt grabbed quick enough
|
|
|
|
SEND_STRING("command \""); |
|
|
|
SEND_STRING("command \""); |
|
|
|
send_string(buffer); |
|
|
|
send_string(buffer); |
|
|
|
SEND_STRING("\" not found\n"); |
|
|
|
SEND_STRING("\" not found\n"); |
|
|
@ -192,6 +250,16 @@ void process_terminal_command(void) { |
|
|
|
send_string(terminal_prompt); |
|
|
|
send_string(terminal_prompt); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void check_pos(void) { |
|
|
|
|
|
|
|
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...
|
|
|
|
|
|
|
|
current_cmd_buffer_pos = CMD_BUFF_SIZE - 1; |
|
|
|
|
|
|
|
} 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
|
|
|
|
|
|
|
|
current_cmd_buffer_pos = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool process_terminal(uint16_t keycode, keyrecord_t *record) { |
|
|
|
bool process_terminal(uint16_t keycode, keyrecord_t *record) { |
|
|
|
|
|
|
|
|
|
|
@ -210,6 +278,8 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) { |
|
|
|
char char_to_add; |
|
|
|
char char_to_add; |
|
|
|
switch (keycode) { |
|
|
|
switch (keycode) { |
|
|
|
case KC_ENTER: |
|
|
|
case KC_ENTER: |
|
|
|
|
|
|
|
push_to_cmd_buffer(); |
|
|
|
|
|
|
|
current_cmd_buffer_pos = 0; |
|
|
|
process_terminal_command(); |
|
|
|
process_terminal_command(); |
|
|
|
return false; break; |
|
|
|
return false; break; |
|
|
|
case KC_ESC: |
|
|
|
case KC_ESC: |
|
|
@ -226,9 +296,36 @@ bool process_terminal(uint16_t keycode, keyrecord_t *record) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case KC_LEFT: |
|
|
|
case KC_LEFT: |
|
|
|
|
|
|
|
return false; break; |
|
|
|
case KC_RIGHT: |
|
|
|
case KC_RIGHT: |
|
|
|
case KC_UP: |
|
|
|
return false; break; |
|
|
|
|
|
|
|
case KC_UP: // 0 = recent
|
|
|
|
|
|
|
|
check_pos(); //check our current buffer position is valid
|
|
|
|
|
|
|
|
if (current_cmd_buffer_pos <= CMD_BUFF_SIZE - 1) { //once we get to the top, dont do anything
|
|
|
|
|
|
|
|
str_len = strlen(buffer); |
|
|
|
|
|
|
|
for(int i= 0;i < str_len ;++i) { |
|
|
|
|
|
|
|
send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already
|
|
|
|
|
|
|
|
//process_terminal(KC_BSPC,record);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],80); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_string(buffer); |
|
|
|
|
|
|
|
++current_cmd_buffer_pos; //get ready to access the above cmd if up/down is pressed again
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; break; |
|
|
|
case KC_DOWN: |
|
|
|
case KC_DOWN: |
|
|
|
|
|
|
|
check_pos(); |
|
|
|
|
|
|
|
if (current_cmd_buffer_pos >= 0) { //once we get to the bottom, dont do anything
|
|
|
|
|
|
|
|
str_len = strlen(buffer); |
|
|
|
|
|
|
|
for(int i= 0;i < str_len ;++i) { |
|
|
|
|
|
|
|
send_string(SS_TAP(X_BSPACE)); //clear w/e is on the line already
|
|
|
|
|
|
|
|
//process_terminal(KC_BSPC,record);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
strncpy(buffer,cmd_buffer[current_cmd_buffer_pos],79); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_string(buffer); |
|
|
|
|
|
|
|
--current_cmd_buffer_pos; //get ready to access the above cmd if down/up is pressed again
|
|
|
|
|
|
|
|
} |
|
|
|
return false; break; |
|
|
|
return false; break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
if (keycode <= 58) { |
|
|
|
if (keycode <= 58) { |
|
|
|