/ Check-in [c906739f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tab-completion now also works using readline/editline.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental-namelist
Files: files | file ages | folders
SHA3-256: c906739f0c1046b57a8c6d4aa32dbfbb4c59a8d94eb87243bf5135c665492129
User & Date: drh 2017-07-06 20:08:17
Context
2017-07-06
22:40
Always load the schema before starting tab-completion. check-in: 907fd3aa user: drh tags: experimental-namelist
20:08
Tab-completion now also works using readline/editline. check-in: c906739f user: drh tags: experimental-namelist
19:26
Use the sqlite3_namelist() interface to implement simple tab-completion using linenoise. check-in: 5cc7b0e2 user: drh tags: experimental-namelist
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  3595   3595                               sha3QueryFunc, 0, 0);
  3596   3596       sqlite3_create_function(p->db, "shell_add_schema", 2, SQLITE_UTF8, 0,
  3597   3597                               shellAddSchemaName, 0, 0);
  3598   3598                               
  3599   3599     }
  3600   3600   }
  3601   3601   
  3602         -#ifdef HAVE_LINENOISE
         3602  +#if HAVE_READLINE || HAVE_EDITLINE
         3603  +/*
         3604  +** Readline completion callbacks
         3605  +*/
         3606  +static char *readline_completion_generator(const char *text, int state){
         3607  +  static char **azCompletions = 0;
         3608  +  static int iCompletion = 0;
         3609  +  char *zRet;
         3610  +  if( state==0 ){
         3611  +    sqlite3_free(azCompletions);
         3612  +    azCompletions = sqlite3_namelist(globalDb, text, -1, 0);
         3613  +    iCompletion = 0;
         3614  +  }
         3615  +  zRet = azCompletions[iCompletion++];
         3616  +  if( zRet==0 ){
         3617  +    sqlite3_free(azCompletions);
         3618  +    azCompletions = 0;
         3619  +  }else{
         3620  +    zRet = strdup(zRet);
         3621  +  }
         3622  +  return zRet;
         3623  +}
         3624  +static char **readline_completion(const char *zText, int iStart, int iEnd){
         3625  +  rl_attempted_completion_over = 1;
         3626  +  return rl_completion_matches(zText, readline_completion_generator);
         3627  +}
         3628  +
         3629  +#elif HAVE_LINENOISE
  3603   3630   /*
  3604   3631   ** Linenoise completion callback
  3605   3632   */
  3606   3633   static void linenoise_completion(const char *zLine, linenoiseCompletions *lc){
  3607   3634     int nLine = (int)strlen(zLine);
  3608   3635     int i, n, iStart;
  3609   3636     char **az;
................................................................................
  7661   7688         if( zHome ){
  7662   7689           nHistory = strlen30(zHome) + 20;
  7663   7690           if( (zHistory = malloc(nHistory))!=0 ){
  7664   7691             sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
  7665   7692           }
  7666   7693         }
  7667   7694         if( zHistory ){ shell_read_history(zHistory); }
  7668         -#ifdef HAVE_LINENOISE
         7695  +#if HAVE_READLINE || HAVE_EDITLINE
         7696  +      rl_attempted_completion_function = readline_completion;
         7697  +#elif HAVE_LINENOISE
  7669   7698         linenoiseSetCompletionCallback(linenoise_completion);
  7670   7699   #endif
  7671   7700         rc = process_input(&data, 0);
  7672   7701         if( zHistory ){
  7673   7702           shell_stifle_history(100);
  7674   7703           shell_write_history(zHistory);
  7675   7704           free(zHistory);