Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a new routine "reasonable_bg_color()" that tries to transform a user-requested background color for a check-in or branch into a color that is appropriate for the current skin. The /test-bgcolor web page was added for testing the algorithm. With this enhancement, it is ok to add back the the --bgcolor and --branchcolor options to "fossil commit". |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f7a18cfcafd18ddcb4b1940ea7f8099f |
User & Date: | drh 2025-03-25 23:57:25.552 |
Context
2025-03-26
| ||
09:54 | Improvements to /test-bgcolor to show the requested color and both light-mode and dark-mode background colors all at once. Also prepopulate the entry boxes with a selection of colors. ... (check-in: a390c6ba user: drh tags: trunk) | |
2025-03-25
| ||
23:57 | Add a new routine "reasonable_bg_color()" that tries to transform a user-requested background color for a check-in or branch into a color that is appropriate for the current skin. The /test-bgcolor web page was added for testing the algorithm. With this enhancement, it is ok to add back the the --bgcolor and --branchcolor options to "fossil commit". ... (check-in: f7a18cfc user: drh tags: trunk) | |
18:13 | Remove +x bit from Makefile.in (not sure when it got added). ... (check-in: f75803fe user: stephan tags: trunk) | |
Changes
Changes to src/branch.c.
︙ | ︙ | |||
868 869 870 871 872 873 874 | const char *zMergeTo = db_column_text(&q, 3); int nCkin = db_column_int(&q, 4); const char *zLastCkin = db_column_text(&q, 5); const char *zBgClr = db_column_text(&q, 6); char *zAge = human_readable_age(rNow - rMtime); sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0); if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0; | > | | 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | const char *zMergeTo = db_column_text(&q, 3); int nCkin = db_column_int(&q, 4); const char *zLastCkin = db_column_text(&q, 5); const char *zBgClr = db_column_text(&q, 6); char *zAge = human_readable_age(rNow - rMtime); sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0); if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0; if( zBgClr ) zBgClr = reasonable_bg_color(zBgClr); if( zBgClr==0 ){ if( zBranch==0 || strcmp(zBranch,"trunk")==0 ){ zBgClr = 0; }else{ zBgClr = hash_color(zBranch); } } if( zBgClr && zBgClr[0] && show_colors ){ |
︙ | ︙ |
Changes to src/checkin.c.
︙ | ︙ | |||
2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 | ** ** Options: ** --allow-conflict Allow unresolved merge conflicts ** --allow-empty Allow a commit with no changes ** --allow-fork Allow the commit to fork ** --allow-older Allow a commit older than its ancestor ** --baseline Use a baseline manifest in the commit process ** --branch NEW-BRANCH-NAME Check in to this new branch ** --close Close the branch being committed ** --date-override DATETIME Make DATETIME the time of the check-in. ** Useful when importing historical check-ins ** from another version control system. ** --delta Use a delta manifest in the commit process ** --hash Verify file status using hashing rather ** than relying on filesystem mtimes | > > | 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 | ** ** Options: ** --allow-conflict Allow unresolved merge conflicts ** --allow-empty Allow a commit with no changes ** --allow-fork Allow the commit to fork ** --allow-older Allow a commit older than its ancestor ** --baseline Use a baseline manifest in the commit process ** --bgcolor COLOR Apply COLOR to this one check-in only ** --branch NEW-BRANCH-NAME Check in to this new branch ** --branchcolor COLOR Apply given COLOR to the branch ** --close Close the branch being committed ** --date-override DATETIME Make DATETIME the time of the check-in. ** Useful when importing historical check-ins ** from another version control system. ** --delta Use a delta manifest in the commit process ** --hash Verify file status using hashing rather ** than relying on filesystem mtimes |
︙ | ︙ |
Changes to src/color.c.
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ** This file contains code used to select colors based on branch and ** user names. ** */ #include "config.h" #include <string.h> #include "color.h" /* ** Compute a hash on a branch or user name */ static unsigned int hash_of_name(const char *z){ unsigned int h = 0; int i; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | ** This file contains code used to select colors based on branch and ** user names. ** */ #include "config.h" #include <string.h> #include "color.h" /* ** 140 standard CSS color names and their corresponding RGB values, ** in alphabetical order by name so that we can do a binary search ** for lookup. */ static const struct CssColors { const char *zName; /* CSS Color name, lower case */ unsigned int iRGB; /* Corresponding RGB value */ } aCssColors[] = { { "aliceblue", 0xf0f8ff }, { "antiquewhite", 0xfaebd7 }, { "aqua", 0x00ffff }, { "aquamarine", 0x7fffd4 }, { "azure", 0xf0ffff }, { "beige", 0xf5f5dc }, { "bisque", 0xffe4c4 }, { "black", 0x000000 }, { "blanchedalmond", 0xffebcd }, { "blue", 0x0000ff }, { "blueviolet", 0x8a2be2 }, { "brown", 0xa52a2a }, { "burlywood", 0xdeb887 }, { "cadetblue", 0x5f9ea0 }, { "chartreuse", 0x7fff00 }, { "chocolate", 0xd2691e }, { "coral", 0xff7f50 }, { "cornflowerblue", 0x6495ed }, { "cornsilk", 0xfff8dc }, { "crimson", 0xdc143c }, { "cyan", 0x00ffff }, { "darkblue", 0x00008b }, { "darkcyan", 0x008b8b }, { "darkgoldenrod", 0xb8860b }, { "darkgray", 0xa9a9a9 }, { "darkgreen", 0x006400 }, { "darkkhaki", 0xbdb76b }, { "darkmagenta", 0x8b008b }, { "darkolivegreen", 0x556b2f }, { "darkorange", 0xff8c00 }, { "darkorchid", 0x9932cc }, { "darkred", 0x8b0000 }, { "darksalmon", 0xe9967a }, { "darkseagreen", 0x8fbc8f }, { "darkslateblue", 0x483d8b }, { "darkslategray", 0x2f4f4f }, { "darkturquoise", 0x00ced1 }, { "darkviolet", 0x9400d3 }, { "deeppink", 0xff1493 }, { "deepskyblue", 0x00bfff }, { "dimgray", 0x696969 }, { "dodgerblue", 0x1e90ff }, { "firebrick", 0xb22222 }, { "floralwhite", 0xfffaf0 }, { "forestgreen", 0x228b22 }, { "fuchsia", 0xff00ff }, { "gainsboro", 0xdcdcdc }, { "ghostwhite", 0xf8f8ff }, { "gold", 0xffd700 }, { "goldenrod", 0xdaa520 }, { "gray", 0x808080 }, { "green", 0x008000 }, { "greenyellow", 0xadff2f }, { "honeydew", 0xf0fff0 }, { "hotpink", 0xff69b4 }, { "indianred", 0xcd5c5c }, { "indigo", 0x4b0082 }, { "ivory", 0xfffff0 }, { "khaki", 0xf0e68c }, { "lavender", 0xe6e6fa }, { "lavenderblush", 0xfff0f5 }, { "lawngreen", 0x7cfc00 }, { "lemonchiffon", 0xfffacd }, { "lightblue", 0xadd8e6 }, { "lightcoral", 0xf08080 }, { "lightcyan", 0xe0ffff }, { "lightgoldenrodyellow", 0xfafad2 }, { "lightgrey", 0xd3d3d3 }, { "lightgreen", 0x90ee90 }, { "lightpink", 0xffb6c1 }, { "lightsalmon", 0xffa07a }, { "lightseagreen", 0x20b2aa }, { "lightskyblue", 0x87cefa }, { "lightslategray", 0x778899 }, { "lightsteelblue", 0xb0c4de }, { "lightyellow", 0xffffe0 }, { "lime", 0x00ff00 }, { "limegreen", 0x32cd32 }, { "linen", 0xfaf0e6 }, { "magenta", 0xff00ff }, { "maroon", 0x800000 }, { "mediumaquamarine", 0x66cdaa }, { "mediumblue", 0x0000cd }, { "mediumorchid", 0xba55d3 }, { "mediumpurple", 0x9370d8 }, { "mediumseagreen", 0x3cb371 }, { "mediumslateblue", 0x7b68ee }, { "mediumspringgreen", 0x00fa9a }, { "mediumturquoise", 0x48d1cc }, { "mediumvioletred", 0xc71585 }, { "midnightblue", 0x191970 }, { "mintcream", 0xf5fffa }, { "mistyrose", 0xffe4e1 }, { "moccasin", 0xffe4b5 }, { "navajowhite", 0xffdead }, { "navy", 0x000080 }, { "oldlace", 0xfdf5e6 }, { "olive", 0x808000 }, { "olivedrab", 0x6b8e23 }, { "orange", 0xffa500 }, { "orangered", 0xff4500 }, { "orchid", 0xda70d6 }, { "palegoldenrod", 0xeee8aa }, { "palegreen", 0x98fb98 }, { "paleturquoise", 0xafeeee }, { "palevioletred", 0xd87093 }, { "papayawhip", 0xffefd5 }, { "peachpuff", 0xffdab9 }, { "peru", 0xcd853f }, { "pink", 0xffc0cb }, { "plum", 0xdda0dd }, { "powderblue", 0xb0e0e6 }, { "purple", 0x800080 }, { "red", 0xff0000 }, { "rosybrown", 0xbc8f8f }, { "royalblue", 0x4169e1 }, { "saddlebrown", 0x8b4513 }, { "salmon", 0xfa8072 }, { "sandybrown", 0xf4a460 }, { "seagreen", 0x2e8b57 }, { "seashell", 0xfff5ee }, { "sienna", 0xa0522d }, { "silver", 0xc0c0c0 }, { "skyblue", 0x87ceeb }, { "slateblue", 0x6a5acd }, { "slategray", 0x708090 }, { "snow", 0xfffafa }, { "springgreen", 0x00ff7f }, { "steelblue", 0x4682b4 }, { "tan", 0xd2b48c }, { "teal", 0x008080 }, { "thistle", 0xd8bfd8 }, { "tomato", 0xff6347 }, { "turquoise", 0x40e0d0 }, { "violet", 0xee82ee }, { "wheat", 0xf5deb3 }, { "white", 0xffffff }, { "whitesmoke", 0xf5f5f5 }, { "yellow", 0xffff00 }, { "yellowgreen", 0x9acd32 }, }; /* ** Attempt to translate a CSS color name into an integer that ** represents the equivalent RGB value. Ignore alpha if provided. ** If the name cannot be translated, return -1. */ int color_name_to_rgb(const char *zName){ if( zName==0 || zName[0]==0 ) return -1; if( zName[0]=='#' ){ int i, v = 0; for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){ v = v*16 + fossil_hexvalue(zName[i]); } if( i<7 ) return -1; return v; }else if( sqlite3_strlike("rgb%)", zName,0)==0 ){ return -1; }else if( sqlite3_strlike("hsl%)",zName,0)==0 ){ return -1; }else{ int iMin = 0; int iMax = count(aCssColors)-1; while( iMin<=iMax ){ int iMid = (iMin+iMax)/2; int c = sqlite3_stricmp(aCssColors[iMid].zName, zName); if( c==0 ) return aCssColors[iMid].iRGB; if( c<0 ){ iMin = iMid+1; }else{ iMax = iMid-1; } } return -1; } } /* ** Shift a color provided by the user so that it is suitable ** for use as a background color in the current skin. ** ** The return value is a #HHHHHH color name contained in ** static space that is overwritten on the next call. ** ** If we cannot make sense of the background color recommendation ** that is the input, then return NULL. */ char *reasonable_bg_color(const char *zRequested){ int iRGB = color_name_to_rgb(zRequested); int cc[3]; int lo, hi; int r, g, b; static int fg = 0; /* 1==black-foreground 2==white-foreground */ static char zColor[10]; int K = 70; /* Tune for background color saturation */ if( iRGB<0 ) return 0; if( fg==0 ) fg = skin_detail_boolean("white-foreground") ? 2 : 1; cc[0] = (iRGB>>16) & 0xff; cc[1] = (iRGB>>8) & 0xff; cc[2] = iRGB & 0xff; lo = cc[0]<cc[1] ? 0 : 1; if( cc[2]<cc[lo] ) lo = 2; hi = cc[0]>cc[1] ? 0 : 1; if( cc[2]>cc[hi] ) hi = 2; if( cc[lo]==cc[hi] ){ /* Requested color is some shade of gray */ r = (K*cc[0])/255; if( fg==1 ) r += (255-K); g = b = r; }else{ int d = cc[hi] - cc[lo]; r = (K*(cc[0] - cc[lo]))/d; g = (K*(cc[1] - cc[lo]))/d; b = (K*(cc[2] - cc[lo]))/d; if( fg==1 ){ r += (255-K); g += (255-K); b += (255-K); } } sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b); return zColor; } /* ** Compute a hash on a branch or user name */ static unsigned int hash_of_name(const char *z){ unsigned int h = 0; int i; |
︙ | ︙ | |||
183 184 185 186 187 188 189 | @ <input type="text" size="30" name='%s(zNm)' value='%h(PD(zNm,""))'><br> } @ <input type="submit" value="Submit"> @ <input type="submit" name="rand" value="Random"> @ </form> style_finish_page(); } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | @ <input type="text" size="30" name='%s(zNm)' value='%h(PD(zNm,""))'><br> } @ <input type="submit" value="Submit"> @ <input type="submit" name="rand" value="Random"> @ </form> style_finish_page(); } /* ** WEBPAGE: test-bgcolor ** ** Show how user-specified background colors will be rendered ** using the reasonable_bg_color() algorithm. */ void test_bgcolor_page(void){ const char *zReq; /* Requested color name */ const char *zBG; /* Actual color provided */ char zNm[10]; int i, cnt; login_check_credentials(); style_set_current_feature("test"); style_header("Background Color Test"); for(i=cnt=0; i<10; i++){ sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i); zReq = P(zNm); if( zReq==0 || zReq[0]==0 ) continue; zBG = reasonable_bg_color(zReq); if( zBG==0 ){ @ <p>"%h(zReq)" is not a recognized color name</p> }else if( zReq[0]!='#' ){ char zReqRGB[12]; sqlite3_snprintf(sizeof(zReqRGB),zReqRGB,"#%06x",color_name_to_rgb(zReq)); @ <p style='border:1px solid;background-color:%s(zBG);'> @ Requested: %h(zReq) (%h(zReqRGB)) → Actual: %h(zBG)</p> cnt++; }else{ @ <p style='border:1px solid;background-color:%s(zBG);'> @ Requested: %h(zReq) → Actual: %h(zBG)</p> cnt++; } } if( cnt ){ @ <hr> } @ <form method="POST"> @ <p>Enter CSS color names below and see them shifted into corresponding @ background colors above.</p> for(i=0; i<10; i++){ sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i); @ <input type="text" size="30" name='%s(zNm)' value='%h(PD(zNm,""))'><br> } @ <input type="submit" value="Submit"> @ </form> style_finish_page(); } |
Changes to src/encode.c.
︙ | ︙ | |||
242 243 244 245 246 247 248 | *zOut = 0; return zRet; } /* ** Convert a single HEX digit to an integer */ | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | *zOut = 0; return zRet; } /* ** Convert a single HEX digit to an integer */ int fossil_hexvalue(int c){ if( c>='a' && c<='f' ){ c += 10 - 'a'; }else if( c>='A' && c<='F' ){ c += 10 - 'A'; }else if( c>='0' && c<='9' ){ c -= '0'; }else{ |
︙ | ︙ | |||
270 271 272 273 274 275 276 | if( !z ) return 0; i = j = 0; while( z[i] ){ switch( z[i] ){ case '%': if( z[i+1] && z[i+2] ){ | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | if( !z ) return 0; i = j = 0; while( z[i] ){ switch( z[i] ){ case '%': if( z[i+1] && z[i+2] ){ z[j] = fossil_hexvalue(z[i+1]) << 4; z[j] |= fossil_hexvalue(z[i+2]); i += 2; } break; case '+': z[j] = ' '; break; default: |
︙ | ︙ |
Changes to src/timeline.c.
︙ | ︙ | |||
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | } }else{ zDateLink = mprintf("<a>"); } @ <td class="timelineTime">%z(zDateLink)%s(zTime)</a></td> @ <td class="timelineGraph"> if( tmFlags & (TIMELINE_UCOLOR|TIMELINE_DELTA|TIMELINE_NOCOLOR) ){ if( tmFlags & TIMELINE_UCOLOR ){ zBgClr = zUser ? user_color(zUser) : 0; }else if( tmFlags & TIMELINE_NOCOLOR ){ zBgClr = 0; }else if( zType[0]=='c' ){ static Stmt qdelta; db_static_prepare(&qdelta, "SELECT baseid IS NULL FROM plink" " WHERE cid=:rid"); db_bind_int(&qdelta, ":rid", rid); if( db_step(&qdelta)!=SQLITE_ROW ){ zBgClr = 0; /* Not a check-in */ }else if( db_column_int(&qdelta, 0) ){ zBgClr = hash_color("b"); /* baseline manifest */ }else{ zBgClr = hash_color("f"); /* delta manifest */ } db_reset(&qdelta); } } if( zType[0]=='c' && (pGraph || zBgClr==0 || (tmFlags & (TIMELINE_BRCOLOR|TIMELINE_DELTA))!=0) ){ zBr = branch_of_rid(rid); if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){ if( tmFlags & (TIMELINE_DELTA|TIMELINE_NOCOLOR) ){ }else if( zBr==0 || strcmp(zBr,"trunk")==0 ){ zBgClr = 0; }else{ zBgClr = hash_color(zBr); } } | > > > > > > > | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | } }else{ zDateLink = mprintf("<a>"); } @ <td class="timelineTime">%z(zDateLink)%s(zTime)</a></td> @ <td class="timelineGraph"> if( tmFlags & (TIMELINE_UCOLOR|TIMELINE_DELTA|TIMELINE_NOCOLOR) ){ /* Don't use the requested background color. Use the background color ** override from query parameters instead. */ if( tmFlags & TIMELINE_UCOLOR ){ zBgClr = zUser ? user_color(zUser) : 0; }else if( tmFlags & TIMELINE_NOCOLOR ){ zBgClr = 0; }else if( zType[0]=='c' ){ static Stmt qdelta; db_static_prepare(&qdelta, "SELECT baseid IS NULL FROM plink" " WHERE cid=:rid"); db_bind_int(&qdelta, ":rid", rid); if( db_step(&qdelta)!=SQLITE_ROW ){ zBgClr = 0; /* Not a check-in */ }else if( db_column_int(&qdelta, 0) ){ zBgClr = hash_color("b"); /* baseline manifest */ }else{ zBgClr = hash_color("f"); /* delta manifest */ } db_reset(&qdelta); } }else{ /* Make sure the user-specified background color is reasonable */ zBgClr = reasonable_bg_color(zBgClr); } if( zType[0]=='c' && (pGraph || zBgClr==0 || (tmFlags & (TIMELINE_BRCOLOR|TIMELINE_DELTA))!=0) ){ zBr = branch_of_rid(rid); if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){ /* If no background color is specified, use a color based on the ** branch name */ if( tmFlags & (TIMELINE_DELTA|TIMELINE_NOCOLOR) ){ }else if( zBr==0 || strcmp(zBr,"trunk")==0 ){ zBgClr = 0; }else{ zBgClr = hash_color(zBr); } } |
︙ | ︙ |