JSBool Window_printChar (JSContext* cx, JSObject* object, uintN argc, jsval* argv, jsval* rval) { if (argc < 1) { JS_ReportError(cx, "Not enough parameters."); return JS_FALSE; } JS_BeginRequest(cx); JS_EnterLocalRootScope(cx); WINDOW* win = (WINDOW*) JS_GetPrivate(cx, object); jsint ch; JS_ValueToInt32(cx, argv[0], &ch); if (argc == 1){ waddch(win, ch); } else if (argc == 2) { JSObject* options; JS_ValueToObject(cx, argv[1], &options); jsval x, y; JS_GetProperty(cx, options, "x", &x); if (JSVAL_IS_VOID(x) || JSVAL_IS_NULL(x)) { JS_GetProperty(cx, options, "X", &x); } JS_GetProperty(cx, options, "y", &y); if (JSVAL_IS_VOID(y) || JSVAL_IS_NULL(y)) { JS_GetProperty(cx, options, "Y", &y); } jsval jsEcho; JS_GetProperty(cx, options, "echo", &jsEcho); JSBool echo; JS_ValueToBoolean(cx, jsEcho, &echo); __Window_options(cx, win, options, JS_TRUE); if (echo) { wechochar(win, ch); } else if (!JSVAL_IS_INT(x) && !JSVAL_IS_INT(y)) { waddch(win, ch); } else { mvwaddch(win, JSVAL_IS_INT(y) ? JSVAL_TO_INT(y) : 0, JSVAL_IS_INT(x) ? JSVAL_TO_INT(x) : 0, ch ); } __Window_options(cx, win, options, JS_FALSE); } JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_TRUE; }
int pechochar(WINDOW *pad, chtype ch) { WINDOW *padwin; int rv; /* * If pad->_padwin exists(meaning that p*refresh have been * previously called), call wechochar on it. Otherwise, call * wechochar on the pad itself */ if ((padwin = pad->_padwin) != NULL) { padwin->_cury = pad->_cury - padwin->_pary; padwin->_curx = pad->_curx - padwin->_parx; rv = wechochar(padwin, ch); pad->_cury = padwin->_cury + padwin->_pary; pad->_curx = padwin->_curx + padwin->_parx; return (rv); } else return (wechochar(pad, ch)); }
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); }
pechochar(WINDOW *pad, const chtype ch) { T((T_CALLED("pechochar(%p, %s)"), (void *) pad, _tracechtype(ch))); if (pad == 0) returnCode(ERR); if (!(pad->_flags & _ISPAD)) returnCode(wechochar(pad, ch)); waddch(pad, ch); prefresh(pad, pad->_pad._pad_y, pad->_pad._pad_x, pad->_pad._pad_top, pad->_pad._pad_left, pad->_pad._pad_bottom, pad->_pad._pad_right); returnCode(OK); }
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); }
char *ask_user(char *fmt, ...) { va_list ap; va_start(ap, fmt); miniprintf(fmt, ap); va_end(ap); char *s = zalloc(255); int c = 0; int i = 0; if (s == NULL) fail("Unable to allocate memory at __FILE__:__LINE__\n"); do { c = wgetch(minibuffer_win); wechochar(minibuffer_win, c); s[i] = c; i++; } while (i < 255 && c != '\n'); return s; }
wgetn_wstr(WINDOW *win, wint_t *str, int maxlen) { SCREEN *sp = _nc_screen_of(win); TTY buf; bool oldnl, oldecho, oldraw, oldcbreak; wint_t erasec; wint_t killc; wint_t *oldstr = str; wint_t *tmpstr = str; wint_t ch; int y, x, code; T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen)); if (!win) returnCode(ERR); _nc_get_tty_mode(&buf); oldnl = sp->_nl; oldecho = sp->_echo; oldraw = sp->_raw; oldcbreak = sp->_cbreak; nl(); noecho(); noraw(); cbreak(); erasec = (wint_t) erasechar(); killc = (wint_t) killchar(); getyx(win, y, x); if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); while ((code = wget_wch(win, &ch)) != ERR) { /* * Map special characters into key-codes. */ if (ch == '\r') ch = '\n'; if (ch == '\n') { code = KEY_CODE_YES; ch = KEY_ENTER; } if (ch < KEY_MIN) { if (ch == erasec) { ch = KEY_BACKSPACE; code = KEY_CODE_YES; } if (ch == killc) { ch = KEY_EOL; code = KEY_CODE_YES; } } if (code == KEY_CODE_YES) { /* * Some terminals (the Wyse-50 is the most common) generate a \n * from the down-arrow key. With this logic, it's the user's * choice whether to set kcud=\n for wget_wch(); terminating * *getn_wstr() with \n should work either way. */ if (ch == KEY_DOWN || ch == KEY_ENTER) { if (oldecho == TRUE && win->_cury == win->_maxy && win->_scroll) wechochar(win, (chtype) '\n'); break; } if (ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (tmpstr > oldstr) { tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho); } } else if (ch == KEY_EOL) { while (tmpstr > oldstr) { tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho); } } else { beep(); } } else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) { beep(); } else { *tmpstr++ = ch; *tmpstr = 0; if (oldecho == TRUE) { int oldy = win->_cury; if (wadd_wint(win, tmpstr - 1) == ERR) { /* * We can't really use the lower-right corner for input, * since it'll mess up bookkeeping for erases. */ win->_flags &= ~_WRAPPED; waddch(win, (chtype) ' '); tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho); continue; } else if (win->_flags & _WRAPPED) { /* * If the last waddch forced a wrap & scroll, adjust our * reference point for erasures. */ if (win->_scroll && oldy == win->_maxy && win->_cury == win->_maxy) { if (--y <= 0) { y = 0; } } win->_flags &= ~_WRAPPED; } wrefresh(win); } } } win->_curx = 0; win->_flags &= ~_WRAPPED; if (win->_cury < win->_maxy) win->_cury++; wrefresh(win); /* Restore with a single I/O call, to fix minor asymmetry between * raw/noraw, etc. */ sp->_nl = oldnl; sp->_echo = oldecho; sp->_raw = oldraw; sp->_cbreak = oldcbreak; (void) _nc_set_tty_mode(&buf); *tmpstr = 0; if (code == ERR) { if (tmpstr == oldstr) { *tmpstr++ = WEOF; *tmpstr = 0; } returnCode(ERR); } T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr))); returnCode(OK); }
_nc_wgetch(WINDOW *win, unsigned long *result, int use_meta EVENTLIST_2nd(_nc_eventlist * evl)) { int ch; #ifdef NCURSES_WGETCH_EVENTS long event_delay = -1; #endif T((T_CALLED("_nc_wgetch(%p)"), win)); *result = 0; if (win == 0 || SP == 0) returnCode(ERR); if (cooked_key_in_fifo()) { if (wgetch_should_refresh(win)) wrefresh(win); *result = fifo_pull(); returnCode(OK); } #ifdef NCURSES_WGETCH_EVENTS if (evl && (evl->count == 0)) evl = NULL; event_delay = _nc_eventlist_timeout(evl); #endif /* * Handle cooked mode. Grab a string from the screen, * stuff its contents in the FIFO queue, and pop off * the first character to return it. */ if (head == -1 && !SP->_notty && !SP->_raw && !SP->_cbreak && !SP->_called_wgetch) { char buf[MAXCOLUMNS], *sp; int rc; TR(TRACE_IEVENT, ("filling queue in cooked mode")); SP->_called_wgetch = TRUE; rc = wgetnstr(win, buf, MAXCOLUMNS); SP->_called_wgetch = FALSE; /* ungetch in reverse order */ #ifdef NCURSES_WGETCH_EVENTS if (rc != KEY_EVENT) #endif ungetch('\n'); for (sp = buf + strlen(buf); sp > buf; sp--) ungetch(sp[-1]); #ifdef NCURSES_WGETCH_EVENTS /* Return it first */ if (rc == KEY_EVENT) { *result = rc; returnCode(OK); } #endif *result = fifo_pull(); returnCode(OK); } if (win->_use_keypad != SP->_keypad_on) _nc_keypad(win->_use_keypad); if (wgetch_should_refresh(win)) wrefresh(win); if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { int delay; TR(TRACE_IEVENT, ("timed delay in wgetch()")); if (SP->_cbreak > 1) delay = (SP->_cbreak - 1) * 100; else delay = win->_delay; #ifdef NCURSES_WGETCH_EVENTS if (event_delay >= 0 && delay > event_delay) delay = event_delay; #endif TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); if (head == -1) { /* fifo is empty */ int rc = check_mouse_activity(delay EVENTLIST_2nd(evl)); #ifdef NCURSES_WGETCH_EVENTS if (rc & 4) { *result = KEY_EVENT; returnCode(OK); } #endif if (!rc) returnCode(ERR); } /* else go on to read data available */ } if (win->_use_keypad) { /* * This is tricky. We only want to get special-key * events one at a time. But we want to accumulate * mouse events until either (a) the mouse logic tells * us it's picked up a complete gesture, or (b) * there's a detectable time lapse after one. * * Note: if the mouse code starts failing to compose * press/release events into clicks, you should probably * increase the wait with mouseinterval(). */ int runcount = 0; int rc; do { ch = kgetch(EVENTLIST_1st(evl)); if (ch == KEY_MOUSE) { ++runcount; if (SP->_mouse_inline(SP)) break; } if (SP->_maxclick < 0) break; } while (ch == KEY_MOUSE && (((rc = check_mouse_activity(SP->_maxclick EVENTLIST_2nd(evl))) != 0 && !(rc & 4)) || !SP->_mouse_parse(runcount))); #ifdef NCURSES_WGETCH_EVENTS if ((rc & 4) && !ch == KEY_EVENT) { ungetch(ch); ch = KEY_EVENT; } #endif if (runcount > 0 && ch != KEY_MOUSE) { #ifdef NCURSES_WGETCH_EVENTS /* mouse event sequence ended by an event, report event */ if (ch == KEY_EVENT) { ungetch(KEY_MOUSE); /* FIXME This interrupts a gesture... */ } else #endif { /* mouse event sequence ended by keystroke, store keystroke */ ungetch(ch); ch = KEY_MOUSE; } } } else { if (head == -1) fifo_push(EVENTLIST_1st(evl)); ch = fifo_pull(); } if (ch == ERR) { #if USE_SIZECHANGE if (SP->_sig_winch) { _nc_update_screensize(); /* resizeterm can push KEY_RESIZE */ if (cooked_key_in_fifo()) { *result = fifo_pull(); returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK); } } #endif returnCode(ERR); } /* * If echo() is in effect, display the printable version of the * key on the screen. Carriage return and backspace are treated * specially by Solaris curses: * * If carriage return is defined as a function key in the * terminfo, e.g., kent, then Solaris may return either ^J (or ^M * if nonl() is set) or KEY_ENTER depending on the echo() mode. * We echo before translating carriage return based on nonl(), * since the visual result simply moves the cursor to column 0. * * Backspace is a different matter. Solaris curses does not * translate it to KEY_BACKSPACE if kbs=^H. This does not depend * on the stty modes, but appears to be a hardcoded special case. * This is a difference from ncurses, which uses the terminfo entry. * However, we provide the same visual result as Solaris, moving the * cursor to the left. */ if (SP->_echo && !(win->_flags & _ISPAD)) { chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch; if (backup < KEY_MIN) wechochar(win, backup); } /* * Simulate ICRNL mode */ if ((ch == '\r') && SP->_nl) ch = '\n'; /* Strip 8th-bit if so desired. We do this only for characters that * are in the range 128-255, to provide compatibility with terminals * that display only 7-bit characters. Note that 'ch' may be a * function key at this point, so we mustn't strip _those_. */ if (!use_meta) if ((ch < KEY_MIN) && (ch & 0x80)) ch &= 0x7f; T(("wgetch returning : %s", _tracechar(ch))); *result = ch; returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK); }
void cursesxx::Widget::put( char c ) { wechochar( this->window.get(), c ); }
wgetnstr_events(WINDOW *win, char *str, int maxlen, EVENTLIST_1st(_nc_eventlist * evl)) { SCREEN *sp = _nc_screen_of(win); TTY buf; bool oldnl, oldecho, oldraw, oldcbreak; char erasec; char killc; char *oldstr; int ch; int y, x; T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); if (!win) returnCode(ERR); _nc_get_tty_mode(&buf); oldnl = sp->_nl; oldecho = sp->_echo; oldraw = sp->_raw; oldcbreak = sp->_cbreak; nl(); noecho(); noraw(); cbreak(); erasec = erasechar(); killc = killchar(); oldstr = str; getyx(win, y, x); if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); while ((ch = wgetch_events(win, evl)) != ERR) { /* * Some terminals (the Wyse-50 is the most common) generate * a \n from the down-arrow key. With this logic, it's the * user's choice whether to set kcud=\n for wgetch(); * terminating *getstr() with \n should work either way. */ if (ch == '\n' || ch == '\r' || ch == KEY_DOWN || ch == KEY_ENTER) { if (oldecho == TRUE && win->_cury == win->_maxy && win->_scroll) wechochar(win, (chtype) '\n'); break; } #ifdef KEY_EVENT if (ch == KEY_EVENT) break; #endif #ifdef KEY_RESIZE if (ch == KEY_RESIZE) break; #endif if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (str > oldstr) { str = WipeOut(win, y, x, oldstr, str, oldecho); } } else if (ch == killc) { while (str > oldstr) { str = WipeOut(win, y, x, oldstr, str, oldecho); } } else if (ch >= KEY_MIN || (maxlen >= 0 && str - oldstr >= maxlen)) { beep(); } else { *str++ = (char) ch; if (oldecho == TRUE) { int oldy = win->_cury; if (waddch(win, (chtype) ch) == ERR) { /* * We can't really use the lower-right * corner for input, since it'll mess * up bookkeeping for erases. */ win->_flags &= ~_WRAPPED; waddch(win, (chtype) ' '); str = WipeOut(win, y, x, oldstr, str, oldecho); continue; } else if (win->_flags & _WRAPPED) { /* * If the last waddch forced a wrap & * scroll, adjust our reference point * for erasures. */ if (win->_scroll && oldy == win->_maxy && win->_cury == win->_maxy) { if (--y <= 0) { y = 0; } } win->_flags &= ~_WRAPPED; } wrefresh(win); } } } win->_curx = 0; win->_flags &= ~_WRAPPED; if (win->_cury < win->_maxy) win->_cury++; wrefresh(win); /* Restore with a single I/O call, to fix minor asymmetry between * raw/noraw, etc. */ sp->_nl = oldnl; sp->_echo = oldecho; sp->_raw = oldraw; sp->_cbreak = oldcbreak; _nc_set_tty_mode(&buf); *str = '\0'; if (ch == ERR) returnCode(ch); T(("wgetnstr returns %s", _nc_visbuf(oldstr))); #ifdef KEY_EVENT if (ch == KEY_EVENT) returnCode(ch); #endif #ifdef KEY_RESIZE if (ch == KEY_RESIZE) returnCode(ch); #endif returnCode(OK); }
// WINDOW *echowindow points to the window that processes the input // basically it's input_win during the game and stdscr before the game screen is loaded bool todd_getline(char **line, size_t *len, WINDOW *echowindow) { // curs_set displays a nice cursor for user convenience curs_set(1); chat_typing = 1; bool ret = false; size_t buf_len = 20; *line = malloc(buf_len); *len = 0; unsigned char c; do { bool rc = todd_getchar(&c); if (!rc || c == '\t') { // pressing TAB (\t) when in input mode is supposed to toggle chat // // however, pressing TAB when logging in (typing name or password) // would cause the program to quit // -> don't accept TAB when logging in // echowindow == input_win either when // todd_getline is called with input_win // OR they are both NULL (when logging in) // therefore, those two cases can't be true at the same time if (echowindow == input_win && input_win != NULL) { free(*line); *line = NULL; *len = 0; goto cleanup; } continue; // don't accept TAB unless in input_win, just skip it } if (c == '\b') // it's a backspace, go back a character { // if echowindow is NULL it means we're asking for the password // in this case, make backspace work int password = 0; if (echowindow == NULL) { password = 1; echowindow = stdscr; } // don't backspace on an empty string or the pointer will cause a segfault if ((*len) != 0) { // if it's a multibyte (scandic letters, § and so on) // len -1 and len -2 have negative values int multibyte = 0; if ((*line)[*len - 1] < 0) multibyte = 1; int y,x; // get current position of cursor to y and x getyx(echowindow,y,x); // move the cursor left by one wmove(echowindow, y,x-1); // blank it from screen and from buffer wechochar(echowindow, ' '); (*line)[*len] = '\0'; (*len)--; if (multibyte) // there's two chars in buffer, not one { (*line)[*len] = '\0'; (*len)--; } // by calling wechochar, the cursor moves right. move it back wmove(echowindow, y,x-1); wrefresh(echowindow); // if this was in the password field, change echowindow back to original value if (password) echowindow = NULL; } } else // it's just a normal character { if (buf_len <= *len) { buf_len += 20; *line = realloc(*line, buf_len); } (*line)[*len] = c; (*len)++; // echo the character, except when echowindow is NULL echo a * to stdscr // this is a hack: echowindow is NULL only when asking for a password // also, don't echo a \r if (echowindow == NULL && c != '\r') wechochar(stdscr, '*'); else if (c != '\r') // without this, todd_getline would eat the "Halt! who goes there" -message // when asking for player name wechochar(echowindow, c); } } while (c != '\r'); (*len)--; // strip trailing newline (*line)[*len] = '\0'; // insert null terminator curs_set(0); if (*len == 0) // it's an empty string.. return false; // else, return true ret = true; cleanup: if (echowindow == input_win) { werase(echowindow); wrefresh(echowindow); } chat_typing = 0; curs_set(0); return ret; }
bool handleInput(int sock, struct addrinfo * p) { int charRead; while(true) { if(timeForKeepAlive) { sendKeepAlivePacket(sock, p); timeForKeepAlive = false; } handleNetwork(sock, p); charRead = wgetch(inputWnd); if(charRead == 127 && nchars > 0) { int cy, cx; getyx(inputWnd, cy, cx); mvwaddch(inputWnd, cy, cx-1, ' '); wmove(inputWnd, cy, cx-1); line[nchars] = '\0'; --nchars; return true; } else if(charRead >= 32 && charRead <= 126 && nchars < MAXLINE) { wechochar(inputWnd, charRead); line[nchars] = charRead; refreshAll(); ++nchars; return true; } else if(charRead == '\n') { if(strncmp(line, "/exit", std::max(nchars, MAXLINE+1)) == 0) { return false; } else if(strncmp(line, "/join ", 6) == 0) { sendJoinPacket(sock, p, &(line[6])); memset(curChannel, '\0', CHANNEL_MAX+1); strncpy(curChannel, &(line[6]), CHANNEL_MAX); channelsJoined.insert(curChannel); } else if(strncmp(line, "/switch ", 8) == 0) { char chanName[CHANNEL_MAX+1]; memset(chanName, '\0', CHANNEL_MAX+1); strncpy(chanName, &(line[8]), CHANNEL_MAX); if(channelsJoined.count(chanName) > 0) { strncpy(curChannel, chanName, CHANNEL_MAX); } else { char err[256]; snprintf(err, 256, "you have not subscribed to channel %.32s", chanName); printErrorMsg(err); } } else if(strncmp(line, "/leave ", 7) == 0) { sendLeavePacket(sock, p, &(line[7])); memset(curChannel, '\0', CHANNEL_MAX+1); strncpy(curChannel, &(line[7]), CHANNEL_MAX); channelsJoined.erase(curChannel); memset(curChannel, '\0', CHANNEL_MAX); } else if(strncmp(line, "/list", 5) == 0) { sendListPacket(sock, p); } else if(strncmp(line, "/who ", 5) == 0) { sendWhoPacket(sock, p, &(line[5])); } else if(line[0] == '/') { printErrorMsg("unrecognized command"); } else if(curChannel[0] != '\0'){ sendSayPacket(sock, p, curChannel, line); } //wprintw(wnd, "%s\n", line); memset(line, '\0', MAXLINE+1); clearInput(); return true; } }; }
WRAP_API int wrap_wechochar(WINDOW *win, unsigned int ch) { return wechochar(win, ch); }
int echochar(const chtype ch) { PDC_LOG(("echochar() - called: ch=%x\n", ch)); return wechochar(stdscr, ch); }
//------------------------------------------------------------------------------ int echochar( const chtype ch ) { __QCS_FCONTEXT( "echochar" ); return wechochar( stdscr, ch ); }
EIF_INTEGER c_ecurses_wechochar (EIF_POINTER w, EIF_INTEGER ch) { return wechochar( ((WINDOW *) w) , (chtype)ch) ; };
/* * echochar -- * Echo character and attributes on stdscr and refresh stdscr. */ int echochar(const chtype ch) { return wechochar(stdscr, ch); }
int wgetch(WINDOW *win) { int ch; T((T_CALLED("wgetch(%p)"), win)); if (!win) returnCode(ERR); if (cooked_key_in_fifo()) { if (wgetch_should_refresh(win)) wrefresh(win); ch = fifo_pull(); T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); returnCode(ch); } /* * Handle cooked mode. Grab a string from the screen, * stuff its contents in the FIFO queue, and pop off * the first character to return it. */ if (head == -1 && !SP->_raw && !SP->_cbreak) { char buf[MAXCOLUMNS], *sp; TR(TRACE_IEVENT, ("filling queue in cooked mode")); wgetnstr(win, buf, MAXCOLUMNS); /* ungetch in reverse order */ ungetch('\n'); for (sp = buf + strlen(buf); sp > buf; sp--) ungetch(sp[-1]); returnCode(fifo_pull()); } if (wgetch_should_refresh(win)) wrefresh(win); if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { int delay; TR(TRACE_IEVENT, ("timed delay in wgetch()")); if (SP->_cbreak > 1) delay = (SP->_cbreak - 1) * 100; else delay = win->_delay; TR(TRACE_IEVENT, ("delay is %d milliseconds", delay)); if (head == -1) /* fifo is empty */ if (!_nc_timed_wait(3, delay, (int *) 0)) returnCode(ERR); /* else go on to read data available */ } if (win->_use_keypad) { /* * This is tricky. We only want to get special-key * events one at a time. But we want to accumulate * mouse events until either (a) the mouse logic tells * us it's picked up a complete gesture, or (b) * there's a detectable time lapse after one. * * Note: if the mouse code starts failing to compose * press/release events into clicks, you should probably * increase the wait with mouseinterval(). */ int runcount = 0; do { ch = kgetch(win); if (ch == KEY_MOUSE) { ++runcount; if (SP->_mouse_inline(SP)) break; } } while (ch == KEY_MOUSE && (_nc_timed_wait(3, SP->_maxclick, (int *) 0) || !SP->_mouse_parse(runcount))); if (runcount > 0 && ch != KEY_MOUSE) { /* mouse event sequence ended by keystroke, push it */ ungetch(ch); ch = KEY_MOUSE; } } else { if (head == -1) fifo_push(); ch = fifo_pull(); } if (ch == ERR) { #if USE_SIZECHANGE if (SP->_sig_winch) { _nc_update_screensize(); /* resizeterm can push KEY_RESIZE */ if (cooked_key_in_fifo()) { ch = fifo_pull(); T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch))); returnCode(ch); } } #endif T(("wgetch returning ERR")); returnCode(ERR); } /* * If echo() is in effect, display the printable version of the * key on the screen. Carriage return and backspace are treated * specially by Solaris curses: * * If carriage return is defined as a function key in the * terminfo, e.g., kent, then Solaris may return either ^J (or ^M * if nonl() is set) or KEY_ENTER depending on the echo() mode. * We echo before translating carriage return based on nonl(), * since the visual result simply moves the cursor to column 0. * * Backspace is a different matter. Solaris curses does not * translate it to KEY_BACKSPACE if kbs=^H. This does not depend * on the stty modes, but appears to be a hardcoded special case. * This is a difference from ncurses, which uses the terminfo entry. * However, we provide the same visual result as Solaris, moving the * cursor to the left. */ if (SP->_echo && !(win->_flags & _ISPAD)) { chtype backup = (ch == KEY_BACKSPACE) ? '\b' : ch; if (backup < KEY_MIN) wechochar(win, backup); } /* * Simulate ICRNL mode */ if ((ch == '\r') && SP->_nl) ch = '\n'; /* Strip 8th-bit if so desired. We do this only for characters that * are in the range 128-255, to provide compatibility with terminals * that display only 7-bit characters. Note that 'ch' may be a * function key at this point, so we mustn't strip _those_. */ if ((ch < KEY_MIN) && (ch & 0x80)) if (!SP->_use_meta) ch &= 0x7f; T(("wgetch returning : %#x = %s", ch, _trace_key(ch))); returnCode(ch); }
NCURSES_EXPORT(int) (echochar) (const chtype z) { T((T_CALLED("echochar(%s)"), _tracechtype2(0,z))); returnCode(wechochar(stdscr,z)); }