#include "nlsop_general.h"
-#define LOGFILE "~/.nlsop_logfile"
+#define LOGFILE "nlsop_gui_logfile"
+#define GOON 2
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;
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;i<display->max_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;i<display->max_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;
/* 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;
}
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;
}
z=atoi(command+1);
break;
default:
- display_new_line(display,"unknown command");
+ display_new_line(display,input,"unknown command");
break;
}
}
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;
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;
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);
}
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;