void read_tty(char ch) { int n; if(kb_pi >= R*C) printf("input buffer full\n"); if(ch == '\b') { if(kb_pi) { kb_pi--; goto echo; } else goto no_echo; } kb_pend[kb_pi] = ch; kb_pi++; if(ch == '\n') { n = write(pipe_in, kb_pend, kb_pi); if(n < kb_pi) printf("truncation\n"); kb_pi = 0; } echo: write_tty_normal(ch); draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2); refresh_scr(p_x1, p_y1, p_x2, p_y2); pend = 0; draw_cur(); no_echo:; }
int do_window() { WMsg msg; static int scroll_off; w_recv(ifd, &msg, sizeof(WMsg)); switch( msg.type ) { case UM_KEY: if(!(msg.arg4 & KBS_BRK)) { if((msg.arg4 & KBS_LSH || msg.arg4 & KBS_RSH)) { if(msg.arg3 & KB_PGDN) { scroll_off += R*C; draw_scr(add_mod(cur_top, scroll_off), 0, 0, C-1, R-1); refresh_scr(0, 0, C-1, R-1); } else if(msg.arg3 & KB_PGUP) { scroll_off -= R*C; draw_scr(add_mod(cur_top, scroll_off), 0, 0, C-1, R-1); refresh_scr(0, 0, C-1, R-1); } } if(msg.arg2 != 0) { if(scroll_off) { scroll_off = 0; draw_scr(cur_top, 0, 0, C-1, R-1); refresh_scr(0, 0, C-1, R-1); } read_tty(msg.arg2); } } break; case UM_EXIT: if(destroy_window(hwnd)) return 1; break; default: break; } return 0; }
void draw_cur() { int r, c; if(!scr_pos_hide) { r = add_mod(scr_pos, -cur_top)/C; c = add_mod(scr_pos, -cur_top)%C; update_scr(scr_pos); draw_ascii(canv, c*FW, (r+1)*FH, scr[scr_pos], bg[scr_pos], fg[scr_pos]); refresh_scr(p_x1, p_y1, p_x2, p_y2); } }
void term_init() { int i; printf("in\n"); for(i = 0; i < R*C*NBUF; i++) { fg[i] = color_table[7]; bg[i] = color_table[0]; scr[i] = ' '; } cur_fg = color_table[7]; cur_bg = color_table[0]; draw_scr(0, 0, 0, C-1, R-1); refresh_scr(0, 0, C-1, R-1); }
static void total_cs(void) { double totcs; goto_xy(18,6); scrcolor(FGmain,BGmain); print("? "); goto_xy(18,6); refresh_scr(); calccoef(); if (err_code ) print("incorrect"); else { totcs= gauss345(cross_section, cos1,cos2,eps); if (err_code<=0 ) { print("%-G [pb]",totcs);} if(err_code==1) print("?"); } }
void menu0(int col,int row,char* label, char* menstr , void (**funcKey)(int) ,char** funcKeyMess, void ** hscr, int* kk) { int i, j, k, col1, npage,lastrow; long lastpage; int ink; int ncol; void * pscr; int fkPos[11]; int height; char fmt[20]; int lastLine; /* colors */ int label_fg =Yellow; int label_bg =Blue; int help_fg1 =White; int help_fg2 =Black; int help_bg =DarkGray; int box_fg =White; int box_bg =DarkGray; int star_fg =Red; int page_fg =Black; int actFunc_fg=Black; int actFunc_bg=White; int pasFunc_fg=White; int pasFunc_bg=DarkGray; /* save colors */ int fcolor_tmp=fColor; int bcolor_tmp=bColor; void *hscr_=NULL; if(hscr==NULL) hscr=&hscr_; lastLine=maxRow(); if (funcKey == NULL) for (i=0;i<11;i++) fkPos[i]=0; else { int xx; scrcolor(FGmain,BGmain); goto_xy(1,lastLine); clr_eol(); xx=0; for (j=0;j<10;j++) { if(funcKey[j] && funcKeyMess[j]) xx=xx+4+strlen(funcKeyMess[j]);} xx= (80 - xx )/2 ; goto_xy(xx,lastLine); for (i=0;i<10;i++) { fkPos[i]=where_x(); if (funcKey[i] && funcKeyMess[i]) { scrcolor(help_fg1,help_bg); print(" F%i-",i+1); scrcolor(help_fg2,help_bg); print(funcKeyMess[i]); } } fkPos[10]=where_x(); } clearTypeAhead(); if (*kk < 0) *kk = -(*kk); ncol=menstr[0]; sprintf(fmt,"%%%d.%ds",ncol,ncol); height=strlen(menstr)/ncol; if(height==0) { *kk=0; return; } if (row+height+1 >lastLine-2) height=lastLine-3-row; lastpage = 1+ (strlen(menstr)/ncol -1)/height ; if(label[0] ==0 || row == 1) { if (*hscr == NULL) get_text(col,row,col+ncol+1,row+2,hscr);} else { char label_[STRSIZ]; int shft,sz; if (*hscr == NULL) get_text(col,row-1,col+ncol+1,row+2,hscr); for(i=0;i<ncol+2;i++) label_[i]=' '; label_[ncol+2]=0; sz=strlen(label); if(sz >ncol+2) {shft=0;sz=ncol+2;} else shft=(ncol+2 -sz)/2; memcpy(label_+shft,label,sz); scrcolor(label_fg,label_bg); goto_xy(col,row-1); print(label_); } get_text(col,row + 3,col + ncol + 1,row + height + 1,&pscr); if (*kk <= 0 || *kk > lastpage * height ) { npage = 1; k = 1; } else { k = ((*kk) - 1) % height + 1; npage = ((*kk) - 1) / height + 1; } col1 = col + 1; label_1: scrcolor(box_fg,box_bg); chepbox(col,row,col + ncol + 1,row + height + 1); scrcolor(star_fg,box_bg); goto_xy(col+1,row); print("<"); /* goto_xy(col+1,row + height+1); print("?"); */ scrcolor(page_fg,box_bg); if (npage > 1) { goto_xy(col + ncol - 2,row); print("PgUp"); } if (npage < lastpage) { goto_xy(col + ncol - 2,row + height + 1); print("PgDn"); } if(npage<lastpage) lastrow=height; else lastrow = (strlen(menstr)/ncol)%height; lastrow=0; scrcolor(pasFunc_fg,pasFunc_bg); for (j = 1; j <= height; j++) { int shift; goto_xy(col + 1,row + j); shift=1+(j-1 + (npage-1)*height)*ncol; if(shift<strlen(menstr)) {print(fmt,menstr+shift );lastrow++;} else print(fmt," "); } scrcolor(actFunc_fg,actFunc_bg); if (k > lastrow) k = lastrow; goto_xy(col + 1,row + k); if (lastrow) print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); while (1) { int jump=1,mousePos; scrcolor(pasFunc_fg,pasFunc_bg); ink = inkey(); /* mouse filter */ if ((ink==KB_MOUSE)&&(mouse_info.but1 == 2)) { if (mouse_info.row == lastLine ) for(i=0; i<10;i++) if ((mouse_info.col > fkPos[i]) && (mouse_info.col < fkPos[i+1])) { if (i==9)ink='0'; else ink='1'+i;} if ( (mouse_info.col >= col ) && (mouse_info.col <=col+ncol+1) ) { mousePos = mouse_info.row - row; if (col+ncol+1-mouse_info.col <4) { if (mousePos==0) ink=KB_PAGEU; if (mousePos==height+1) ink=KB_PAGED; } if ((mousePos == 0 ) && ( mouse_info.col-col <4)) ink=KB_ESC; if ((mousePos < 0)&&(mousePos >= height)) { if (mousePos > k) {ink=KB_DOWN; jump=mousePos - k;} if (mousePos < k) {ink=KB_UP; jump=k - mousePos;} if (mousePos==k ) ink=KB_ENTER; } } } /* end of filter */ if (lastrow == 0) goto label_3; label_4: switch (ink) { case KB_MOUSE: if (mouse_info.but1 != 2) break; if (mouse_info.row == lastLine ) for(i=0; i<10;i++) if ((mouse_info.col > fkPos[i]) && (mouse_info.col < fkPos[i+1])) { if (i==9)ink='0'; else ink='1'+i; goto label_4; } if ( (mouse_info.col < col ) || (mouse_info.col >col+ncol+1) || (mouse_info.row < row ) || (mouse_info.row >row+height+1) ) break; mousePos = mouse_info.row - row; if ((mousePos == 0 ) && ( mouse_info.col-col <4)) ink=KB_ESC; if ((mousePos != 0)&&(mousePos != height+1)) { if (mousePos > k) { ink=KB_DOWN; jump=mousePos - k;} if (mousePos < k ) { ink=KB_UP; jump=k - mousePos;} } if (col+ncol+1-mouse_info.col <4) { if (mousePos==0) ink=KB_PAGEU; if (mousePos==height+1) ink=KB_PAGED; } if (mousePos==k ) ink=KB_ENTER; if (ink!=KB_MOUSE) goto label_4; break; case KB_DOWN: if(k==lastrow) { if(npage < lastpage) { k=1; npage++; goto label_1; } else { be_be(); break; } }else {ink= KB_RIGHT; goto label_4;} case KB_UP: if(k==1) { if (npage > 1) { k=height; npage--; goto label_1; } else{ be_be(); break; } } else {ink= KB_LEFT; goto label_4;} case KB_LEFT: goto_xy(col1,row + k); print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); k = k - jump; if (k == 0) k = lastrow; scrcolor(actFunc_fg,actFunc_bg); goto_xy(col1,row + k); print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); break; case KB_RIGHT: goto_xy(col1,row + k); print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); k = k + jump ; if(k > lastrow) k = 1; scrcolor(actFunc_fg,actFunc_bg); goto_xy(col1,row + k); print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); break; case KB_ENTER: scrcolor(box_fg,box_bg); chepbox(col,row,col+ncol+1,row+2); put_text(&pscr); goto_xy(col1,row + 1); scrcolor(actFunc_fg,actFunc_bg); print(fmt,menstr+1+(k-1+(npage-1)*height)*ncol); *kk = (npage - 1) * height + k; goto_xy(1,lastLine);scrcolor(FGmain,BGmain); clr_eol(); if(hscr==&hscr_) put_text(hscr); refresh_scr(); escpressed(); return; case KB_BACKSP: case KB_ESC: goto label_3; case KB_PAGEU: if (npage > 1) { npage--; goto label_1; } else be_be(); break; case KB_PAGED: if (npage < lastpage) { npage++; goto label_1; } else be_be(); break; case '1': case'2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': case KB_F1: case KB_F2: case KB_F3: case KB_F4: case KB_F5: case KB_F6: case KB_F7: case KB_F8: case KB_F9: case KB_F10: { int fk; if (funcKey==NULL) break; if ( ink>='0' && ink <='9') { fk=ink-'0';if (fk==0) fk=10;} else fk=ink-KB_F1+1; if ((funcKey[fk-1]) != NULL) { void * saveHlp; get_text(1,lastLine,maxCol(),lastLine,&saveHlp); scrcolor(box_fg,box_bg); goto_xy(col+1,row); print("%c",boxFrame[1]); goto_xy(1,lastLine);scrcolor(FGmain,BGmain);clr_eol(); (*funcKey[fk-1])((npage-1)*height+k); put_text(&saveHlp); scrcolor(star_fg,box_bg); goto_xy(col+1,row); print("<"); } break; } case 6: /* ^F */ case 'f': case 'F': { char name[32]=""; int key=correctStr(5,23,"Enter name(Esc for exit):",name,30,1); if(key) { char * x=strstr(menstr+1,name); if(x==NULL) { if(blind) sortie(121); else messanykey(10,10, "Not detected"); break; } k= ((x-menstr)-1)/menstr[0]; npage = k/ height + 1; k = k% height + 1; goto label_1; } } break; } } label_3: put_text(hscr); put_text(&pscr); scrcolor(fcolor_tmp,bcolor_tmp); goto_xy(1,lastLine); clr_eol(); *kk = 0; }
void write_tty(char *buf, int n) { static int estate; static int num, num2; static int light, hide; static int saved_r, saved_c; int i; int tmp, tr, tc; while(n--) { switch(estate) { case 0: //normal state if(*buf == '\033') { estate = 1; } else { write_tty_normal(*buf); estate = estate; } break; case 1: //esc begin if(*buf == '[') estate = 2; else estate = 0; break; case 2: //meet '[' if(*buf == 'K') { //清除从光标到行尾内容 estate = 0; } else if(*buf == 's') { //保存光标位置 saved_r = add_mod(scr_pos, -cur_top)/C; saved_c = add_mod(scr_pos, -cur_top)%C; estate = 0; } else if(*buf == 'u') { //恢复光标位置 scr_pos = add_mod(cur_top, saved_c+C*saved_r); estate = 0; } else if(*buf == '?') { //隐藏/显示光标 estate = 6; } else if(*buf >= 0 && *buf <= '9') { num = *buf - '0'; estate = 3; } else { printf("unkown esc seq 1\n"); estate = 0; } break; case 3: //first arg if(*buf == 'm') { switch(num) { case 0: //关闭所有属性 light = 0; hide = 0; cur_fg = color_table[7]; cur_bg = color_table[0]; break; case 1: //设置高亮 light = 1; break; case 4: //下划线 break; case 5: //闪烁 break; case 7: //反显 tmp = cur_fg; cur_fg = cur_bg; cur_bg = tmp; break; case 8: //消隐 hide = 1; break; default: if(num >= 30 && num <= 37) { //前景色 cur_fg = hide ? cur_bg : color_table[num-30+light*8]; }else if(num >= 40 && num <= 47) { //背景色 cur_bg = color_table[num-40+light*8]; } else { printf("unkown esc seq 2\n"); } break; } estate = 0; } else if(*buf == 'J') { if(num == 2) { //清屏 for(i = 0; i < R*C; i++) { int p = add_mod(i, cur_top); scr[p] = ' '; fg[p] = color_table[7]; bg[p] = color_table[0]; } p_x1 = 0; p_y1 = 0; p_x2 = C-1; p_y2 = R-1; pend = 1; estate = 0; } else { printf("unkown esc seq 3\n"); estate = 0; } } else if(*buf == 'A') { //上移动 tr = add_mod(scr_pos, -cur_top)/C; tc = add_mod(scr_pos, -cur_top)%C; tr -= num; if(tr < 0) tr = 0; scr_pos = add_mod(cur_top, tc+C*tr); estate = 0; } else if(*buf == 'B') { //下移动 tr = add_mod(scr_pos, -cur_top)/C; tc = add_mod(scr_pos, -cur_top)%C; tr += num; if(tr >= R) tr = R-1; scr_pos = add_mod(cur_top, tc+C*tr); estate = 0; } else if(*buf == 'C') { //左移动 tr = add_mod(scr_pos, -cur_top)/C; tc = add_mod(scr_pos, -cur_top)%C; tc -= num; if(tc < 0) tc = 0; scr_pos = add_mod(cur_top, tc+C*tr); estate = 0; } else if(*buf == 'D') { //右移动 tr = add_mod(scr_pos, -cur_top)/C; tc = add_mod(scr_pos, -cur_top)%C; tc += num; if(tc >= C) tc = C-1; scr_pos = add_mod(cur_top, tc+C*tr); estate = 0; } else if(*buf == ';') { estate = 4; } else if(*buf >= '0' && *buf <= '9') { num = num*10 + *buf - '0'; estate = estate; } break; case 4: //meet ; if(*buf >= '0' && *buf <= '9') { num2 = *buf - '0'; estate = 5; } else { printf("unkown esc seq 4\n"); estate = 0; } break; case 5: //second arg if(*buf == 'H') { //设置光标 tr = num; tc = num2; if(tc >= C) tc = C-1; if(tr >= R) tr = R-1; scr_pos = add_mod(cur_top, tc+C*tr); estate = 0; } else if(*buf >= '0' && *buf <= '9') { num2 = num2*10 + *buf - '0'; estate = estate; } else { printf("unkown esc seq 5\n"); estate = 0; } break; case 6: //meet ? if(*buf >= '0' && *buf <= '9') { num2 = *buf - '0'; estate = 7; } else { printf("unkown esc seq 6\n"); estate = 0; } break; case 7: if(*buf == 'h') { //显示光标 if(num2 == 25) { scr_pos_hide = 0; } else printf("unkown esc seq 7\n"); estate = 0; } else if(*buf == 'l') { //隐藏光标 if(num2 == 25) { scr_pos_hide = 1; printf("cursor hide\n"); } else printf("unkown esc seq 8\n"); estate = 0; } else if(*buf >= '0' && *buf <= '9') { num2 = num2*10 + *buf - '0'; estate = estate; } else { printf("unkown esc seq 9\n"); estate = 0; } break; default: printf("esc bug\n"); exit(1); break; } buf++; } draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2); refresh_scr(p_x1, p_y1, p_x2, p_y2); pend = 0; draw_cur(); }