mirror of
https://github.com/eddyem/tty_term.git
synced 2026-01-31 20:35:15 +03:00
strange things appears...
This commit is contained in:
parent
655ad5bd90
commit
6a63b5858c
30
main.c
30
main.c
@ -54,16 +54,15 @@ int main(int argc, char **argv){
|
|||||||
}
|
}
|
||||||
//fd = fopen("loglog", "w");
|
//fd = fopen("loglog", "w");
|
||||||
//fprintf(fd, "start\n");
|
//fprintf(fd, "start\n");
|
||||||
init_ncurses();
|
const char *EOL = "\n", *seol = "\\n";
|
||||||
init_readline();
|
|
||||||
const char *EOL = "\n";
|
|
||||||
if(strcasecmp(G->eol, "n")){
|
if(strcasecmp(G->eol, "n")){
|
||||||
if(strcasecmp(G->eol, "r") == 0) EOL = "\r";
|
if(strcasecmp(G->eol, "r") == 0){ EOL = "\r"; seol = "\\r"; }
|
||||||
else if(strcasecmp(G->eol, "rn") == 0) EOL = "\r\n";
|
else if(strcasecmp(G->eol, "rn") == 0){ EOL = "\r\n"; seol = "\\r\\n"; }
|
||||||
else if(strcasecmp(G->eol, "nr") == 0) EOL = "\n\r";
|
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\"");
|
else ERRX("End of line should be \"r\", \"n\" or \"rn\" or \"nr\"");
|
||||||
}
|
}
|
||||||
strcpy(dtty.eol, EOL);
|
strcpy(dtty.eol, EOL);
|
||||||
|
strcpy(dtty.seol, seol);
|
||||||
int eollen = strlen(EOL);
|
int eollen = strlen(EOL);
|
||||||
dtty.eollen = eollen;
|
dtty.eollen = eollen;
|
||||||
signal(SIGTERM, signals); // kill (-15) - quit
|
signal(SIGTERM, signals); // kill (-15) - quit
|
||||||
@ -71,6 +70,8 @@ int main(int argc, char **argv){
|
|||||||
signal(SIGINT, signals); // ctrl+C - quit
|
signal(SIGINT, signals); // ctrl+C - quit
|
||||||
signal(SIGQUIT, signals); // ctrl+\ - quit
|
signal(SIGQUIT, signals); // ctrl+\ - quit
|
||||||
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
||||||
|
init_ncurses();
|
||||||
|
init_readline();
|
||||||
pthread_t writer;
|
pthread_t writer;
|
||||||
if(pthread_create(&writer, NULL, cmdline, (void*)&dtty)) ERR("pthread_create()");
|
if(pthread_create(&writer, NULL, cmdline, (void*)&dtty)) ERR("pthread_create()");
|
||||||
settimeout(G->tmoutms);
|
settimeout(G->tmoutms);
|
||||||
@ -81,14 +82,27 @@ int main(int argc, char **argv){
|
|||||||
char *buf = dtty.dev->buf;
|
char *buf = dtty.dev->buf;
|
||||||
char *eol = NULL, *estr = buf + l;
|
char *eol = NULL, *estr = buf + l;
|
||||||
do{
|
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){
|
if(eol){
|
||||||
*eol = 0;
|
*eol = 0;
|
||||||
add_ttydata(buf);
|
add_ttydata(buf);
|
||||||
buf = eol + eollen;
|
buf = eol + eollen;
|
||||||
}else{
|
}else{
|
||||||
add_ttydata(buf);
|
char *ptr = buf;
|
||||||
|
while(*ptr){
|
||||||
|
if(*ptr == '\n' || *ptr == '\r'){ *ptr = 0; break;}
|
||||||
|
++ptr;
|
||||||
}
|
}
|
||||||
|
add_ttydata(buf);
|
||||||
|
}*/
|
||||||
}while(eol && buf < estr);
|
}while(eol && buf < estr);
|
||||||
}else if(l < 0){
|
}else if(l < 0){
|
||||||
pthread_mutex_unlock(&dtty.mutex);
|
pthread_mutex_unlock(&dtty.mutex);
|
||||||
|
|||||||
@ -103,6 +103,7 @@ static void msg_win_redisplay(bool for_resize){
|
|||||||
}else{ // put only first part
|
}else{ // put only first part
|
||||||
int rest = LINES-2 - nlines;
|
int rest = LINES-2 - nlines;
|
||||||
waddnstr(msg_win, buf, rest *COLS);
|
waddnstr(msg_win, buf, rest *COLS);
|
||||||
|
free(buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -135,8 +136,8 @@ static void readline_redisplay(){
|
|||||||
|
|
||||||
static void show_mode(bool for_resize){
|
static void show_mode(bool for_resize){
|
||||||
wclear(sep_win);
|
wclear(sep_win);
|
||||||
if(insert_mode) waddstr(sep_win, "INSERT (TAB to switch, ctrl+D to quit)");
|
if(insert_mode) wprintw(sep_win, "INSERT (TAB to switch, ctrl+D to quit) ENDLINE: %s", dtty?dtty->seol:"n");
|
||||||
else waddstr(sep_win, "SCROLL (TAB to switch, q to quit)");
|
else wprintw(sep_win, "SCROLL (TAB to switch, q to quit) ENDLINE: %s", dtty?dtty->seol:"n");
|
||||||
if(for_resize) wnoutrefresh(sep_win);
|
if(for_resize) wnoutrefresh(sep_win);
|
||||||
else wrefresh(sep_win);
|
else wrefresh(sep_win);
|
||||||
cmd_win_redisplay(for_resize);
|
cmd_win_redisplay(for_resize);
|
||||||
@ -278,6 +279,7 @@ static void rollup(){
|
|||||||
void *cmdline(void* arg){
|
void *cmdline(void* arg){
|
||||||
MEVENT event;
|
MEVENT event;
|
||||||
dtty = (ttyd*)arg;
|
dtty = (ttyd*)arg;
|
||||||
|
show_mode(false);
|
||||||
do{
|
do{
|
||||||
int c = wgetch(cmd_win);
|
int c = wgetch(cmd_win);
|
||||||
bool processed = true;
|
bool processed = true;
|
||||||
|
|||||||
@ -26,6 +26,7 @@ typedef struct{
|
|||||||
TTY_descr *dev;
|
TTY_descr *dev;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
char eol[3];
|
char eol[3];
|
||||||
|
char seol[5];
|
||||||
int eollen;
|
int eollen;
|
||||||
} ttyd;
|
} ttyd;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user