void line_edit_autocomplete::show_completions() { if (!m_completer_enabled) return; QString prefix; // substring on which the completion is to be based int pos = cursorPosition(); int start = get_prefix_pos(text(), pos); if (start>=0) { prefix=text().mid(start, pos-start); } if (prefix.isEmpty()) { // nothing to complete if (popup->isVisible()) { popup->clear(); popup->hide(); } } else { QList<QString> completions = get_completions(prefix); redisplay_popup(completions); } }
void option_proposer::suggest_completion (const char *option_prefix) { auto_string_vec results; get_completions (option_prefix, results); for (unsigned i = 0; i < results.length (); i++) printf ("%s\n", results[i]); }
void completion(const char *buf, linenoiseCompletions *lc) { int num_completions = 0; char **completions = get_completions(global_ctx, buf, &num_completions); for (int i = 0; i < num_completions; i++) { linenoiseAddCompletion(lc, completions[i]); free(completions[i]); } free(completions); }
/** * @brief Reads a whole line from the input channel. * @note Input chars are echoed on the same stream object with the * following exceptions: * - DEL and BS are echoed as BS-SPACE-BS. * - CR is echoed as CR-LF. * - 0x4 is echoed as "^D". * - Other values below 0x20 are not echoed. * . * * @param[in] scfg pointer to a @p ShellConfig object * @param[in] line pointer to the line buffer * @param[in] size buffer maximum length * @param[in] shp pointer to a @p ShellHistory object or NULL * @return The operation status. * @retval true the channel was reset or CTRL-D pressed. * @retval false operation successful. * * @api */ bool shellGetLine(ShellConfig *scfg, char *line, unsigned size, ShellHistory *shp) { char *p = line; BaseSequentialStream *chp = scfg->sc_channel; #if SHELL_USE_ESC_SEQ == TRUE bool escape = false; bool bracket = false; #endif #if SHELL_USE_HISTORY != TRUE (void) shp; #endif while (true) { char c; if (streamRead(chp, (uint8_t *)&c, 1) == 0) return true; #if SHELL_USE_ESC_SEQ == TRUE if (c == 27) { escape = true; continue; } if (escape) { escape = false; if (c == '[') { escape = true; bracket = true; continue; } if (bracket) { bracket = false; #if SHELL_USE_HISTORY == TRUE if (c == 'A') { int len = get_history(shp, line, SHELL_HIST_DIR_BK); if (len > 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } if (c == 'B') { int len = get_history(shp, line, SHELL_HIST_DIR_FW); if (len == 0) *line = 0; if (len >= 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } #endif } continue; } #endif #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_) if (c == 4) { chprintf(chp, "^D"); return true; } #endif if ((c == 8) || (c == 127)) { if (p != line) { streamPut(chp, 0x08); streamPut(chp, 0x20); streamPut(chp, 0x08); p--; } continue; } if (c == '\r') { chprintf(chp, SHELL_NEWLINE_STR); #if SHELL_USE_HISTORY == TRUE save_history(shp, line, p - line); #endif *p = 0; return false; } #if SHELL_USE_COMPLETION == TRUE if (c == '\t') { if (p < line + size - 1) { *p = 0; get_completions(scfg, line); int len = process_completions(scfg, line, p - line, size); if (len > 0) { write_completions(scfg, line, p - line); p = line + len; } } continue; } #endif #if SHELL_USE_HISTORY == TRUE if (c == 14) { int len = get_history(shp, line, SHELL_HIST_DIR_FW); if (len == 0) *line = 0; if (len >= 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } if (c == 16) { int len = get_history(shp, line, SHELL_HIST_DIR_BK); if (len > 0) { _shell_reset_cur(chp); _shell_clr_line(chp); chprintf(chp, "%s", line); p = line + len; } continue; } #endif if (c < 0x20) continue; if (p < line + size - 1) { streamPut(chp, c); *p++ = (char)c; } } }