mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Up to now, the tab completion logic has only examined the last few words of the current input line; "last few" being originally as few as four words, but lately up to nine words. Furthermore, it only looked at what libreadline considers the current line of input, which made it rather myopic if you split your command across lines. This was tolerable, sort of, so long as the match patterns were only designed to consider the last few words of input; but with the recent addition of HeadMatches() and Matches() matching rules, we really have to do better if we want those to behave sanely. Hence, change the code to break the entire line down into words, and to include any previous lines in the command buffer along with the active readline input buffer. This will be a little bit slower than the previous coding, but some measurements say that even a query of several thousand characters can be parsed in a hundred or so microseconds on modern machines; so it's really not going to be significant for interactive tab completion. To reduce the cost some, I arranged to avoid the per-word malloc calls that used to occur: all the words are now kept in one malloc'd buffer.
52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
/*
|
|
* psql - the PostgreSQL interactive terminal
|
|
*
|
|
* Copyright (c) 2000-2015, PostgreSQL Global Development Group
|
|
*
|
|
* src/bin/psql/input.h
|
|
*/
|
|
#ifndef INPUT_H
|
|
#define INPUT_H
|
|
|
|
/*
|
|
* If some other file needs to have access to readline/history, include this
|
|
* file and save yourself all this work.
|
|
*
|
|
* USE_READLINE is what to conditionalize readline-dependent code on.
|
|
*/
|
|
#ifdef HAVE_LIBREADLINE
|
|
#define USE_READLINE 1
|
|
|
|
#if defined(HAVE_READLINE_READLINE_H)
|
|
#include <readline/readline.h>
|
|
#if defined(HAVE_READLINE_HISTORY_H)
|
|
#include <readline/history.h>
|
|
#endif
|
|
#elif defined(HAVE_EDITLINE_READLINE_H)
|
|
#include <editline/readline.h>
|
|
#if defined(HAVE_EDITLINE_HISTORY_H)
|
|
#include <editline/history.h>
|
|
#endif
|
|
#elif defined(HAVE_READLINE_H)
|
|
#include <readline.h>
|
|
#if defined(HAVE_HISTORY_H)
|
|
#include <history.h>
|
|
#endif
|
|
#endif /* HAVE_READLINE_READLINE_H, etc */
|
|
#endif /* HAVE_LIBREADLINE */
|
|
|
|
#include "pqexpbuffer.h"
|
|
|
|
|
|
extern char *gets_interactive(const char *prompt, PQExpBuffer query_buf);
|
|
extern char *gets_fromFile(FILE *source);
|
|
|
|
extern void initializeInput(int flags);
|
|
|
|
extern bool printHistory(const char *fname, unsigned short int pager);
|
|
|
|
extern void pg_append_history(const char *s, PQExpBuffer history_buf);
|
|
extern void pg_send_history(PQExpBuffer history_buf);
|
|
|
|
#endif /* INPUT_H */
|