/* * mvwdelch -- * Do a delete-char on the line at (y, x) of the given window. */ int mvwdelch(WINDOW *win, int y, int x) { if (wmove(win, y, x) == ERR) return ERR; return wdelch(win); }
static void send_bytes(int portfd, const unsigned char* buf, int n, WINDOW* win) { ssize_t written = 0; while (written < n) { ssize_t rc = write(portfd, &buf[written], n - written); if (rc >= 0) written += rc; else if (errno != EINTR) exit_error("send bytes", errno); } int xmax, ymax; getmaxyx(win, ymax, xmax); --xmax; if (n > xmax) { buf += n - xmax; n = xmax; } int x, y; getyx(win, y, x); int ndel = x + n - xmax; if (ndel > 0) { wmove(win, y, 0); for (int i = 0; i < ndel; ++i) wdelch(win); wmove(win, y, x - ndel); } for (int i = 0; i < n; ++i) { cchar_t cc; wchar_t wc[CCHARW_MAX]; attr_t attrs; short color_pair; wgetbkgrnd(win, &cc); getcchar(&cc, wc, &attrs, &color_pair, 0); wc[0] = kc_to_wide_char(buf[i]); setcchar(&cc, wc, attrs, color_pair, 0); wadd_wch(win, &cc); } while (tcdrain(portfd) < 0) { if (errno != EINTR) exit_error("send bytes", errno); } }
int mvdelch(int y, int x) { PDC_LOG(("mvdelch() - called\n")); if (move(y, x) == ERR) return ERR; return wdelch(stdscr); }
/* input:delch() delete a character */ int lui_delch_input(lua_State *L) { INPUT *i; luasoul_checkclass(L, 1, INPUT_CLASS, i); /* get input */ wdelch(i->pad); return 0; }
int mvwdelch(WINDOW *win, int y, int x) { PDC_LOG(("mvwdelch() - called\n")); if (wmove(win, y, x) == ERR) return ERR; return wdelch(win); }
void Terminal::clear_(){ for(int start = cmd.GetSize() + offset; start >= offset; start--){ wmove(input_window, 0, start); wdelch(input_window); } cmd.Clear(); cursX = offset; update_cursor_(); refresh_(); }
/** * Key backspace. */ static void case_key_backspace(volatile struct readline_session_context *ctx) { struct current_cursor_pos yx; if (ctx->bufpos == 0) { term_beep(); return; } if (loLim_isset(ctx->act, ctx->prompt_size)) { magic_swap_panels(ctx, false); } if (ctx->insert_mode) { wchar_t *ptr = &ctx->buffer[ctx->bufpos--]; (void) wmemmove(ptr - 1, ptr, wcslen(ptr)); ctx->buffer[--ctx->n_insert] = 0L; yx = term_get_pos(ctx->act); if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR || wdelch(ctx->act) == ERR || wclrtoeol(ctx->act) == ERR) { readline_error(EPERM, "wmove, wdelch or wclrtoeol"); } readline_winsnstr(ctx->act, &ctx->buffer[ctx->bufpos], -1); } else { /* not insert_mode */ ctx->buffer[--ctx->bufpos] = 0L; ctx->n_insert--; yx = term_get_pos(ctx->act); if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR || wdelch(ctx->act) == ERR) { readline_error(EPERM, "wmove or wdelch"); } } update_panels(); (void) doupdate(); }
/** * Read at most n characters from the FIFO into a window * * @v *win window in which to echo input * @v *str pointer to string in which to store result * @v n maximum number of characters to read into string (inc. NUL) * @ret rc return status code */ int wgetnstr ( WINDOW *win, char *str, int n ) { char *_str; int c; if ( n == 0 ) { *str = '\0'; return OK; } _str = str; while ( ( c = _wgetc( win ) ) != ERR ) { /* termination enforcement - don't let us go past the end of the allocated buffer... */ if ( n == 0 && ( c >= 32 && c <= 126 ) ) { _wcursback( win ); wdelch( win ); } else { if ( c >= 32 && c <= 126 ) { *(_str++) = c; n--; } else { switch(c) { case KEY_LEFT : case KEY_BACKSPACE : _wcursback( win ); wdelch( win ); break; case KEY_ENTER : *_str = '\0'; return OK; default : beep(); break; } } } } return ERR; }
void wdelchar() { register struct vt *v; v = &VT_array[VT_curid]; v->flags |= VT_DIRTY; if (!(v->flags & VT_NOBORDER)) { /* * insert character before border * (not necessary yet, handled in fields) */ ; } wdelch(v->win); }
int CursedWindow::getChar() { int c, width, height, distFromSpace; c = wgetch(contentWindow); getyx(contentWindow, cursorY, cursorX); getmaxyx(contentWindow, height, width); switch(c){ case KEY_DC: waddch(contentWindow, 'x'); break; case KEY_DOWN: wmove(contentWindow, cursorY+1, cursorX); break; case KEY_UP: wmove(contentWindow, cursorY-1, cursorX); break; case KEY_LEFT: wmove(contentWindow, cursorY, cursorX-1); break; case KEY_RIGHT: wmove(contentWindow, cursorY, cursorX+1); break; case KEY_BACKSPACE: wmove(contentWindow, cursorY, cursorX-1); wdelch(contentWindow); break; case ' ': lastSpaceX = cursorX; // waddch(contentWindow, '\n'); //waddch(contentWindow, c); default: if (cursorX < width-1){ waddch(contentWindow, c); } else { distFromSpace = cursorX - lastSpaceX; // need to drop the text down at the last space // wmove(contentWindow, y, lastSpaceX); // waddch(contentWindow, '\n'); // wmove(contentWindow, y+1, lastSpaceX+distFromSpace); waddch(contentWindow, c); } break; } return c; }
void putch(WINDOW * win, char ch) { if (ch == 4 || ch == 7) ch = '\b'; if ( ch < ' ' && ch != '\t' && ch != '\n' && ch != '\b' && ch != 'å' && ch != 'Å' && ch != 'ä' && ch != 'Ä' && ch != 'ö' && ch != 'Ö' ) return; pthread_mutex_lock(&scr_mutex); wechochar(win, (unsigned char)ch); if (ch == '\b') { wdelch(win); refresh(); } pthread_mutex_unlock(&scr_mutex); }
//циклический ввод и отправка сообщений void MessageType(void) { int ch,x,y,i=0;//,j=1; char message[getmaxx(mpanel[2])-1]; while((ch=wgetch(mpanel[2]))!=KEY_F(5)&&end==0) { wrefresh(mpanel[2]); //обработка enter if(ch==10) { GetMessage(message); ClearPanel(2); wmove(mpanel[2],1,1); i=0; ClientSendMsg(message); } else if(ch==KEY_BACKSPACE) { getyx(mpanel[2],y,x); if(x!=1) { wmove(mpanel[2],y,x-1); wdelch(mpanel[2]); box(mpanel[2],0,0); wmove(mpanel[2],0,getmaxx(mpanel[2])/2-13); wprintw(mpanel[2]," Type your message, %ld ",(long)getpid()); wmove(mpanel[2],1,getmaxx(mpanel[2])-2); wprintw(mpanel[2]," "); wmove(mpanel[2],y,x-1); i--; } } else { //не даем печатать за границу if(i>=getmaxx(mpanel[2])-2) { continue; } wprintw(mpanel[2],"%c",ch); i++; } } }
void putch(WINDOW * win, char ch) { if (ch == 4 || ch == 7) // Translate left-arrow, backspace to CTL-H ch = '\b'; if (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\b' && ch != 'å' && ch != 'Å' && ch != 'ä' && ch != 'Ä' && ch != 'ö' && ch != 'Ö' ) { return; } pthread_mutex_lock(&scr_mutex); // Get exclusive access to screen. wechochar(win, (unsigned char)ch); if (ch == '\b') { wdelch(win); refresh(); } pthread_mutex_unlock(&scr_mutex); }
//активаци¤ командной строки void ActivateCMD(void) { int ch,i=0,x,y; char command[getmaxx(cmd)]; ClearPanel(3); wmove(cmd,1,1); curs_set(1); keypad(cmd,1); while((ch=wgetch(cmd))!=10&&i<getmaxx(cmd)) { wrefresh(cmd); if(ch==KEY_BACKSPACE) { getyx(cmd,y,x); if(x!=1) { wmove(cmd,y,x-1); wdelch(cmd); //после удалени¤ символа нужно поправить рамку box(cmd,0,0); wmove(cmd,0,2); wprintw(cmd,"Command line"); wmove(cmd,1,getmaxx(cmd)-2); wprintw(cmd," "); wmove(cmd,y,x-1); i--; } } else { wprintw(cmd,"%c",ch); command[i]=ch; i++; } } ExecuteCMD(command); curs_set(0); wrefresh(cmd); }
char Console::getchar() { noecho(); char c = wgetch(cmd_window); if (c != 127 && c != 8) { if (cmd_curs_x == CMD_WINDOW_STARTX) { cmd_curs_x += 2; } else { cmd_curs_x += 1; } wmove(cmd_window, CMD_WINDOW_STARTY, cmd_curs_x); waddch(cmd_window, c); refresh(); } else if (cmd_curs_x != CMD_WINDOW_STARTX) { wmove(cmd_window, CMD_WINDOW_STARTY, cmd_curs_x); wdelch(cmd_window); cmd_curs_x -= 1; wmove(cmd_window, CMD_WINDOW_STARTY, cmd_curs_x); refresh(); } return c; }
/** * Pop a character from the FIFO into a window * * @v *win window in which to echo input * @ret c char from input stream */ int wgetch ( WINDOW *win ) { int c; c = _wgetc( win ); if ( m_echo ) { if ( c >= KEY_MIN ) { switch(c) { case KEY_LEFT : case KEY_BACKSPACE : _wcursback( win ); wdelch( win ); break; default : beep(); break; } } else { _wputch( win, (chtype)( c | win->attrs ), WRAP ); } } return c; }
/** * Handles what happens if the delete key is pressed. */ static void case_key_dc(volatile struct readline_session_context *ctx) { wchar_t *ptr; const int this_index = ctx->bufpos + 1; if (!ctx->insert_mode) { term_beep(); return; } ptr = &ctx->buffer[this_index]; (void) wmemmove(ptr - 1, ptr, wcslen(ptr)); ctx->buffer[--ctx->n_insert] = 0L; if (wdelch(ctx->act) == ERR || wclrtoeol(ctx->act) == ERR) { readline_error(EPERM, "wdelch or wclrtoeol"); } readline_winsnstr(ctx->act, &ctx->buffer[ctx->bufpos], -1); update_panels(); (void) doupdate(); }
void inputTest(WINDOW *win) { int w, h, bx, by, sw, sh, i, c, num = 0; int line_to_use = 3; char buffer[80]; WINDOW *subWin; static const char spinner[4] = "/-\\|"; int spinner_count = 0; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); } else #endif wbkgd(subWin, A_BOLD); box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); wclear (win); mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); wtimeout(win, 200); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION); PDC_save_key_modifiers(TRUE); // PDC_return_key_modifiers(TRUE); #endif curs_set(0); /* turn cursor off */ while (1) { while (1) { c = wgetch(win); if (c == ERR) { spinner_count++; if (spinner_count == 4) spinner_count = 0; mvwaddch(win, line_to_use, 3, spinner[spinner_count]); wrefresh(win); } else break; } #ifdef PDCURSES // wmove(win, line_to_use + 1, 18); // wclrtoeol(win); #endif mvwaddstr(win, line_to_use, 5, "Key Pressed: "); wclrtoeol(win); wprintw( win, "(%x) ", c); if( has_key( c)) wprintw(win, "%s", keyname(c)); else if (isprint(c) || c > 0xff) waddch( win, c); else wprintw(win, "%s", unctrl(c)); #ifdef PDCURSES if (c == KEY_MOUSE) { int button = 0, status = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else if (BUTTON_CHANGED(4)) /* added 21 Jan 2011: BJG */ button = 4; else if (BUTTON_CHANGED(5)) button = 5; if( button) status = (button > 3 ? Mouse_status.xbutton[(button) - 4] : Mouse_status.button[(button) - 1]); wmove(win, line_to_use, 5); wclrtoeol(win); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) waddstr(win, "moved: "); else if (MOUSE_WHEEL_UP) waddstr(win, "wheel up: "); else if (MOUSE_WHEEL_DOWN) waddstr(win, "wheel dn: "); else if (MOUSE_WHEEL_LEFT) waddstr(win, "wheel lt: "); else if (MOUSE_WHEEL_RIGHT) waddstr(win, "wheel rt: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_PRESSED) waddstr(win, "pressed: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_CLICKED) waddstr(win, "clicked: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) waddstr(win, "double: "); else if ((status & BUTTON_ACTION_MASK) == BUTTON_TRIPLE_CLICKED) waddstr(win, "triple: "); else waddstr(win, "released: "); wprintw(win, "Posn: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); if (button && (status & BUTTON_MODIFIER_MASK)) { if (status & BUTTON_SHIFT) waddstr(win, " SHIFT"); if (status & BUTTON_CONTROL) waddstr(win, " CONTROL"); if (status & BUTTON_ALT) waddstr(win, " ALT"); } } else if (PDC_get_key_modifiers()) { waddstr(win, " Modifier(s):"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT) waddstr(win, " SHIFT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL) waddstr(win, " CONTROL"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT) waddstr(win, " ALT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK) waddstr(win, " NUMLOCK"); } #endif wrefresh(win); if (c == ' ') break; line_to_use++; if( line_to_use == 10) line_to_use = 3; } wtimeout(win, -1); /* turn off timeout() */ curs_set(1); /* turn cursor back on */ #ifdef PDCURSES mouse_set(0L); PDC_save_key_modifiers(FALSE); // PDC_return_key_modifiers(FALSE); #endif wclear(win); mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { mvwprintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); flushinp(); mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); keypad(win, TRUE); raw(); wgetnstr(win, buffer, 3); flushinp(); wmove(win, 9, 10); wdelch(win); mvwaddstr(win, 4, 1, "The character should now have been deleted"); Continue(win); refresh(); wclear(win); echo(); buffer[0] = '\0'; mvwaddstr(win, 3, 2, "The window should have moved"); mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key"); mvwaddstr(win, 6, 2, "Enter a number then a string separated by space"); mvwin(win, 2, 1); wrefresh(win); mvwscanw(win, 7, 6, "%d %s", &num, buffer); mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); Continue(win); refresh(); wclear(win); echo(); mvwaddstr(win, 3, 2, "Enter a 5 character string: "); wgetnstr(win, buffer, 5); mvwprintw(win, 4, 2, "String: %s", buffer); Continue(win); }
std::string Terminal::GetCommand(const int &prev_cmd_return_/*=0*/){ std::string output = ""; sclock::time_point commandRequestTime = sclock::now(); sclock::time_point currentTime; //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } // Check for commands in the command queue. if(!prompt_user && !cmd_queue.empty()){ while(true){ output = cmd_queue.front(); cmd_queue.pop_front(); // Check for blank lines. if(!output.empty()){ break; } } from_script = true; } else{ // Get a command from the user. while(true){ if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV) Close(); return "_SIGSEGV_"; } if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT) SIGNAL_INTERRUPT = false; output = "CTRL_C"; break; } if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP) SIGNAL_TERMSTOP = false; output = "CTRL_Z"; break; } //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } flush(); // If there is anything in the stream, dump it to the screen // Time out if there is no command within the set interval (default 0.5 s). if (commandTimeout_ > 0) { // Update the current time. currentTime = sclock::now(); std::chrono::duration<float> time_span = std::chrono::duration_cast<std::chrono::duration<float>>(currentTime - commandRequestTime); // If the timeout has passed we simply return the empty output string. if (time_span.count() > commandTimeout_) { break; } } int keypress = wgetch(input_window); // Check for internal commands if(keypress == ERR){continue;} // No key was pressed in the interval else if(keypress == 10){ // Enter key (10) std::string temp_cmd = cmd.Get(); //Reset the position in the history. commands.Reset(); if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command commands.Push(temp_cmd); } output = temp_cmd; std::cout << prompt << output << "\n"; flush(); _scrollPosition = 0; clear_(); tabCount = 0; break; } else if(keypress == '\t' && enableTabComplete) { tabCount++; output = cmd.Get().substr(0,cursX - offset) + "\t"; break; } else if(keypress == 4){ // ctrl-d (EOT) output = "CTRL_D"; clear_(); tabCount = 0; break; } else if(keypress == 9){ } // Tab key (9) else if(keypress == KEY_UP){ // 259 if(commands.GetIndex() == 0){ commands.Capture(cmd.Get()); } std::string temp_cmd = commands.GetPrev(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); } } else if(keypress == KEY_DOWN){ // 258 std::string temp_cmd = commands.GetNext(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); } } else if(keypress == KEY_LEFT){ cursX--; } // 260 else if(keypress == KEY_RIGHT){ cursX++; } // 261 else if(keypress == KEY_PPAGE){ //Page up key scroll_(-(_winSizeY-2)); } else if(keypress == KEY_NPAGE){ //Page down key scroll_(_winSizeY-2); } else if(keypress == KEY_BACKSPACE){ // 263 wmove(input_window, 0, --cursX); wdelch(input_window); cmd.Pop(cursX - offset); } else if(keypress == KEY_DC){ // Delete character (330) //Remove character from terminal wdelch(input_window); //Remove character from cmd string cmd.Pop(cursX - offset); } else if(keypress == KEY_IC){ cmd.ToggleInsertMode(); } // Insert key (331) else if(keypress == KEY_HOME){ cursX = offset; } else if(keypress == KEY_END){ cursX = cmd.GetSize() + offset; } else if(keypress == KEY_MOUSE) { //Handle mouse events MEVENT mouseEvent; //Get information about mouse event. getmouse(&mouseEvent); switch (mouseEvent.bstate) { //Scroll up case BUTTON4_PRESSED: scroll_(-3); break; //Scroll down. (Yes the name is strange.) case REPORT_MOUSE_POSITION: scroll_(3); break; } } else if(keypress == KEY_RESIZE) { //Do nothing with the resize key } else{ in_char_((char)keypress); cmd.Put((char)keypress, cursX - offset - 1); } // Check for cursor too far to the left if(cursX < offset){ cursX = offset + cmd.GetSize(); } // Check for cursor too far to the right if(cursX > (int)(cmd.GetSize() + offset)){ cursX = cmd.GetSize() + offset; } if (keypress != ERR) tabCount = 0; update_cursor_(); refresh_(); } if(prompt_user){ // Waiting for user to specify yes or no. if(output != "yes" && output != "y"){ std::cout << prompt << "Aborting execution!\n"; cmd_queue.clear(); } prompt_user = false; return ""; } from_script = false; } // In the event of an empty command, return. if(output.empty()) return ""; // Check for system commands. std::string temp_cmd_string = output.substr(output.find_first_not_of(' '), output.find_first_of(' ')); // Strip the command from the front of the input. std::string temp_arg_string = output.substr(output.find_first_of(' ')+1, output.find_first_of('#')); // Does not ignore leading whitespace. if(temp_cmd_string.empty() || temp_cmd_string[0] == '#'){ // This is a comment line. return ""; } if(temp_cmd_string.substr(0, output.find_first_of(' ')).find('.') != std::string::npos){ if(temp_cmd_string == ".cmd"){ // Load a command script. std::string command_filename = temp_arg_string.substr(output.find_first_not_of(' ')); // Ignores leading whitespace. if(!LoadCommandFile(command_filename.c_str())){ // Failed to load command script. std::cout << prompt << "Error! Failed to load command script " << command_filename << ".\n"; } } else if(temp_cmd_string == ".echo"){ // Print something to the screen. std::cout << prompt << temp_arg_string << std::endl; } else if(temp_cmd_string == ".prompt"){ // Prompt the user with a yes/no question. std::cout << prompt << temp_arg_string << " (yes/no)" << std::endl; prompt_user = true; } else{ // Unrecognized command. std::cout << prompt << "Error! Unrecognized system command " << temp_cmd_string << ".\n"; } return ""; // Done processing the command. Don't need to send it to the caller. } // Print the command if it was read from a script. This is done so that the user // will know what is happening in the script file. It will also ignore system // commands in the file. if(from_script){ std::cout << prompt << output << "\n"; flush(); _scrollPosition = 0; clear_(); tabCount = 0; } return output; }
/* **************************************************************************** * Read input from ncurses window. * * IN: * @window Window where prompt will be printed. * @msg Message prompt. * @pos At deleting wrong input, cursor do not moving beyond that pos. * @len Max allowed length of string. * @echoing Show characters typed by the user. * * OUT: * @with_esc Flag which determines when function finish with ESC. * @str Entered string. **************************************************************************** */ void cmd_readline(WINDOW *window, const char * msg, unsigned int pos, bool * with_esc, char * str, unsigned int len, bool echoing) { int ch; int i = 0; bool done = false; if (echoing) echo(); cbreak(); nodelay(window, FALSE); keypad(window, TRUE); /* show prompt if msg not empty */ if (strlen(msg) != 0) { wprintw(window, "%s", msg); wrefresh(window); } memset(str, 0, len); while (1) { if (done) break; ch = wgetch(window); switch (ch) { case ERR: str[0] = '\0'; flushinp(); done = true; break; case 27: /* Esc */ wclear(window); wprintw(window, "Do nothing. Operation canceled. "); nodelay(window, TRUE); *with_esc = true; str[0] = '\0'; flushinp(); done = true; break; case 10: /* Enter */ str[len] = '\0'; flushinp(); nodelay(window, TRUE); *with_esc = false; /* normal finish with \n */ done = true; break; case 263: case 330: case 127: /* Backspace, Delete, */ if (i > 0) { i--; wdelch(window); continue; } else { wmove(window, 0, pos); continue; } break; default: if (strlen(str) < len + 1) { str[i] = ch; i++; } break; } } noecho(); cbreak(); nodelay(window, TRUE); keypad(window, FALSE); }
void erase_cursor(struct cursor *cursor) { wdelch(cursor->window); wrefresh(cursor->window); }
std::string Terminal::GetCommand(){ std::string output = ""; time_t commandRequestTime; time_t currentTime; time(&commandRequestTime); //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } while(true){ if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV) Close(); return "_SIGSEGV_"; } if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT) SIGNAL_INTERRUPT = false; output = "CTRL_C"; text_length = 0; break; } else if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP) SIGNAL_TERMSTOP = false; output = "CTRL_Z"; text_length = 0; break; } flush(); // If there is anything in the stream, dump it to the screen //Time out if there is no command within the set interval (default 0.5 s). if (commandTimeout_ > 0) { time(¤tTime); //If the timeout has passed we simply return the empty output string. if (currentTime > commandRequestTime + commandTimeout_) { break; } } int keypress = wgetch(input_window); // Check for internal commands if(keypress == ERR){ } // No key was pressed in the interval else if(keypress == 10){ // Enter key (10) std::string temp_cmd = cmd.Get(); //Reset the position in the history. commands.Reset(); if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command commands.Push(temp_cmd); } output = temp_cmd; std::cout << prompt << output << "\n"; flush(); text_length = 0; _scrollPosition = 0; clear_(); tabCount = 0; break; } else if(keypress == '\t' && enableTabComplete) { tabCount++; output = cmd.Get().substr(0,cursX - offset) + "\t"; break; } else if(keypress == 4){ // ctrl-d (EOT) output = "CTRL_D"; text_length = 0; clear_(); tabCount = 0; break; } else if(keypress == 9){ } // Tab key (9) else if(keypress == KEY_UP){ // 259 if(commands.GetIndex() == 0){ commands.Capture(cmd.Get()); } std::string temp_cmd = commands.GetPrev(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); text_length = cmd.GetSize(); } } else if(keypress == KEY_DOWN){ // 258 std::string temp_cmd = commands.GetNext(); if(temp_cmd != "NULL"){ clear_(); cmd.Set(temp_cmd); in_print_(cmd.Get().c_str()); text_length = cmd.GetSize(); } } else if(keypress == KEY_LEFT){ cursX--; } // 260 else if(keypress == KEY_RIGHT){ cursX++; } // 261 else if(keypress == KEY_PPAGE){ //Page up key scroll_(-(_winSizeY-2)); } else if(keypress == KEY_NPAGE){ //Page down key scroll_(_winSizeY-2); } else if(keypress == KEY_BACKSPACE){ // 263 wmove(input_window, 0, --cursX); wdelch(input_window); cmd.Pop(cursX - offset); text_length = cmd.GetSize(); } else if(keypress == KEY_DC){ // Delete character (330) //Remove character from terminal wdelch(input_window); //Remove character from cmd string cmd.Pop(cursX - offset); text_length = cmd.GetSize(); } else if(keypress == KEY_IC){ cmd.ToggleInsertMode(); } // Insert key (331) else if(keypress == KEY_HOME){ cursX = offset; } else if(keypress == KEY_END){ cursX = text_length + offset; } else if(keypress == KEY_MOUSE) { //Handle mouse events MEVENT mouseEvent; //Get information about mouse event. getmouse(&mouseEvent); switch (mouseEvent.bstate) { //Scroll up case BUTTON4_PRESSED: scroll_(-3); break; //Scroll down. (Yes the name is strange.) case REPORT_MOUSE_POSITION: scroll_(3); break; } } else if(keypress == KEY_RESIZE) { //Do nothing with the resize key } else{ in_char_((char)keypress); cmd.Put((char)keypress, cursX - offset - 1); text_length = cmd.GetSize(); } // Check for cursor too far to the left if(cursX < offset){ cursX = offset; } // Check for cursor too far to the right if(cursX > (text_length + offset)){ cursX = text_length + offset; } //Update status message if (status_window) { werase(status_window); print(status_window,statusStr.at(0).c_str()); } if (keypress != ERR) tabCount = 0; update_cursor_(); refresh_(); } return output; }
int chkr_wdelch(WINDOW *win) { CHECK_WIN(win); return(wdelch(win)); }
static void inputTest(WINDOW *win) { int answered; int repeat; int w, h, bx, by, sw, sh, i, c, num; char buffer[80]; WINDOW *subWin; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD); } else wbkgd(subWin, A_BOLD); #else wbkgd(subWin, A_BOLD); #endif box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); MvWAddStr(win, 2, 1, "Press some keys for 5 seconds"); MvWAddStr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { MvWPrintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); MvWAddStr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); noraw(); wgetch(win); flushinp(); wmove(win, 9, 10); wdelch(win); MvWAddStr(win, 4, 1, "The character should now have been deleted"); Continue(win); wclear(win); MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); MvWAddStr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); #if HAVE_TYPEAHEAD typeahead(-1); #endif #ifdef NCURSES_MOUSE_VERSION mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); #endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win); if (c >= KEY_MIN) wprintw(win, "Key Pressed: %s", keyname(c)); else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #ifdef KEY_MOUSE if (c == KEY_MOUSE) { #if defined(NCURSES_MOUSE_VERSION) #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) MEVENT event; int button = 0; getmouse(&event); if (ButtonChanged(1)) button = 1; else if (ButtonChanged(2)) button = 2; else if (ButtonChanged(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (ButtonPressed(button)) wprintw(win, "pressed: "); else if (ButtonDouble(button)) wprintw(win, "double: "); else if (ButtonTriple(button)) wprintw(win, "triple: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", event.y, event.x); #elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) wprintw(win, "moved: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) wprintw(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) wprintw(win, "double: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); #endif /* NCURSES_VERSION vs PDCURSES */ } #endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; } #if 0 nodelay(win, TRUE); wgetch(win); nodelay(win, FALSE); #endif #if defined(PDCURSES) mouse_set(0L); #endif refresh(); repeat = 0; do { static const char *fmt[] = { "%d %10s", "%d %[a-zA-Z]s", "%d %[][a-zA-Z]s", "%d %[^0-9]" }; char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]); wclear(win); MvWAddStr(win, 3, 2, "The window should have moved"); MvWAddStr(win, 4, 2, "This text should have appeared without you pressing a key"); MvWPrintw(win, 6, 2, "Scanning with format \"%s\"", format); mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); erase(); refresh(); wrefresh(win); echo(); noraw(); num = 0; *buffer = 0; answered = mvwscanw(win, 7, 6, format, &num, buffer); MvWPrintw(win, 8, 6, "String: %s Number: %d (%d values read)", buffer, num, answered); Continue(win); ++repeat; free(format); } while (answered > 0); }
int sc_deleteChar() { return (wdelch(stdscr) != ERR); }
/* * delch -- * Do a delete-char on the line, leaving (cury, curx) unchanged. */ int delch(void) { return wdelch(stdscr); }
int main(int argc, char** argv){ int port,sd,row,col,crow,ccol,ctcol; char buffer[BUFFSIZE],tmp[BUFFSIZE]; char username[MAXUSERSIZE],*user;//samething temp holder variable if(argc!=4){ fprintf(stderr,"Usage: %s takes 3 arguments a server, a portname, and a username", argv[0]); exit(EXIT_FAILURE); } port= atoi(argv[2]); bzero(username,MAXUSERSIZE); memcpy(username,argv[3],strlen(argv[3])); user=username; // their_addr.sin_family=AF_INET; // their_addr.sin_port = htons(port); //if(!inet_aton(argv[1], &their_addr.sin_addr.s_addr)){ // fprintf(stderr,"%s requires a valid server address", argv[0]); // exit(EXIT_FAILURE); //} struct addrinfo* ai,*ac; struct addrinfo hints; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = 0; hints.ai_protocol = port; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; if(getaddrinfo(argv[1],argv[2],NULL,&ai)<0){ close(sd); fprintf(stderr,"please input a vaild server!\n",argv[1]); exit(EXIT_FAILURE); } for (ac = ai; ac != NULL; ac = ac->ai_next) { sd = socket(AF_INET, SOCK_DGRAM,0); fcntl(sd, F_SETFL, O_NONBLOCK); if (sd == -1) continue; if (connect(sd, ac->ai_addr, ac->ai_addrlen) != -1) break; /* Success */ close(sd); } // their_addr.sin_addr.s_addr=ai.ai_addr; // memset(&(their_addr.sin_zero),'\0',8); //char host[NI_MAXHOST],service[NI_MAXSERV]; WINDOW *chat_win,*text_win,*user_win; // if(connect(sd,ai->ai_addr,ai->ai_addrlen)){ // close(sd); // fprintf(stderr,"Failed to connect to %s!\n",argv[1]); // exit(EXIT_FAILURE); // }else{ initscr(); crow=1; ccol=2; ctcol=2; getmaxyx(stdscr,row,col); chat_win=create_newwin(row-3,col-30,0,0); user_win=create_newwin(row-2,col,0,col-30); text_win=create_newwin(3,col,row-3,0); scrollok(chat_win, TRUE); idlok(chat_win,TRUE); scrollok(text_win, TRUE); noecho(); if(sd!=-1){ mvwprintw(chat_win,crow++,ccol,"connected to server %s",argv[1]); wrefresh(chat_win); }else{ mvwprintw(chat_win,crow++,ccol,"couldn't connect to server %s ... exiting",argv[1]); wrefresh(chat_win); sleep(1); delwin(text_win); delwin(chat_win); delwin(user_win); endwin(); return 0; } // } int bsize=BUFFSIZE; int nread; //send user name to server bzero(buffer,BUFFSIZE); bzero(tmp,BUFFSIZE); memcpy(buffer,username,strlen(username)); send(sd,buffer,strlen(username),0); int i=0; int j; char c; int getusers=1; wmove(text_win,1,ctcol); wrefresh(text_win); while(1){ bzero(buffer,BUFFSIZE); if(kbhit()){ c=getchar(); if(c=='\r') continue; tmp[i]=c; i++; mvwaddch(text_win,1,ctcol,c); wrefresh(text_win); ctcol++; while(1){ if(kbhit()){ c=getchar(); if(c=='\r') break; if(c==(char)127||c==(char)8){ if(i>0){ ctcol--; wmove(text_win,1,ctcol); wdelch(text_win); wrefresh(text_win); tmp[i]='\0'; i--; } continue; } if(i>BUFFSIZE) continue; tmp[i]=c; i++; mvwaddch(text_win,1,ctcol,c); wrefresh(text_win); ctcol++; } if((nread=recvp(chat_win,&crow,ccol,col-28,user_win,user,sd,buffer,BUFFSIZE,0))!=-1){ wmove(text_win,1,ctcol); wrefresh(text_win); } } } if(i>0){ if(memcmp(tmp,"clear\0",6)==0){ wmove(chat_win,1,ccol); wclrtobot(chat_win); box(chat_win, 0 , 0); wrefresh(chat_win); box(text_win,0,0); wrefresh(text_win); crow=1; ccol=1; }else{ send(sd,tmp,i,0); } wmove(text_win,1,0); wclrtoeol(text_win); wrefresh(text_win); ctcol=1; i=0; bzero(tmp,BUFFSIZE); } if((nread=recvp(chat_win,&crow,ccol,col-28,user_win,user,sd,buffer,BUFFSIZE,0))!=-1){ wmove(text_win,1,ctcol); wrefresh(text_win); if(memcmp(buffer,"close\0",6)==0){ sleep(1); break; } //onetime thing if(getusers){ getusers=0; memcpy(tmp,":users:",7); send(sd,tmp,7,0); bzero(tmp,BUFFSIZE); } } } close(sd); delwin(text_win); delwin(chat_win); delwin(user_win); endwin(); return 0; }
EIF_INTEGER c_ecurses_wdelch (EIF_POINTER w) { return wdelch((WINDOW *) w); };
NCURSES_EXPORT(int) (mvwdelch) (WINDOW * a1, int a2, int z) { T((T_CALLED("mvwdelch(%p,%d,%d)"), (const void *)a1, a2, z)); returnCode((wmove(a1,a2,z) == (-1) ? (-1) : wdelch(a1))); }
int delch(void) { PDC_LOG(("delch() - called\n")); return wdelch(stdscr); }