]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Columnar modes respond to nScreenWidth.
authordrh <>
Sat, 15 Nov 2025 15:18:41 +0000 (15:18 +0000)
committerdrh <>
Sat, 15 Nov 2025 15:18:41 +0000 (15:18 +0000)
FossilOrigin-Name: 60d26ebb4d91cc885b6b938ef2fc2864ebbf5a18d2e456521ee2f4aa3b22eddf

ext/qrf/qrf.c
manifest
manifest.uuid

index ab882bff100f26109818ad3c37b43460b57896ae..ca3eb7d8127be91bd66b3ece3ba63bca0d01b195 100644 (file)
@@ -1192,6 +1192,9 @@ static void qrfAppendWithTabs(
         col += k;
         z++;
         nVal--;
+      }else if( c=='\r' && nVal==1 ){
+        z++;
+        nVal--;
       }else{
         char zCtrlPik[4];
         col++;
@@ -1270,9 +1273,7 @@ struct qrfColData {
   int *aiWth;              /* Width of each cell */
   struct qrfPerCol {       /* Per-column data */
     char *z;                 /* Cache of text for current row */
-    sqlite3_int64 nW;        /* Total text width across all rows */
     int w;                   /* Computed width of this column */
-    int nLn;                 /* Lines of text over all rows */
     int mxW;                 /* Maximum natural (unwrapped) width */
     unsigned char e;         /* Alignment */
     unsigned char fx;        /* Width is fixed */
@@ -1425,7 +1426,9 @@ static void qrfLoadAlignment(qrfColData *pData, Qrf *p){
 static void qrfRestrictScreenWidth(qrfColData *pData, Qrf *p){
   int sepW;             /* Width of all box separators and margins */
   int sumW;             /* Total width of data area over all columns */
-  int i;                /* Loop counter */
+  int targetW;          /* Desired total data area */
+  int i;                /* Loop counters */
+  int nCol;             /* Number of columns */
 
   pData->nMargin = 2;   /* Default to normal margins */
   if( p->spec.nScreenWidth==0 ) return;
@@ -1434,7 +1437,8 @@ static void qrfRestrictScreenWidth(qrfColData *pData, Qrf *p){
   }else{
     sepW = pData->nCol*3 + 1;
   }
-  for(i=sumW=0; i<pData->nCol; i++) sumW += pData->a[i].w;
+  nCol = pData->nCol;
+  for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w;
   if( p->spec.nScreenWidth >= sumW+sepW ) return;
 
   /* First thing to do is reduce the separation between columns */
@@ -1444,7 +1448,49 @@ static void qrfRestrictScreenWidth(qrfColData *pData, Qrf *p){
   }else{
     sepW = pData->nCol + 1;
   }
-
+  targetW = p->spec.nScreenWidth - sepW;
+
+#define MIN_SQUOZE    8
+#define MIN_EX_SQUOZE 16
+  /* Reduce the width of the widest eligible column.  A column is
+  ** eligible for narrowing if:
+  **
+  **    *  It is not a fixed-width column  (a[0].fx is false)
+  **    *  The current width is more than MIN_SQUOZE
+  **    *  Either:
+  **         +  The current width is more then MIN_EX_SQUOZE, or
+  **         +  The current width is more than half the max width (a[].mxW)
+  **
+  ** Keep making reductions until either no more reductions are
+  ** possible or until the size target is reached.
+  */
+  while( sumW > targetW ){
+    int gain, w;
+    int ix = -1;
+    int mx = 0;
+    for(i=0; i<nCol; i++){
+      if( pData->a[i].fx==0
+       && (w = pData->a[i].w)>mx
+       && w>MIN_SQUOZE
+       && (w>MIN_EX_SQUOZE || w*2>pData->a[i].mxW)
+      ){
+        ix = i;
+        mx = w;
+      }
+    }
+    if( ix<0 ) break;
+    if( mx>=MIN_SQUOZE*2 ){
+      gain = mx/2;
+    }else{
+      gain = mx - MIN_SQUOZE;
+    }
+    if( sumW - gain < targetW ){
+      gain = sumW - targetW;
+    }
+    sumW -= gain;
+    pData->a[ix].w -= gain;
+    pData->bMultiRow = 1;
+  }
 }
 
 /*
@@ -1495,9 +1541,7 @@ static void qrfColumnar(Qrf *p){
       z = data.az[data.n] = sqlite3_str_finish(pStr);
       data.aiWth[data.n] = w = qrfDisplayWidth(z, n, &nNL);
       data.n++;
-      data.a[i].nW += w;
       if( w>data.a[i].mxW ) data.a[i].mxW = w;
-      data.a[i].nLn += 1+nNL;
       if( nNL ) data.bMultiRow = 1;
     }
     p->spec.eText = saved_eText;
@@ -1517,9 +1561,7 @@ static void qrfColumnar(Qrf *p){
       z = data.az[data.n] = sqlite3_str_finish(pStr);
       data.aiWth[data.n] = w = qrfDisplayWidth(z, n, &nNL);
       data.n++;
-      data.a[i].nW += w;
       if( w>data.a[i].mxW ) data.a[i].mxW = w;
-      data.a[i].nLn += 1+nNL;
       if( nNL ) data.bMultiRow = 1;
     }
     p->nRow++;
index 20a81c9b37f94a5b76ad9782a6511a87a724e64d..ecc36a524cb5bc903e660c9db047332b7726fec1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Columnar\sformats\srespond\sto\s--screenwidth\srestrictions\sby\sremoving\ncell\spadding.
-D 2025-11-15T12:09:13.368
+C Columnar\smodes\srespond\sto\snScreenWidth.
+D 2025-11-15T15:18:41.104
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -417,7 +417,7 @@ F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6
 F ext/misc/zipfile.c 09e6e3a3ff40a99677de3c0bc6569bd5f4709b1844ac3d1c1452a456c5a62f1c
 F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee
 F ext/qrf/README.md 09dd538966d8ee32598fc010e7fe6755bd7190494953a02960a9c81197d20cf3
-F ext/qrf/qrf.c fbb6de94990683f8dab198fd11f8d525814e238f239d8c2b5ba876f0547fc20d
+F ext/qrf/qrf.c 290b95fa8613e11a90d5a5a92c32fa22ce415b01fa9578ff5070427b057ac02e
 F ext/qrf/qrf.h b4b3489b3b3683523fd248d15cf5945830643b036943efacdb772a3e00367aa2
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
@@ -2176,8 +2176,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 777eeb2ed2708faf42559387bd582b9345a794798a0327e4fcd75e37948eac60
-R 18da84638cbc549862fa04427f55af51
+P cbe233ca131118692fd4a84d8fcf0dfca926fa935f66cfb718c235d54084de3d
+R 49aa952fd6d1037ed4892eb8fb7a4604
 U drh
-Z 09f09c667712ec4cacfa01d0509edacc
+Z 19e20e94655f4bd956606b3998f9b671
 # Remove this line to create a well-formed Fossil manifest.
index 92b0f0bbf5a5a162a9d8ab9800305c5446d6ad78..9645122c510ef49c056f4ef1d07ec5e8380bc125 100644 (file)
@@ -1 +1 @@
-cbe233ca131118692fd4a84d8fcf0dfca926fa935f66cfb718c235d54084de3d
+60d26ebb4d91cc885b6b938ef2fc2864ebbf5a18d2e456521ee2f4aa3b22eddf