/* character input */ static void _tinysh_char_in(uchar c) { uchar *line=input_buffers[cur_buf_index]; if(c=='\n' || c=='\r') /* validate command */ { tinysh_cmd_t *cmd; int context=0; /* first, echo the newline */ if(echo) putchar(c); while(*line && *line==' ') line++; if(*line) /* not empty line */ { cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; exec_command_line(cmd,line); cur_buf_index=(cur_buf_index+1)%HISTORY_DEPTH; cur_index=0; input_buffers[cur_buf_index][0]=0; } start_of_line(); } /* else if(c==TOPCHAR) // return to top level // { if(echo) putchar(c); cur_context=0; cur_cmd_ctx=0; } //*/ else if(c==8 || c==127) /* backspace */ { if(cur_index>0) { puts("\b \b"); cur_index--; line[cur_index]=0; } } else if(c==16) /* CTRL-P: back in history */ { int prevline=(cur_buf_index+HISTORY_DEPTH-1)%HISTORY_DEPTH; if(input_buffers[prevline][0]) { line=input_buffers[prevline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); putchar('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index=prevline; } } else if(c==14) /* CTRL-N: next in history */ { int nextline=(cur_buf_index+1)%HISTORY_DEPTH; if(input_buffers[nextline][0]) { line=input_buffers[nextline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); putchar('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index=nextline; } } /* else if(c=='?') // display help // { tinysh_cmd_t *cmd; cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; help_command_line(cmd,line); start_of_line(); puts(line); cur_index=strlen(line); } //*/ else if(c==9) /* TAB: autocompletion */ { tinysh_cmd_t *cmd; cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; //puts(cur_cmd_ctx);puts("--\r\n"); if(complete_command_line(cmd,line)) { start_of_line(); puts(line); } cur_index=strlen(line); //sprintf(buf, "cur_index: %d--\r\n", cur_index); //puts(buf); //puts("cur index:--");puts(cur_index);puts("--\r\n"); } else /* any input character */ { if(cur_index<BUFFER_SIZE) { if(echo) putchar(c); line[cur_index++]=c; line[cur_index]=0; } } }
/* character input */ static void _tinysh_char_in(uchar c) { uchar *line=input_buffers[cur_buf_index]; int i; if(c==128) // start binary transaction { binary_transaction(); return; } if(last_was_switch) { last_was_switch = 0; } else if(last_was_escape) { last_was_escape=0; last_was_dummy=1; } else if(last_was_dummy) { if(c==65) /* up arrow: back in history */ { int prevline=(cur_buf_index_for_viewing+HISTORY_DEPTH-1)%HISTORY_DEPTH; if(input_buffers[prevline][0]) { line=input_buffers[prevline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); tinysh_char_out('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index_for_viewing=prevline; line=input_buffers[cur_buf_index]; for(i=0;input_buffers[cur_buf_index_for_viewing][i]!=0;i++) input_buffers[cur_buf_index][i]=input_buffers[cur_buf_index_for_viewing][i]; input_buffers[cur_buf_index][i] = 0; } } else if(c==66) /* down: next in history */ { int nextline=(cur_buf_index_for_viewing+1)%HISTORY_DEPTH; if(input_buffers[nextline][0]) { line=input_buffers[nextline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); tinysh_char_out('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index_for_viewing=nextline; line=input_buffers[cur_buf_index]; for(i=0;input_buffers[cur_buf_index_for_viewing][i]!=0;i++) input_buffers[cur_buf_index][i]=input_buffers[cur_buf_index_for_viewing][i]; input_buffers[cur_buf_index][i] = 0; } } last_was_dummy=0; } else { if(c=='\n' || c=='\r') /* validate command */ { tinysh_cmd_t *cmd; int context=0; /* first, echo the newline */ if(echo) tinysh_char_out('\n'); tinysh_char_out('\r'); line=input_buffers[cur_buf_index]; input_buffers[cur_buf_index][strlen(line)]=0; if(*line) /* not empty line */ { cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; exec_command_line(cmd,line); cur_buf_index=(cur_buf_index+1)%HISTORY_DEPTH; cur_index=0; input_buffers[cur_buf_index][0]=0; cur_buf_index_for_viewing=cur_buf_index; } start_of_line(); } else if(c==TOPCHAR) /* return to top level */ { if(echo) tinysh_char_out(c); cur_context=0; cur_cmd_ctx=0; } else if(c==8 || c==127) /* backspace */ { if(cur_index>0) { puts("\b \b"); cur_index--; line[cur_index]=0; } } else if(c=='~') /* repeat the current line */ { repeat_line(); } else if(c==3) /* cancel the current line */ { if(echo) tinysh_char_out('\n'); tinysh_char_out('\r'); line=input_buffers[cur_buf_index]; input_buffers[cur_buf_index][strlen(line)]=0; start_of_line(); } else if(c=='`') /* switch FPGA */ { last_was_switch=1; } else if(c==16) /* CTRL-P: back in history */ { int prevline=(cur_buf_index_for_viewing+HISTORY_DEPTH-1)%HISTORY_DEPTH; if(input_buffers[prevline][0]) { line=input_buffers[prevline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); tinysh_char_out('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index_for_viewing=prevline; line=input_buffers[cur_buf_index]; for(i=0;input_buffers[cur_buf_index_for_viewing][i]!=0;i++) input_buffers[cur_buf_index][i]=input_buffers[cur_buf_index_for_viewing][i]; input_buffers[cur_buf_index][i] = 0; } } else if(c==14) /* CTRL-N: next in history */ { int nextline=(cur_buf_index_for_viewing+1)%HISTORY_DEPTH; if(input_buffers[nextline][0]) { line=input_buffers[nextline]; /* fill the rest of the line with spaces */ while(cur_index-->strlen(line)) puts("\b \b"); tinysh_char_out('\r'); start_of_line(); puts(line); cur_index=strlen(line); cur_buf_index_for_viewing=nextline; line=input_buffers[cur_buf_index]; for(i=0;input_buffers[cur_buf_index_for_viewing][i]!=0;i++) input_buffers[cur_buf_index][i]=input_buffers[cur_buf_index_for_viewing][i]; input_buffers[cur_buf_index][i] = 0; } } else if(c=='?') /* display help */ { tinysh_cmd_t *cmd; cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; help_command_line(cmd,line); start_of_line(); puts(line); cur_index=strlen(line); } else if(c==9 || c=='!') /* TAB: autocompletion */ { tinysh_cmd_t *cmd; cmd=cur_cmd_ctx?cur_cmd_ctx->child:root_cmd; if(complete_command_line(cmd,line)) { start_of_line(); puts(line); } cur_index=strlen(line); } else if(c==27) { last_was_escape=1; } else /* any input character */ { if(cur_index<BUFFER_SIZE) { if(echo) tinysh_char_out(c); line[cur_index++]=c; line[cur_index]=0; } } } }