Fossil SCM
Improvements to the "fossil search" help page. Document the --highlight option. Disable colorization if the NO_COLOR environment variable exists.
Commit
eeec6c894ed9cfc16958a8f26dc6db93de1045a55b09ef1dae01b59e503b6cbf
Parent
16d98b94bb58555…
1 file changed
+33
-15
+33
-15
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -645,30 +645,38 @@ | ||
| 645 | 645 | ** |
| 646 | 646 | ** COMMAND: search* |
| 647 | 647 | ** |
| 648 | 648 | ** Usage: %fossil search [OPTIONS] PATTERN... |
| 649 | 649 | ** |
| 650 | -** Search the repository database for PATTERN and show matches. | |
| 651 | -** The following elements of the repository can be searched: | |
| 652 | -** | |
| 653 | -** * check-in comments | |
| 654 | -** * embedded documentation | |
| 655 | -** * forum posts | |
| 656 | -** * tickets | |
| 657 | -** * tech notes | |
| 658 | -** * wiki pages | |
| 659 | -** * built-in fossil help text | |
| 660 | -** | |
| 661 | -** Use options (listed below) to select the scope of the search. The | |
| 662 | -** default is check-in comments only. | |
| 650 | +** Search the repository for PATTERN and show matches. Depending on | |
| 651 | +** options and how the administrator has search configured for the | |
| 652 | +** repository, the search can cover: | |
| 653 | +** | |
| 654 | +** * check-in comments (-c) | |
| 655 | +** * embedded documentation (--docs) | |
| 656 | +** * forum posts (--forum) | |
| 657 | +** * tickets (--tickets) | |
| 658 | +** * tech notes (--technotes) | |
| 659 | +** * wiki pages (--wiki) | |
| 660 | +** * built-in fossil help text (-h) | |
| 661 | +** * all of the above (-a) | |
| 662 | +** | |
| 663 | +** Use options below to select the scope of the search. The | |
| 664 | +** default is check-in comments only (-c). | |
| 665 | +** | |
| 666 | +** Output is colorized if writing to a TTY and if the NO_COLOR environment | |
| 667 | +** variable is not set. Use the "--highlight 0" option to disable colorization | |
| 668 | +** or use "--highlight 91" to force it on. Change the argument to --highlight | |
| 669 | +** to change the color. | |
| 663 | 670 | ** |
| 664 | 671 | ** Options: |
| 665 | 672 | ** -a|--all Search everything |
| 666 | 673 | ** -c|--checkins Search checkin comments |
| 667 | 674 | ** --docs Search embedded documentation |
| 668 | 675 | ** --forum Search forum posts |
| 669 | 676 | ** -h|--bi-help Search built-in help |
| 677 | +** --highlight N Used VT100 color N for matching text. 0 means "off". | |
| 670 | 678 | ** -n|--limit N Limit output to N matches |
| 671 | 679 | ** --technotes Search tech notes |
| 672 | 680 | ** --tickets Search tickets |
| 673 | 681 | ** -W|--width WIDTH Set display width to WIDTH columns, 0 for |
| 674 | 682 | ** unlimited. Defaults to the terminal's width. |
| @@ -687,14 +695,24 @@ | ||
| 687 | 695 | const char *zScope = 0; |
| 688 | 696 | const char *zWidth = find_option("width","W",1); |
| 689 | 697 | int bDebug = find_option("debug",0,0)!=0; /* Undocumented */ |
| 690 | 698 | int nLimit = zLimit ? atoi(zLimit) : -1000; |
| 691 | 699 | int width; |
| 692 | - int nTty = fossil_isatty(1) ? 91 : 0; | |
| 700 | + int nTty = 0; /* VT100 highlight color for matching text */ | |
| 701 | + const char *zHighlight = 0; | |
| 702 | + | |
| 703 | + /* Only colorize the output if talking to a tty and NO_COLOR does not | |
| 704 | + ** exist or is false. */ | |
| 705 | + if( fossil_isatty(1) ){ | |
| 706 | + char *zNoColor = fossil_getenv("NO_COLOR"); | |
| 707 | + if( zNoColor==0 || zNoColor[0]==0 || is_false(zNoColor) ){ | |
| 708 | + nTty = 91; | |
| 709 | + } | |
| 710 | + } | |
| 693 | 711 | |
| 694 | 712 | /* Undocumented option to change highlight color */ |
| 695 | - const char *zHighlight = find_option("highlight",0,1); | |
| 713 | + zHighlight = find_option("highlight",0,1); | |
| 696 | 714 | if( zHighlight ) nTty = atoi(zHighlight); |
| 697 | 715 | |
| 698 | 716 | /* Undocumented option (legacy) */ |
| 699 | 717 | zScope = find_option("scope",0,1); |
| 700 | 718 | |
| 701 | 719 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -645,30 +645,38 @@ | |
| 645 | ** |
| 646 | ** COMMAND: search* |
| 647 | ** |
| 648 | ** Usage: %fossil search [OPTIONS] PATTERN... |
| 649 | ** |
| 650 | ** Search the repository database for PATTERN and show matches. |
| 651 | ** The following elements of the repository can be searched: |
| 652 | ** |
| 653 | ** * check-in comments |
| 654 | ** * embedded documentation |
| 655 | ** * forum posts |
| 656 | ** * tickets |
| 657 | ** * tech notes |
| 658 | ** * wiki pages |
| 659 | ** * built-in fossil help text |
| 660 | ** |
| 661 | ** Use options (listed below) to select the scope of the search. The |
| 662 | ** default is check-in comments only. |
| 663 | ** |
| 664 | ** Options: |
| 665 | ** -a|--all Search everything |
| 666 | ** -c|--checkins Search checkin comments |
| 667 | ** --docs Search embedded documentation |
| 668 | ** --forum Search forum posts |
| 669 | ** -h|--bi-help Search built-in help |
| 670 | ** -n|--limit N Limit output to N matches |
| 671 | ** --technotes Search tech notes |
| 672 | ** --tickets Search tickets |
| 673 | ** -W|--width WIDTH Set display width to WIDTH columns, 0 for |
| 674 | ** unlimited. Defaults to the terminal's width. |
| @@ -687,14 +695,24 @@ | |
| 687 | const char *zScope = 0; |
| 688 | const char *zWidth = find_option("width","W",1); |
| 689 | int bDebug = find_option("debug",0,0)!=0; /* Undocumented */ |
| 690 | int nLimit = zLimit ? atoi(zLimit) : -1000; |
| 691 | int width; |
| 692 | int nTty = fossil_isatty(1) ? 91 : 0; |
| 693 | |
| 694 | /* Undocumented option to change highlight color */ |
| 695 | const char *zHighlight = find_option("highlight",0,1); |
| 696 | if( zHighlight ) nTty = atoi(zHighlight); |
| 697 | |
| 698 | /* Undocumented option (legacy) */ |
| 699 | zScope = find_option("scope",0,1); |
| 700 | |
| 701 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -645,30 +645,38 @@ | |
| 645 | ** |
| 646 | ** COMMAND: search* |
| 647 | ** |
| 648 | ** Usage: %fossil search [OPTIONS] PATTERN... |
| 649 | ** |
| 650 | ** Search the repository for PATTERN and show matches. Depending on |
| 651 | ** options and how the administrator has search configured for the |
| 652 | ** repository, the search can cover: |
| 653 | ** |
| 654 | ** * check-in comments (-c) |
| 655 | ** * embedded documentation (--docs) |
| 656 | ** * forum posts (--forum) |
| 657 | ** * tickets (--tickets) |
| 658 | ** * tech notes (--technotes) |
| 659 | ** * wiki pages (--wiki) |
| 660 | ** * built-in fossil help text (-h) |
| 661 | ** * all of the above (-a) |
| 662 | ** |
| 663 | ** Use options below to select the scope of the search. The |
| 664 | ** default is check-in comments only (-c). |
| 665 | ** |
| 666 | ** Output is colorized if writing to a TTY and if the NO_COLOR environment |
| 667 | ** variable is not set. Use the "--highlight 0" option to disable colorization |
| 668 | ** or use "--highlight 91" to force it on. Change the argument to --highlight |
| 669 | ** to change the color. |
| 670 | ** |
| 671 | ** Options: |
| 672 | ** -a|--all Search everything |
| 673 | ** -c|--checkins Search checkin comments |
| 674 | ** --docs Search embedded documentation |
| 675 | ** --forum Search forum posts |
| 676 | ** -h|--bi-help Search built-in help |
| 677 | ** --highlight N Used VT100 color N for matching text. 0 means "off". |
| 678 | ** -n|--limit N Limit output to N matches |
| 679 | ** --technotes Search tech notes |
| 680 | ** --tickets Search tickets |
| 681 | ** -W|--width WIDTH Set display width to WIDTH columns, 0 for |
| 682 | ** unlimited. Defaults to the terminal's width. |
| @@ -687,14 +695,24 @@ | |
| 695 | const char *zScope = 0; |
| 696 | const char *zWidth = find_option("width","W",1); |
| 697 | int bDebug = find_option("debug",0,0)!=0; /* Undocumented */ |
| 698 | int nLimit = zLimit ? atoi(zLimit) : -1000; |
| 699 | int width; |
| 700 | int nTty = 0; /* VT100 highlight color for matching text */ |
| 701 | const char *zHighlight = 0; |
| 702 | |
| 703 | /* Only colorize the output if talking to a tty and NO_COLOR does not |
| 704 | ** exist or is false. */ |
| 705 | if( fossil_isatty(1) ){ |
| 706 | char *zNoColor = fossil_getenv("NO_COLOR"); |
| 707 | if( zNoColor==0 || zNoColor[0]==0 || is_false(zNoColor) ){ |
| 708 | nTty = 91; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | /* Undocumented option to change highlight color */ |
| 713 | zHighlight = find_option("highlight",0,1); |
| 714 | if( zHighlight ) nTty = atoi(zHighlight); |
| 715 | |
| 716 | /* Undocumented option (legacy) */ |
| 717 | zScope = find_option("scope",0,1); |
| 718 | |
| 719 |