/** * Regular handling of a key-press. */ static void handle_key(volatile struct readline_session_context *ctx, wint_t wc) { if (ctx->no_bufspc) { term_beep(); return; } if (hiLim_isset(ctx->act)) { magic_swap_panels(ctx, true); } if (ctx->insert_mode) { wchar_t *ptr = &ctx->buffer[ctx->bufpos]; struct current_cursor_pos yx; (void) wmemmove(ptr + 1, ptr, wcslen(ptr)); *ptr = wc; ctx->bufpos++, ctx->n_insert++; readline_winsch(ctx->act, wc); yx = term_get_pos(ctx->act); if (wmove(ctx->act, yx.cury, yx.curx + 1) == ERR) { readline_error(EPERM, "wmove"); } } else { ctx->buffer[ctx->bufpos] = wc; ctx->bufpos++, ctx->n_insert++; readline_waddch(ctx->act, wc); } update_panels(); (void) doupdate(); }
/* * Ring the bell if ring-bell is set. */ void ding (void) { if (thisflag & FLAG_DEFINING_MACRO) cancel_kbd_macro (); if (get_variable_bool ("ring-bell")) term_beep (); }
void write_string(char *s, int cnt) { int i; char *p; for(i = 0, p = s; i <= cnt; ++i) { switch(*p) { case BELL_CHAR: if(GET_BIT(options, DO_BELLS)) { term_beep(1); } else { if(!term_standout_status()) { term_standout_on(); term_putchar(*p + 'A' - 1); term_standout_off(); } else { term_putchar(*p + 'A' - 1); } } ++p; break; case BOLD_CHAR: term_toggle_boldface(); ++p; break; case INVERSE_CHAR: term_toggle_standout(); ++p; break; case UNDERLINE_CHAR: term_toggle_underline(); ++p; break; default: term_putchar(*p); ++p; break; } } }
/** * 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(); }
/** * 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(); }
/** * Key right */ static void case_key_right(volatile struct readline_session_context *ctx) { struct current_cursor_pos yx; if (!ctx->insert_mode) { term_beep(); return; } if (hiLim_isset(ctx->act)) { magic_swap_panels(ctx, true); } ctx->bufpos++; yx = term_get_pos(ctx->act); if (wmove(ctx->act, yx.cury, yx.curx + 1) == ERR) { readline_error(EPERM, "wmove"); } update_panels(); (void) doupdate(); }
/** * Key left */ static void case_key_left(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); } ctx->bufpos--; yx = term_get_pos(ctx->act); if (wmove(ctx->act, yx.cury, yx.curx - 1) == ERR) { readline_error(EPERM, "wmove"); } update_panels(); (void) doupdate(); }
/* * edit_char: handles each character for an input stream. Not too difficult * to work out. */ void edit_char(u_char key) { void (*func) (char, char *) = NULL; char *ptr = NULL; u_char extended_key; WaitPrompt *oldprompt; int meta_hit = 0, meta_not_hit; int i; /* were we waiting for a keypress? */ if (current_screen->promptlist && current_screen->promptlist->type == WAIT_PROMPT_KEY) { char key_[2] = "\0"; key_[0] = key; oldprompt = current_screen->promptlist; (*oldprompt->func) (oldprompt->data, key_); set_input(empty_str); current_screen->promptlist = oldprompt->next; new_free(&oldprompt->data); new_free(&oldprompt->prompt); new_free(&oldprompt); change_input_prompt(-1); return; } extended_key = key; /* Check to see if its an eight bit char and if we allow it */ if (!get_int_var(EIGHT_BIT_CHARACTERS_VAR)) key &= 0x7f; /* mask out non-ascii crap */ /* Check to see if this is a meta-key */ for (i = 1; i <= 9; i++) { if (current_screen->meta_hit[i]) { if (keys[i][key]) { func = key_names[keys[i][key]->key_index].func; ptr = keys[i][key]->stuff; } current_screen->meta_hit[i] = 0; meta_hit = 1; break; } } if (!meta_hit) { if (keys[0][key]) { func = key_names[keys[0][key]->key_index].func; ptr = keys[0][key]->stuff; } } /* is there a meta key that isnt still outstanding? */ meta_not_hit = 1; for (i = 1; i <= 3; i++) meta_not_hit = meta_not_hit && !current_screen->meta_hit[i]; for (i = 5; i <= 9; i++) meta_not_hit = meta_not_hit && !current_screen->meta_hit[i]; if (meta_not_hit) { /* did we just hit the quote character? */ if (current_screen->quote_hit) { current_screen->quote_hit = 0; input_add_character(extended_key, empty_str); } /* nope. none of these. just a regular character */ else if (func) func(extended_key, ptr ? ptr : empty_str); } else term_beep(); /* two metas in a row gets a beep */ }