]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
CLI improvement: New command-line option "--cmdline-edit BOOLEAN" to
authordrh <>
Thu, 23 Jul 2026 12:12:37 +0000 (12:12 +0000)
committerdrh <>
Thu, 23 Jul 2026 12:12:37 +0000 (12:12 +0000)
enable/disable command-line editing.  Command-line editing is disabled
by default if either stdin or stdout is not a tty.

FossilOrigin-Name: 675ed9a486fecc734a6aad2e80fd800183c33f72dce1435a193f0e4cf4ede944

manifest
manifest.uuid
src/shell.c.in

index 9c13a0835a6cd33c4501a6d21f9e8300e3501bfa..aa9388367d6909f9be167279d944745f73b3b357 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\serror\shandling\scase\sin\s#base64.
-D 2026-07-22T14:16:33.877
+C CLI\simprovement:\s\sNew\scommand-line\soption\s"--cmdline-edit\sBOOLEAN"\sto\nenable/disable\scommand-line\sediting.\s\sCommand-line\sediting\sis\sdisabled\nby\sdefault\sif\seither\sstdin\sor\sstdout\sis\snot\sa\stty.
+D 2026-07-23T12:12:37.978
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -743,7 +743,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 54395ee97eb710e695202d4112cf2b1c1c7767a57afcea745df71abb1c917768
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 586ccc75f2fa289c51554330f9ff549d00dae4122ac7e2af712437e2ef737cc8
-F src/shell.c.in ce9ef76da7cc153afaa6aa233a155be885859f41c803a20bdc42d1c628b8ccab
+F src/shell.c.in 0df571dd1eae1a15577361902eb5487a072d3290ea94e1e72e757050b641f870
 F src/sqlite.h.in 2101a2b494cbc282d0dc1c3f631c4fb83060c52876cc9d7615b091ad66d932b1
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 0efd4723bad9124ea1f581d9f1ea0254ac1c6f3e5fb29e4f3dcf36c72485a456
@@ -2217,8 +2217,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P 1e90bedec99054f4856bfb89efc4d676486504db67bd1304c45d14c638ddfc7e
-R 4ba1df6437fed061f1eb71312c47e6fe
-U stephan
-Z c36e942c267e89119f3168abed8a1ce3
+P f8c408f66257881937ed18b77e274f71dba2d97dd44546372fa0b0a9629efbd2
+R bad555b624f4fd2230e93ef522552de4
+U drh
+Z 924a5276b6b3c8953d98d053fbac0712
 # Remove this line to create a well-formed Fossil manifest.
index 71f83d14361037e6101384d41e75ff15caeec487..6a72c5b5736a121e7f3e8492afd3a18307beaacb 100644 (file)
@@ -1 +1 @@
-f8c408f66257881937ed18b77e274f71dba2d97dd44546372fa0b0a9629efbd2
+675ed9a486fecc734a6aad2e80fd800183c33f72dce1435a193f0e4cf4ede944
index 6a73f2e8449b4314fd554a6adbbc178f7fe6e3e9..f71f92653bff0c0a1ee8bf23cec4704f4c11dd4e 100644 (file)
@@ -164,6 +164,7 @@ typedef unsigned char u8;
 # define shell_write_history(X) write_history(X)
 # define shell_stifle_history(X) stifle_history(X)
 # define shell_readline(X) readline(X)
+# define SHELL_CMDLINE_EDIT_AVAILABLE 1  /* command-line editing available */
 
 #elif HAVE_LINENOISE
 
@@ -173,16 +174,25 @@ typedef unsigned char u8;
 # define shell_write_history(X) linenoiseHistorySave(X)
 # define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
 # define shell_readline(X) linenoise(X)
+# define SHELL_CMDLINE_EDIT_AVAILABLE 1  /* command-line editing available */
 
 #else
 
 # define shell_read_history(X)
 # define shell_write_history(X)
 # define shell_stifle_history(X)
-
-# define SHELL_USE_LOCAL_GETLINE 1
+# define SHELL_CMDLINE_EDIT_AVAILABLE 0  /* command-line editing not available */
 #endif
 
+/*
+** Global variable shellCmdLineEdit determines whether or not command-line
+** editing is enabled.  It defaults to 1 if the CLI is linked against a
+** command-line editing library (linenoise, readline, or editline) and
+** to 0 if no command-line editing library is available.  The
+** "--cmdline-edit off" command-line option will change this value to 0.
+*/
+static int shellCmdLineEdit = SHELL_CMDLINE_EDIT_AVAILABLE;
+
 #ifndef deliberate_fall_through
 /* Quiet some compilers about some of our intentional code. */
 # if defined(GCC_VERSION) && GCC_VERSION>=7000000
@@ -911,7 +921,7 @@ static char *local_getline(char *zLine, FILE *in){
   int nLine = zLine==0 ? 0 : 100;
   int n = 0;
 
-  while( 1 ){
+  while( seenInterrupt<2 ){
     if( n+100>nLine ){
       if( nLine>=1073741773 ){
         free(zLine);
@@ -1464,26 +1474,29 @@ static char *one_input_line(
     const char *zBase = prompt_string(p, bContinue!=0);
     char *zPrompt = expand_prompt(p, zAll, zBase);
     shell_check_oom(zPrompt);
-#if SHELL_USE_LOCAL_GETLINE
-    sputz(stdout, zPrompt);
-    fflush(stdout);
-    do{
-      zResult = local_getline(zPrior, stdin);
-      zPrior = 0;
-      /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
-      if( zResult==0 ) sqlite3_sleep(50);
-    }while( zResult==0 && seenInterrupt>0 );
-#else
-    free(zPrior);
-    zResult = shell_readline(zPrompt);
-    while( zResult==0 ){
-      /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
-      sqlite3_sleep(50);
-      if( seenInterrupt==0 ) break;
-      zResult = shell_readline("");
-    }
-    if( zResult && *zResult ) shell_add_history(zResult);
+#if SHELL_CMDLINE_EDIT_AVAILABLE
+    if( shellCmdLineEdit ){
+      free(zPrior);
+      zResult = shell_readline(zPrompt);
+      while( zResult==0 ){
+        /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
+        sqlite3_sleep(50);
+        if( seenInterrupt==0 ) break;
+        zResult = shell_readline("");
+      }
+      if( zResult && *zResult ) shell_add_history(zResult);
+    }else
 #endif
+    {
+      sputz(stdout, zPrompt);
+      fflush(stdout);
+      do{
+        zResult = local_getline(zPrior, stdin);
+        zPrior = 0;
+        /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
+        if( zResult==0 ) sqlite3_sleep(50);
+      }while( zResult==0 && seenInterrupt>0 );
+    }
     sqlite3_free(zPrompt);
   }
   return zResult;
@@ -13525,6 +13538,7 @@ static const char zOptions[] =
   "   -batch               force batch I/O\n"
   "   -box                 set '.mode box'\n"
   "   -cmd COMMAND         run \"COMMAND\" before reading stdin\n"
+  "   -cmdline-edit BOOL   enable or disable command-line editing\n"
   "   -column              set '.mode column'\n"
   "   -csv                 set '.mode csv -limits off'\n"
 #if !defined(SQLITE_OMIT_DESERIALIZE)
@@ -13795,6 +13809,9 @@ int SQLITE_CDECL main(int argc, char **argv){
 #else
   stdin_is_interactive = isatty(0);
   stdout_is_console = isatty(1);
+  if( !stdin_is_interactive || !stdout_is_console ){
+    shellCmdLineEdit = 0;
+  }
 #endif
   atexit(abnormalExit);
 #ifdef SQLITE_DEBUG
@@ -14042,6 +14059,8 @@ int SQLITE_CDECL main(int argc, char **argv){
     }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){
       /* skip over the argument */
       i++;
+    }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
+      shellCmdLineEdit = booleanValue(cmdline_option_value(argc,argv,++i));
     }else if( cli_strcmp(z,"-test-argv")==0 ){
       /* Undocumented test option.  Print the values in argv[] and exit.
       ** Use this to verify that any translation of the argv[], for example
@@ -14304,6 +14323,8 @@ int SQLITE_CDECL main(int argc, char **argv){
     }else if( cli_strcmp(z,"-multiplex")==0 ){
       i++;
 #endif
+    }else if( cli_strcmp(z,"-cmdline-edit")==0 ){
+      i+=2;
     }else if( cli_strcmp(z,"-help")==0 ){
       usage(1);
     }else if( cli_strcmp(z,"-cmd")==0 ){