/ Check-in [03bbb947]
Login

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

Overview
Comment:Add support for the linenoise command-line editing library in shell.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 03bbb947192b0c28d960604eae12e5fc2fa6e74e
User & Date: drh 2015-02-25 13:48:10
Context
2015-02-25
14:25
Make sure the sqlite3_mutex.id field is initialized in the Win32 mutex implementation, even when SQLITE_DEBUG is turned off. check-in: 6d132e7a user: drh tags: trunk
14:09
Merge the latest trunk fixes and enhancements into the apple-osx branch. check-in: ba8294e2 user: drh tags: apple-osx
14:02
Merge the latest trunk fixes into the sessions branch. check-in: 131a2d31 user: drh tags: sessions
13:48
Add support for the linenoise command-line editing library in shell.c. check-in: 03bbb947 user: drh tags: trunk
10:54
Add support for linenoise to shell.c. Closed-Leaf check-in: f7f2598c user: dan tags: linenoise
01:06
When cleaning with MSVC, prevent superfluous output regarding 'missing' files and directories. check-in: 034c16bd user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

    55     55   # include <sys/types.h>
    56     56   #endif
    57     57   
    58     58   #if HAVE_READLINE
    59     59   # include <readline/readline.h>
    60     60   # include <readline/history.h>
    61     61   #endif
           62  +
    62     63   #if HAVE_EDITLINE
    63         -# undef HAVE_READLINE
    64         -# define HAVE_READLINE 1
    65     64   # include <editline/readline.h>
    66     65   #endif
    67         -#if !HAVE_READLINE
    68         -# define add_history(X)
    69         -# define read_history(X)
    70         -# define write_history(X)
    71         -# define stifle_history(X)
           66  +
           67  +#if HAVE_EDITLINE || HAVE_READLINE
           68  +
           69  +# define shell_add_history(X) add_history(X)
           70  +# define shell_read_history(X) read_history(X)
           71  +# define shell_write_history(X) write_history(X)
           72  +# define shell_stifle_history(X) stifle_history(X)
           73  +# define shell_readline(X) readline(X)
           74  +
           75  +#elif HAVE_LINENOISE
           76  +
           77  +# include "linenoise.h"
           78  +# define shell_add_history(X) linenoiseHistoryAdd(X)
           79  +# define shell_read_history(X) linenoiseHistoryLoad(X)
           80  +# define shell_write_history(X) linenoiseHistorySave(X)
           81  +# define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
           82  +# define shell_readline(X) linenoise(X)
           83  +
           84  +#else
           85  +
           86  +# define shell_read_history(X) 
           87  +# define shell_write_history(X)
           88  +# define shell_stifle_history(X)
           89  +
           90  +# define SHELL_USE_LOCAL_GETLINE 1
    72     91   #endif
           92  +
    73     93   
    74     94   #if defined(_WIN32) || defined(WIN32)
    75     95   # include <io.h>
    76     96   # include <fcntl.h>
    77     97   #define isatty(h) _isatty(h)
    78     98   #ifndef access
    79     99   # define access(f,m) _access((f),(m))
................................................................................
   447    467   static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
   448    468     char *zPrompt;
   449    469     char *zResult;
   450    470     if( in!=0 ){
   451    471       zResult = local_getline(zPrior, in);
   452    472     }else{
   453    473       zPrompt = isContinuation ? continuePrompt : mainPrompt;
   454         -#if HAVE_READLINE
   455         -    free(zPrior);
   456         -    zResult = readline(zPrompt);
   457         -    if( zResult && *zResult ) add_history(zResult);
   458         -#else
          474  +#if SHELL_USE_LOCAL_GETLINE
   459    475       printf("%s", zPrompt);
   460    476       fflush(stdout);
   461    477       zResult = local_getline(zPrior, stdin);
          478  +#else
          479  +    free(zPrior);
          480  +    zResult = shell_readline(zPrompt);
          481  +    if( zResult && *zResult ) shell_add_history(zResult);
   462    482   #endif
   463    483     }
   464    484     return zResult;
   465    485   }
   466    486   
   467    487   /*
   468    488   ** Shell output mode information from before ".explain on", 
................................................................................
  4632   4652         zHome = find_home_dir();
  4633   4653         if( zHome ){
  4634   4654           nHistory = strlen30(zHome) + 20;
  4635   4655           if( (zHistory = malloc(nHistory))!=0 ){
  4636   4656             sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
  4637   4657           }
  4638   4658         }
  4639         -#if HAVE_READLINE
  4640         -      if( zHistory ) read_history(zHistory);
  4641         -#endif
         4659  +      if( zHistory ) shell_read_history(zHistory);
  4642   4660         rc = process_input(&data, 0);
  4643   4661         if( zHistory ){
  4644         -        stifle_history(100);
  4645         -        write_history(zHistory);
         4662  +        shell_stifle_history(100);
         4663  +        shell_write_history(zHistory);
  4646   4664           free(zHistory);
  4647   4665         }
  4648   4666       }else{
  4649   4667         rc = process_input(&data, stdin);
  4650   4668       }
  4651   4669     }
  4652   4670     set_table_name(&data, 0);
  4653   4671     if( data.db ){
  4654   4672       sqlite3_close(data.db);
  4655   4673     }
  4656   4674     sqlite3_free(data.zFreeOnClose); 
  4657   4675     return rc;
  4658   4676   }