small updates
This commit is contained in:
24
tecs/term.c
24
tecs/term.c
@@ -252,7 +252,7 @@ static int dirty=0; /* line is to be cleared through a call of term_clear */
|
||||
|
||||
void term_clear(void) {
|
||||
if (dirty) {
|
||||
fputs("\r\033[K", stdout);
|
||||
fputs("\r\033[K\033[0m", stdout);
|
||||
dirty=0;
|
||||
}
|
||||
}
|
||||
@@ -267,8 +267,11 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
char key, *lin;
|
||||
int i,j,l,iret,buflen;
|
||||
char tmp[512];
|
||||
static int init=1;
|
||||
static char back[128]="";
|
||||
|
||||
if (back[0] == '\0') {
|
||||
memset(back, '\b', sizeof back);
|
||||
}
|
||||
buf[size-1]='\0'; /* make sure buf is null terminated */
|
||||
l=strlen(buf);
|
||||
if (*pos>l) {
|
||||
@@ -279,17 +282,20 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
iret=term_get_key(&key, 0);
|
||||
while (1) {
|
||||
if (iret==-1 || key == RET_CHAR || key==EVT_CHAR) { /* refresh after a short timeout */
|
||||
snprintf(tmp, sizeof tmp, "%s%s%s%s%s%.*s",
|
||||
"\r\033[1m", prompt, "\033[34m", buf, "\033[K\033[0m", l - *pos, back);
|
||||
/*
|
||||
assert(l*2+20+strlen(prompt)<sizeof(tmp));
|
||||
tmp[0]='\r';
|
||||
tmp[1]='\0';
|
||||
strcpy(tmp,"\r\033[1;34m");
|
||||
strcat(tmp, prompt);
|
||||
strcat(tmp, buf);
|
||||
strcat(tmp,"\033[K");
|
||||
strcat(tmp,"\033[K\033[0m");
|
||||
j=strlen(tmp);
|
||||
for (i=l; i>*pos; i--) {
|
||||
tmp[j]='\b'; j++;
|
||||
}
|
||||
tmp[j]='\0';
|
||||
*/
|
||||
fputs(tmp, stdout);
|
||||
if (iret==-1) {
|
||||
iret=term_get_key(&key, -1); /* no timeout */
|
||||
@@ -318,11 +324,9 @@ int term_get_line(char *buf, int size, int *pos, char *prompt, fd_set *mask) {
|
||||
}
|
||||
hist_pos=hist_end;
|
||||
term_save_hist(0);
|
||||
printf("\r\033[K\n");
|
||||
for (i = strlen(prompt) - 1; i > 0; i--) {
|
||||
printf("-");
|
||||
}
|
||||
printf(" %s", buf);
|
||||
printf("\r\033[K\n\033[1;34m");
|
||||
printf("%s", buf);
|
||||
printf("\033[0m");
|
||||
return(STDIN_FILENO);
|
||||
|
||||
/* normal EXIT */
|
||||
|
||||
Reference in New Issue
Block a user