From: hackbard Date: Sun, 7 Nov 2004 11:49:56 +0000 (+0000) Subject: gui fixes! should work now X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85ca8485e31042e3890d09979c14cafdb75d077f;p=physik%2Fnlsop.git gui fixes! should work now --- diff --git a/nlsop_gui.c b/nlsop_gui.c index a7b447d..78cc86b 100644 --- a/nlsop_gui.c +++ b/nlsop_gui.c @@ -51,7 +51,8 @@ #include "nlsop_general.h" -#define LOGFILE "~/.nlsop_logfile" +#define LOGFILE "nlsop_gui_logfile" +#define GOON 2 int usage(char *prog) { @@ -64,7 +65,7 @@ int usage(char *prog) * gui internal functions */ -int display_new_line(t_display *display,char *text) { +int display_new_line(t_display *display,t_input *input,char *text) { int x,y; int ptr; @@ -79,26 +80,32 @@ int display_new_line(t_display *display,char *text) { memset(tmp,0x20,display->max_x); display_line(display,0,0,x,0,'#'); - display_string(display,1,y-y/2-17,"nlsop gui (C) 2004 Frank Zirkelbach",35); + display_string(display,x/2-17,1,"nlsop gui (C) 2004 Frank Zirkelbach",35); display_line(display,0,2,x,2,'#'); display_line(display,0,y-1,x,y-1,'#'); display_string(display,0,y,"prompt: ",8); - display_string(display,8,y,tmp,x-8); - display_set_cursor(display,8,y); - - ptr=3*display->max_x; - for(i=0;imax_x-6;i++) { - memcpy(display->screen+ptr,display->screen+ptr+display->max_x, - display->max_x); - ptr+=display->max_x; + memcpy(tmp,input->content,input->c_count); + display_string(display,8,y,tmp,x-9); + + if(text!=NULL) { + ptr=3*display->max_x; + for(i=0;imax_y-6;i++) { + memcpy(display->screen+ptr,display->screen+ptr+display->max_x, + display->max_x); + ptr+=display->max_x; + } + i=strlen(text); + memcpy(display->screen+ptr,text,i); + memset(display->screen+ptr+i,0x20,x-i); } display_draw(display); + display_set_cursor(display,8+input->c_count,y); return 1; } -int send_and_wait_for_answer(t_net *net,t_display *display) { +int send_and_wait_for_answer(t_net *net,t_display *display,t_input *input) { int i,count; t_job job; @@ -113,7 +120,7 @@ int send_and_wait_for_answer(t_net *net,t_display *display) { /* receive information */ network_receive_chan(net,0,&data,sizeof(unsigned char)); if(data!=GUI_INFO) { - display_new_line(display,"no gui info answer, ignored"); + display_new_line(display,input,"no gui info answer, ignored"); return -1; } @@ -125,10 +132,10 @@ int send_and_wait_for_answer(t_net *net,t_display *display) { job.channel,job.status&IN_WORK?'a':'q', job.info.b,job.info.c,job.info.s, job.info.diff_rate,job.info.dr_ac,job.progress); - display_new_line(display,string); + display_new_line(display,input,string); } - display_new_line(display,"done"); + display_new_line(display,input,"done"); return 1; } @@ -200,7 +207,7 @@ int send_job(t_net *net,t_input *input,t_display *display) { z=atoi(command+1); break; default: - display_new_line(display,"unknown command"); + display_new_line(display,input,"unknown command"); break; } } @@ -217,6 +224,31 @@ int send_job(t_net *net,t_input *input,t_display *display) { return 1; } +int get_whatever(t_input *input,void *ptr) { + + char last; + t_display *display; + + display=(t_display *)ptr; + + last=input->content[input->c_count-1]; + + if((last=='\n')||(last=='\r')) { + input->content[input->c_count-1]='\0'; + input->c_count=0; + return GOON; + } + + display_new_line(display,input,NULL); + + return 1; +} + +int nothing(t_event *event,void *allineed) { + + return 1; +} + int get_command(t_event *event,void *allineed) { t_net *net; @@ -229,24 +261,29 @@ int get_command(t_event *event,void *allineed) { display=(t_display *)addr[1]; input=(t_input *)addr[2]; - switch(input->content[0]) { - case GUI_INFO: - send_and_wait_for_answer(net,display); - break; - case GUI_ADDJOB: - send_job(net,input,display); - break; - case GUI_QUIT: - /* stop everything */ - event_math(0,event,READ,REMOVE); - network_shutdown(net); - display_shutdown(display); - input_shutdown(input); - event_stop(event); - return 2; - default: - display_new_line(display,"unknown gui command"); - break; + input_get_event(input,get_whatever,display); + + /* if there was a new line! */ + if(input->c_count==0) { + switch(input->content[0]) { + case GUI_INFO: + send_and_wait_for_answer(net,display,input); + break; + case GUI_ADDJOB: + send_job(net,input,display); + break; + case GUI_QUIT: + /* stop everything */ + event_math(0,event,READ,REMOVE); + network_shutdown(net); + display_shutdown(display); + input_shutdown(input); + event_stop(event); + return 2; + default: + display_new_line(display,input,"unknown gui command"); + break; + } } return 1; @@ -319,22 +356,22 @@ int main(int argc,char **argv) return -1; } + /* display init */ + display_init(&display,fd); + /* input init */ input_init(&input,fd); - input.mode=CONTENT_BUFFER|LINE_BUFFERED|INPUT_ECHO; + input.mode=CONTENT_BUFFER|ECHO; input_ios_init(&input); /* event init */ event_init(&event,fd); event_set_timeout(&event,0,0); - /* display init */ - display_init(&display,fd); - /* user interaction */ event_math(0,&event,READ,ADD); - display_new_line(&display,"welcome to nlsop gui! :)"); + display_new_line(&display,&input,"welcome to nlsop gui! :)"); /* connect to server */ network_init(&net,fd); @@ -345,18 +382,19 @@ int main(int argc,char **argv) } network_select(&net,0); - display_new_line(&display,"successfully connected to server"); + display_new_line(&display,&input,"successfully connected to server"); /* tell server: i am a client, i may work for you */ data=NLSOP_GUI; network_send(net.connection[0].fd,&data,1); - display_new_line(&display,"send data to server, waiting for input ..."); + display_new_line(&display,&input,"send data to server, waiting for input"); /* wait for job */ - event_start(&event,allyouneed,get_command,NULL); + event_start(&event,allyouneed,get_command,nothing); + + dprintf(fd,"hu?\n"); - free(allyouneed); close(fd); return 1;