]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improvements to the way \x works so that it can be used to change
authordrh <>
Fri, 10 Apr 2026 00:55:40 +0000 (00:55 +0000)
committerdrh <>
Fri, 10 Apr 2026 00:55:40 +0000 (00:55 +0000)
the prompt color.  This really messes with linenoise, though.

FossilOrigin-Name: bbee56f970ade40734c8a278f46d8a268b305fe349c3739c977fa9141d2c3b6a

manifest
manifest.uuid
src/shell.c.in

index 997b4f4cf19419ea2eddc29fc3c9f716cac8bfc0..a9c024d8301f7d36ecdf03a975d307069be4b580 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C A\sprototype\sof\scode\sthat\sshows\show\sto\sexpand\sbackslash\sescapes\sin\sthe\nCLI\sprompt.
-D 2026-04-09T23:37:48.087
+C Improvements\sto\sthe\sway\s&#92;x\sworks\sso\sthat\sit\scan\sbe\sused\sto\schange\nthe\sprompt\scolor.\s\sThis\sreally\smesses\swith\slinenoise,\sthough.
+D 2026-04-10T00:55:40.521
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -735,7 +735,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c ffe199f025a0dd74670d2a77232bdea364a4d7b36f32c64a6572d39ba6a11576
-F src/shell.c.in 35f99690f368ef171713cbccd89efef382944e4b85396bdb78e6995636e278b3
+F src/shell.c.in 2bbbb04153354fe3d11677d69ce7b6d5bfe8113e2d3693791915590eaa4f1bce
 F src/sqlite.h.in e2915e4a86d5e0783afb5cb72411df38d987c7f3c5aa2d5441b8e74d30b649d8
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 1b7a0ee438bb5c2896d0609c537e917d8057b3340f6ad004d2de44f03e3d3cca
@@ -2197,8 +2197,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P 39f6c5a8a7d91e03f89b13496e333b9500977a2cbcc0c27ba14dfb87dc81e678
-R d2a4bc02232fb4db2f52e0b9d98461ba
+P 9cf28959671920b4909521bb1db6f0cbbc85448fbf3594c43b4000505b4e055b
+R 1af695b623ae09a49f6867ddfb6fa639
 U drh
-Z f5b6fe9da177b5e89ebf6c4cb7c9f5ea
+Z 856f286521a626031b862b8cbac557c5
 # Remove this line to create a well-formed Fossil manifest.
index 3544fb98a026194b6f2f24f32ca0581144113377..e75a3aba4b466d040b3ecf86a985d6dbc4012185 100644 (file)
@@ -1 +1 @@
-9cf28959671920b4909521bb1db6f0cbbc85448fbf3594c43b4000505b4e055b
+bbee56f970ade40734c8a278f46d8a268b305fe349c3739c977fa9141d2c3b6a
index 88956da8415f36de42a64714954c6a7f82b279c2..86eb9bd620d6af0ea14814e91e4da64e87c7e1e9 100644 (file)
@@ -939,10 +939,11 @@ static char *expand_prompt(
   sqlite3_str *pOut = sqlite3_str_new(0);
   int i;
   char c;
+  int onoff = 1;
   for(i=0; zPrompt[i]; i++){
     if( zPrompt[i]!='\\' ) continue;
     if( i>0 ){
-      sqlite3_str_append(pOut, zPrompt, i);
+      if( onoff ) sqlite3_str_append(pOut, zPrompt, i);
       zPrompt += i;
       i = 0;
     }
@@ -965,39 +966,74 @@ static char *expand_prompt(
       while( i<=2 && zPrompt[i+1]>='0' && zPrompt[i+1]<='7' ){
         v = v*8 + zPrompt[++i] - '0';
       }
-      sqlite3_str_appendchar(pOut, 1, v);
+      if( onoff ) sqlite3_str_appendchar(pOut, 1, v);
       zPrompt += i+1;
       i = -1;
       continue;
     }
+    if( c=='e' ){
+      /* \e is \033 "Escape" */
+      if( onoff ) sqlite3_str_append(pOut, "\033", 1);
+      zPrompt += 2;
+      i = -1;
+      continue;
+    }
+
+    /* The intent of the following codes it to provide alternative
+    ** text displays depending on whether or not the connection is
+    ** currently in a transaction.  Example 1:  Show a "*" before the ">"
+    ** like psql:
+    **
+    **         .prompt 'sqlite\x*\;> '
+    **
+    ** Example 2: Show database filename is blue if not in a transaction,
+    ** or red if within a transaction:
+    **
+    **         .prompt '\e[1;\x31\:34\;m\f>\e[0m '
+    */
+    if( c==':' ){
+      /* toggle display on/off */
+      onoff = !onoff;
+      zPrompt += 2;
+      i = -1;
+      continue;
+    }
+    if( c==';' ){
+      /* Turn display on */
+      onoff = 1;
+      zPrompt += 2;
+      i = -1;
+      continue;
+    }
     if( c=='x' ){
-      /* \x becomes "*" if in a transaction and nothing if not */
-      if( p->db && !sqlite3_get_autocommit(p->db) ){
-        sqlite3_str_append(pOut, "*", 1);
-      }
+      /* \x turns display off not in a transaction, on if in txn */
+      onoff = p->db && !sqlite3_get_autocommit(p->db);
       zPrompt += 2;
       i = -1;
       continue;
     }
+
     if( c=='f' || c=='F' || c=='~' ){
       /* \f becomes the tail of the database filename */
       /* \F becomes the full pathname */
       /* \~ becomes the full pathname relative to $HOME */
-      sqlite3_filename pFN = p->db ? sqlite3_db_filename(p->db,0) : 0;
-      const char *zFN;
-      if( pFN && (zFN = sqlite3_filename_database(pFN))!=0 ){
-        if( c=='f' ){
-          const char *zTail = strrchr(zFN,'/');
-          if( zTail && zTail[1] ) zFN = &zTail[1];
-        }else if( c=='~' ){
-          const char *zHOME = getenv("HOME");
-          size_t nHOME = zHOME ? strlen(zHOME) : 0;
-          if( nHOME<strlen(zFN) && memcmp(zHOME,zFN,nHOME)==0 ){
-            sqlite3_str_append(pOut,"~",1);
-            zFN += nHOME;
+      if( onoff ){
+        sqlite3_filename pFN = p->db ? sqlite3_db_filename(p->db,0) : 0;
+        const char *zFN = pFN ? sqlite3_filename_database(pFN) : ":memory:";
+        if( zFN ){
+          if( c=='f' ){
+            const char *zTail = strrchr(zFN,'/');
+            if( zTail && zTail[1] ) zFN = &zTail[1];
+          }else if( c=='~' ){
+            const char *zHOME = getenv("HOME");
+            size_t nHOME = zHOME ? strlen(zHOME) : 0;
+            if( nHOME<strlen(zFN) && memcmp(zHOME,zFN,nHOME)==0 ){
+              sqlite3_str_append(pOut,"~",1);
+              zFN += nHOME;
+            }
           }
+          sqlite3_str_appendall(pOut, zFN);
         }
-        sqlite3_str_appendall(pOut, zFN);
       }
       zPrompt += 2;
       i = -1;
@@ -1005,11 +1041,11 @@ static char *expand_prompt(
     }
 
     /* No match to a known escape.  Generate an error. */
-    sqlite3_str_appendf(pOut,"UNKNOWN(\"\\%c\")",c);
+    if( onoff ) sqlite3_str_appendf(pOut,"UNKNOWN(\"\\%c\")",c);
     zPrompt += 2;
     i = -1;
   }
-  if( i>0 ){
+  if( i>0 && onoff ){
     sqlite3_str_append(pOut, zPrompt, i);
   }
   return sqlite3_str_finish(pOut);