/////////////////////////////////////////////////// // error message with nonstop /////////////////////////////////////////////////// void msg_nonstop(char* msg, ...) { BOOL raw_mode = mis_raw_mode(); char msg2[1024]; va_list args; va_start(args, msg); vsnprintf(msg2, 1024, msg, args); va_end(args); if(raw_mode) { const int maxy = mgetmaxy(); const int maxx = mgetmaxx(); xclear(); view(); mclear_online(maxy-2); mclear_lastline(); mvprintw(maxy-2, 0, "%s", msg2); refresh(); } else { fprintf(stderr, "%s", msg2); } }
void select_str_view() { int maxx = mgetmaxx(); int maxy = mgetmaxy(); /// view /// mclear_online(maxy-2); mclear_lastline(); move(maxy-2, 0); printw("%s", gSelectStrMsg); // move(maxy-1, 0); printw(" "); int i; for(i=0; i< gSelectStrLen; i++) { if(gSelectStrCursor == i) { attron(A_REVERSE); printw("%s", gSelectStrStr[i]); attroff(A_REVERSE); printw(" "); } else { printw("%s ", gSelectStrStr[i]); } } //move(maxy-2, 0); }
/////////////////////////////////////////////////// // error message /////////////////////////////////////////////////// void merr_msg(char* msg, ...) { BOOL raw_mode = mis_raw_mode(); char msg2[1024]; va_list args; va_start(args, msg); vsnprintf(msg2, 1024, msg, args); va_end(args); if(raw_mode) { const int maxy = mgetmaxy(); const int maxx = mgetmaxx(); xclear(); view(); mclear_online(maxy-2); mclear_lastline(); mvprintw(maxy-2, 0, "%s", msg2); refresh(); (void)getch(); #if defined(__CYGWIN__) xclear_immediately(); // 画面の再描写 view(); refresh(); #endif } else { fprintf(stderr, "%s", msg2); } }
void mbackspace_head_of_line_immediately() { const int maxx = mgetmaxx(); write_escape_suqence(tigetstr("cuu1")); write_escape_suqence(tparm(tigetstr("cuf"), maxx)); write_escape_suqence(tigetstr("dch1")); }
void mclear_online(int y) { char space[1024]; int x; const int maxx = mgetmaxx(); for(x=0; x<maxx; x++) { space[x] = ' '; } space[x] = 0; attron(0); mvprintw(y, 0, space); }
void mclear_lastline() { char space[1024]; int x; const int maxx = mgetmaxx(); const int maxy = mgetmaxy(); for(x=0; x<maxx-1; x++) { space[x] = ' '; } space[x] = 0; attron(0); mvprintw(maxy-1, 0, space); }
void input_box_view() { int maxx = mgetmaxx(); int maxy = mgetmaxy(); /// view /// mclear_online(maxy-2); mclear_lastline(); mvprintw(maxy-2, 0, "%s", gInputBoxMsg); move(maxy-1, 0); const int len = string_length(gInputBoxInput); int i; for(i=0; i< len && i<maxx-1; i++) { printw("%c", string_c_str(gInputBoxInput)[i]); } //move_immediately(maxy -1, gInputBoxCursor); move(maxy -1, gInputBoxCursor); }
void xyzsh_readline_interface_on_curses(char* cmdline, int cursor_point, char** argv, int argc, BOOL exit_in_spite_ofjob_exist, BOOL welcome_msg) { gSigChld = FALSE; gSigWinch = FALSE; signal(SIGCHLD, handler); signal(SIGWINCH, handler); const int maxx = mgetmaxx(); const int maxy = mgetmaxy(); int temulator_y = 0; int temulator_x = 0; int temulator_height = maxy; int temulator_width = maxx; sTEmulator* temulator = temulator_init(temulator_height, temulator_width); struct sTEmulatorFunArg arg; arg.cmdline = cmdline; arg.cursor_point = cursor_point; arg.argv = argv; arg.argc = argc; arg.exit_in_spite_ofjob_exist = exit_in_spite_ofjob_exist; arg.welcome_msg = welcome_msg; temulator_open(temulator, temulator_fun, &arg); initscr(); start_color(); noecho(); raw(); nodelay(stdscr, TRUE); keypad(stdscr, TRUE); curs_set(0); ESCDELAY=50; temulator_init_colors(); WINDOW* term_win = newwin(temulator_height, temulator_width, temulator_y, temulator_x); int pty = temulator->mFD; fd_set mask, read_ok; FD_ZERO(&mask); FD_SET(0, &mask); FD_SET(pty, &mask); int dirty = 0; struct timeval next; gettimeofday(&next, NULL); while(1) { struct timeval tv = { 0, 1000 * 1000 / 100 }; read_ok = mask; if(select(pty+1, &read_ok, NULL, NULL, &tv) > 0) { if(FD_ISSET(pty, &read_ok)) { temulator_read(temulator); dirty = 1; } } int key; while((key = getch()) != ERR) { temulator_write(temulator, key); dirty = 1; } gettimeofday(&tv, NULL); if(dirty && is_expired(tv, next)) { temulator_draw_on_curses(temulator, term_win, temulator_y, temulator_x); wrefresh(term_win); dirty = 0; next = timeval_add(tv, slice); } if(gSigChld) { gSigChld = FALSE; break; } if(gSigWinch) { gSigWinch = 0; temulator_height = mgetmaxy(); temulator_width = mgetmaxx(); if(temulator_width >= 10 && temulator_height >= 10) { resizeterm(temulator_height, temulator_width); wresize(term_win, temulator_height, temulator_width); temulator_resize(temulator, temulator_height, temulator_width); dirty = 1; } } } endwin(); temulator_final(temulator); }
int input_box(char* msg, char* result, int result_size, char* def_input, int def_cursor) { gInputBoxMsg = msg; int result2 = 0; gInputBoxCursor = def_cursor; string_put(gInputBoxInput, def_input); gView = input_box_view; while(1) { xclear(); view(); //input_box_view(); refresh(); /// input /// int meta; int key = xgetch(&meta); if(key == 10 || key == 13) { result2 = 0; break; } else if(key == 6 || key == KEY_RIGHT) { input_box_cursor_move(gInputBoxInput, &gInputBoxCursor, 1); } else if(key == 2 || key == KEY_LEFT) { input_box_cursor_move(gInputBoxInput, &gInputBoxCursor, -1); } else if(key == 8 || key == KEY_BACKSPACE) { // CTRL-H if(gInputBoxCursor > 0) { char* str2 = string_c_str(gInputBoxInput); int utfpos = str_pointer2kanjipos(gKanjiCode, str2, str2 + gInputBoxCursor); char* before_point = str_kanjipos2pointer(gKanjiCode, str2, utfpos-1); int new_cursor = before_point-str2; string_erase(gInputBoxInput, before_point - str2, (str2 + gInputBoxCursor) - before_point); gInputBoxCursor = new_cursor; } } else if(key == 4 || key == KEY_DC) { // CTRL-D DELETE char* str2 = string_c_str(gInputBoxInput); if(string_length(gInputBoxInput) > 0) { if(gInputBoxCursor < string_length(gInputBoxInput)) { int utfpos = str_pointer2kanjipos(gKanjiCode, str2, str2 + gInputBoxCursor); char* next_point = str_kanjipos2pointer(gKanjiCode, str2, utfpos+1); string_erase(gInputBoxInput, gInputBoxCursor, next_point - (str2 + gInputBoxCursor)); } } } else if(key == 1 || key == KEY_HOME) { // CTRL-A input_box_cursor_move(gInputBoxInput, &gInputBoxCursor, -999); } else if(key == 5 || key == KEY_END) { // CTRL-E input_box_cursor_move(gInputBoxInput, &gInputBoxCursor, 999); } else if(key == 11) { // CTRL-K string_erase(gInputBoxInput, gInputBoxCursor, string_length(gInputBoxInput)-gInputBoxCursor); } else if(key == 21) { // CTRL-U string_put(gInputBoxInput, ""); gInputBoxCursor = 0; } else if(key == 23) { // CTRL-W if(gInputBoxCursor > 0) { const char* s = string_c_str(gInputBoxInput); int pos = gInputBoxCursor-1; if(s[pos]==' ' || s[pos]=='/' || s[pos]=='\'' || s[pos]=='"') { while(pos>=0 && (s[pos]==' ' || s[pos]=='/' || s[pos]=='\'' || s[pos]=='"')) { pos--; } } while(pos>=0 && s[pos]!=' ' && s[pos]!='/' && s[pos]!='\'' && s[pos]!='"') { pos--; } string_erase(gInputBoxInput, pos+1, gInputBoxCursor-pos-1); gInputBoxCursor = pos+1; } } else if(meta==1 && key == 'd') { // Meta-d const char* s = string_c_str(gInputBoxInput); if(s[gInputBoxCursor] != 0) { int pos = gInputBoxCursor; pos++; while(s[pos]!=0 && (s[pos] == ' ' || s[pos] == '/' || s[pos] == '\'' || s[pos] == '"')) { pos++; } while(s[pos]!=0 && s[pos] != ' ' && s[pos] != '/' && s[pos] != '\'' && s[pos] != '"') { pos++; } string_erase(gInputBoxInput, gInputBoxCursor, pos-gInputBoxCursor); } } else if(meta==1 && key == 'b') { // META-b if(gInputBoxCursor > 0) { const char* s = string_c_str(gInputBoxInput); int pos = gInputBoxCursor; pos--; while(pos>=0 && (s[pos] == ' ' || s[pos] == '/' || s[pos] == '\'' || s[pos] == '"')) { pos--; } while(pos>=0 && s[pos] != ' ' && s[pos] != '/' && s[pos] != '\'' && s[pos] != '"') { pos--; } gInputBoxCursor = pos+1; } } else if(meta==1 && key == 'f') { // META-f const char* s = string_c_str(gInputBoxInput); if(s[gInputBoxCursor] != 0) { int pos = gInputBoxCursor; pos++; while(s[pos]!=0 && (s[pos] == ' ' || s[pos] == '/' || s[pos] == '\'' || s[pos] == '"')) { pos++; } while(s[pos]!=0 && s[pos] != ' ' && s[pos] != '/' && s[pos] != '\'' && s[pos] != '"') { pos++; } gInputBoxCursor = pos; } } else if(key == 3 || key == 7 || key == 27) { // CTRL-C -G Escape result2 = 1; break; } else if(key == 12) { // CTRL-L xclear_immediately(); } else { if(meta == 0 && !(key >= 0 && key <= 27)) { char tmp[128]; snprintf(tmp, 128, "%c", key); string_insert(gInputBoxInput, gInputBoxCursor, tmp); gInputBoxCursor++; } } } gView = NULL; int maxx = mgetmaxx(); int maxy = mgetmaxy(); xstrncpy(result, string_c_str(gInputBoxInput), result_size); mmove_immediately(maxy -2, 0); #if defined(__CYGWIN__) xclear_immediately(); // 画面の再描写 view(); refresh(); #endif return result2; }
/////////////////////////////////////////////////// // choice /////////////////////////////////////////////////// char* choice(char* msg, char* str[], int len, int cancel) { const int maxy = mgetmaxy(); const int maxx = mgetmaxx(); int cursor = 0; while(1) { /// view /// clear(); view(); mclear_online(maxy-2); mclear_lastline(); move(maxy-2, 0); printw("%s", msg); printw(" "); int i; for(i=0; i< len; i++) { if(cursor == i) { attron(A_REVERSE); printw("%s", str[i]); attroff(A_REVERSE); printw(" "); } else { printw("%s ", str[i]); } } refresh(); /// input /// int meta; int key = xgetch(&meta); if(key == 10 || key == 13) { break; } else if(key == 6 || key == KEY_RIGHT) { cursor++; if(cursor >= len) cursor = len-1; } else if(key == 2 || key == KEY_LEFT) { cursor--; if(cursor < 0) cursor= 0; } else if(key == 12) { // CTRL-L xclear_immediately(); } else if(key == 3 || key == 7 || key == 27) { // CTRL-C -G Escape return NULL; } else { int i; for(i=0; i< len; i++) { if(toupper(key) == toupper(str[i][0])) { cursor = i; goto finished; } } } } finished: #if defined(__CYGWIN__) xclear_immediately(); // 画面の再描写 view(); refresh(); #endif return str[cursor]; }
void mmove_line_home_immediately() { const int maxx = mgetmaxx(); write_escape_suqence(tparm(tigetstr("cub"), maxx)); }