]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Honor the NO_COLOR environment variable. If NO_COLOR is set and
authordrh <>
Mon, 4 May 2026 10:14:13 +0000 (10:14 +0000)
committerdrh <>
Mon, 4 May 2026 10:14:13 +0000 (10:14 +0000)
SQLITE_PS1 and SQLITE_PS2 are not set, then the default prompt is
monochrome and ANSI escapes are omitted.  Also change the name of
the SQLITE_PS_NOANSI compile-time option to SQLITE_NO_COLOR.

FossilOrigin-Name: 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb

manifest
manifest.uuid
src/shell.c.in

index f2b665ce8dc848bef5f04797ef0ab4fd9e00d6af..2309847f30cdbf430b68bc3ddbd8a2f3d6c8decd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C New\stest\scases\sfor\sthe\sshell\sprompt
-D 2026-05-03T18:31:49.934
+C Honor\sthe\sNO_COLOR\senvironment\svariable.\s\sIf\sNO_COLOR\sis\sset\sand\nSQLITE_PS1\sand\sSQLITE_PS2\sare\snot\sset,\sthen\sthe\sdefault\sprompt\sis\nmonochrome\sand\sANSI\sescapes\sare\somitted.\s\sAlso\schange\sthe\sname\sof\nthe\sSQLITE_PS_NOANSI\scompile-time\soption\sto\sSQLITE_NO_COLOR.
+D 2026-05-04T10:14:13.819
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -736,7 +736,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c fcc406bfb055bee9954ee77c023f4a2a66a24bcdf1573516a72280811a269c20
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 4c05cde130f26991b7411d8c6809e0630625e18078742c963a047b4b9cc01d49
-F src/shell.c.in e0eb5d8c91b0fa29dc25b4511e46c28d800a11e94d8763a58610983e4a120810
+F src/shell.c.in 23c17a6f73d3fb3ed9e0ddcaa9994e8ad521ae9b5d1fb1d1bd8a7b5caa6c7940
 F src/sqlite.h.in 39d2e09114d2bdb7afd998f4a469c8f8cd065f8093835a7d0422f260fc78fb4f
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 9788c301f95370fa30e808861f1d2e6f022a816ddbe2a4f67486784c1b31db2e
@@ -2203,8 +2203,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P f5649795cd8d7a1f270037ef0b212ea605c1665ec05a75a6da0b250f2aeab070
-R daac4c37beafe71b6d5a94bfbd982640
+P 2340cbbd230bdadedbb5d3eb9cfd287fd934e69ce5a2c989e141b0fc87b947aa
+R a6b0454e8c391a63932f36d2efa2f0e8
 U drh
-Z 55650fa07137fdaa2a9585b2911bac41
+Z 615ead25f324eae5ee6c5e7d8842ef22
 # Remove this line to create a well-formed Fossil manifest.
index 829c34f4a7f9781e988b1912ecffac4b42f86133..f9a45b04356fc1927b15cae55133824cfc97428a 100644 (file)
@@ -1 +1 @@
-2340cbbd230bdadedbb5d3eb9cfd287fd934e69ce5a2c989e141b0fc87b947aa
+7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb
index 9c1acbdbc720b99c4d4df1dc186cc6075b02f1ed..350361a34e744b392e8a573929493f5a1a412342 100644 (file)
@@ -927,6 +927,18 @@ static char *local_getline(char *zLine, FILE *in){
   return zLine;
 }
 
+/*
+** Return true if either the SQLITE_NO_COLOR compile-time option is used
+** or if the NO_COLOR environment variable exists
+*/
+static int shellNoColor(void){
+#ifdef SQLITE_NO_COLOR
+  return 1;
+#else
+  return getenv("NO_COLOR")!=0;
+#endif
+}
+
 /*
 ** The SQLITE_PS_APPDEF macro should be set to the name of a function
 ** that accepts a single "int" argument and returns a "const char *"
@@ -952,20 +964,24 @@ static const char *shellPromptAppDef(int c){
     case 1:
 #if   defined(SQLITE_PS1)
       return SQLITE_PS1;
-#elif defined(SQLITE_PS_NOANSI)
-      return "/A-/v /~> ";
 #else
-      return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
+      if( shellNoColor() ){
+        return "/A-/v /~> ";
+      }else{
+        return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
+      }
 #endif
 
     /* The default continuation prompt string */
     case 2:
 #if   defined(SQLITE_PS2)
       return SQLITE_PS2;
-#elif defined(SQLITE_PS_NOANSI)
-      return "/B/C> ";
 #else
-      return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
+      if( shellNoColor() ){
+        return "/B/C> ";
+      }else{
+        return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
+      }
 #endif
 
     /* Name of environment variables that override the prompt strings
@@ -13423,22 +13439,13 @@ static void main_init(ShellState *p) {
 /*
 ** Output text to the console in a font that attracts extra attention.
 */
-#if 0 /* Windows now handles ANSI escape codes */
 static void printBold(const char *zText){
-  HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
-  CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
-  GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
-  SetConsoleTextAttribute(out,
-         FOREGROUND_RED|FOREGROUND_INTENSITY
-  );
-  sputz(stdout, zText);
-  SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
-}
-#else
-static void printBold(const char *zText){
-  cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText);
+  if( shellNoColor() ){
+    cli_printf(stdout, "%s", zText);
+  }else{
+    cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText);
+  }
 }
-#endif
 
 /*
 ** Get the argument to an --option.  Throw an error and die if no argument