diff --git a/main.c b/main.c index bb70362..e8fc083 100644 --- a/main.c +++ b/main.c @@ -54,16 +54,15 @@ int main(int argc, char **argv){ } //fd = fopen("loglog", "w"); //fprintf(fd, "start\n"); - init_ncurses(); - init_readline(); - const char *EOL = "\n"; + const char *EOL = "\n", *seol = "\\n"; if(strcasecmp(G->eol, "n")){ - if(strcasecmp(G->eol, "r") == 0) EOL = "\r"; - else if(strcasecmp(G->eol, "rn") == 0) EOL = "\r\n"; - else if(strcasecmp(G->eol, "nr") == 0) EOL = "\n\r"; + if(strcasecmp(G->eol, "r") == 0){ EOL = "\r"; seol = "\\r"; } + else if(strcasecmp(G->eol, "rn") == 0){ EOL = "\r\n"; seol = "\\r\\n"; } + else if(strcasecmp(G->eol, "nr") == 0){ EOL = "\n\r"; seol = "\\n\\r"; } else ERRX("End of line should be \"r\", \"n\" or \"rn\" or \"nr\""); } strcpy(dtty.eol, EOL); + strcpy(dtty.seol, seol); int eollen = strlen(EOL); dtty.eollen = eollen; signal(SIGTERM, signals); // kill (-15) - quit @@ -71,6 +70,8 @@ int main(int argc, char **argv){ signal(SIGINT, signals); // ctrl+C - quit signal(SIGQUIT, signals); // ctrl+\ - quit signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z + init_ncurses(); + init_readline(); pthread_t writer; if(pthread_create(&writer, NULL, cmdline, (void*)&dtty)) ERR("pthread_create()"); settimeout(G->tmoutms); @@ -81,14 +82,27 @@ int main(int argc, char **argv){ char *buf = dtty.dev->buf; char *eol = NULL, *estr = buf + l; do{ - eol = strstr(buf, EOL); + eol = strchr(buf, '\n'); + if(eol){ + *eol = 0; + add_ttydata(buf); + buf = eol + 1; + }else{ + add_ttydata(buf); + } + /*eol = strstr(buf, EOL); if(eol){ *eol = 0; add_ttydata(buf); buf = eol + eollen; }else{ + char *ptr = buf; + while(*ptr){ + if(*ptr == '\n' || *ptr == '\r'){ *ptr = 0; break;} + ++ptr; + } add_ttydata(buf); - } + }*/ }while(eol && buf < estr); }else if(l < 0){ pthread_mutex_unlock(&dtty.mutex); diff --git a/ncurses_and_readline.c b/ncurses_and_readline.c index 28d38fb..789a52b 100644 --- a/ncurses_and_readline.c +++ b/ncurses_and_readline.c @@ -103,6 +103,7 @@ static void msg_win_redisplay(bool for_resize){ }else{ // put only first part int rest = LINES-2 - nlines; waddnstr(msg_win, buf, rest *COLS); + free(buf); break; } free(buf); @@ -135,8 +136,8 @@ static void readline_redisplay(){ static void show_mode(bool for_resize){ wclear(sep_win); - if(insert_mode) waddstr(sep_win, "INSERT (TAB to switch, ctrl+D to quit)"); - else waddstr(sep_win, "SCROLL (TAB to switch, q to quit)"); + if(insert_mode) wprintw(sep_win, "INSERT (TAB to switch, ctrl+D to quit) ENDLINE: %s", dtty?dtty->seol:"n"); + else wprintw(sep_win, "SCROLL (TAB to switch, q to quit) ENDLINE: %s", dtty?dtty->seol:"n"); if(for_resize) wnoutrefresh(sep_win); else wrefresh(sep_win); cmd_win_redisplay(for_resize); @@ -278,6 +279,7 @@ static void rollup(){ void *cmdline(void* arg){ MEVENT event; dtty = (ttyd*)arg; + show_mode(false); do{ int c = wgetch(cmd_win); bool processed = true; diff --git a/ncurses_and_readline.h b/ncurses_and_readline.h index f7ef07f..bb8d60a 100644 --- a/ncurses_and_readline.h +++ b/ncurses_and_readline.h @@ -26,6 +26,7 @@ typedef struct{ TTY_descr *dev; pthread_mutex_t mutex; char eol[3]; + char seol[5]; int eollen; } ttyd;