| 654 | } |
| 655 | |
| 656 | MetadataResult DisplayColors(ShellState &state, const vector<string> &args) { |
| 657 | bool bold = false; |
| 658 | bool underline = false; |
| 659 | for (idx_t i = 1; i < args.size(); i++) { |
| 660 | if (args[i] == "bold") { |
| 661 | bold = true; |
| 662 | } else if (args[i] == "underline") { |
| 663 | underline = true; |
| 664 | } else { |
| 665 | return MetadataResult::PRINT_USAGE; |
| 666 | } |
| 667 | } |
| 668 | PrintIntensity intensity = PrintIntensity::STANDARD; |
| 669 | if (bold && underline) { |
| 670 | intensity = PrintIntensity::BOLD_UNDERLINE; |
| 671 | } else if (bold) { |
| 672 | intensity = PrintIntensity::BOLD; |
| 673 | } else if (underline) { |
| 674 | intensity = PrintIntensity::UNDERLINE; |
| 675 | } |
| 676 | ShellHighlight highlighter(state); |
| 677 | vector<duckdb::const_reference<HighlightColorInfo>> color_list; |
| 678 | for (idx_t i = 0; i < static_cast<idx_t>(PrintColor::EXTENDED_COLOR_COUNT); i++) { |
| 679 | auto color = static_cast<PrintColor>(i); |
| 680 | color_list.push_back(*ShellHighlight::GetColorInfo(color)); |
| 681 | } |
| 682 | // group and sort the colors |
| 683 | // groups color by whether or not their name contains certain words |
| 684 | // this is the order in which colors are displayed |
| 685 | vector<vector<string>> color_groups {{"red", "maroon", "coral"}, |
| 686 | {"orange"}, |
| 687 | {"yellow", "gold", "khaki", "wheat"}, |
| 688 | {"green", "chartreuse", "lime", "honeydew", "olive"}, |
| 689 | {"cyan", "aqua", "turquoise"}, |
| 690 | {"blue", "navy"}, |
| 691 | {"pink", "orchid", "rose", "thistle", "salmon", "tan"}, |
| 692 | {"purple", "magenta", "plum", "fuchsia", "violet"}, |
| 693 | {"brown"}, |
| 694 | {"grey", "gray", "black"}, |
| 695 | {"white", "silver", "cornsilk"}}; |
| 696 | std::sort(color_list.begin(), color_list.end(), [&](const HighlightColorInfo &a, const HighlightColorInfo &b) { |
| 697 | // find the group index of this color |
| 698 | auto a_group = FindColorGroup(color_groups, a.color_name); |
| 699 | auto b_group = FindColorGroup(color_groups, b.color_name); |
| 700 | if (a_group != b_group) { |
| 701 | return a_group < b_group; |
| 702 | } |
| 703 | // for colors in the same group - sort on hue, followed by luminosity |
| 704 | auto a_hue = GetHue(a); |
| 705 | auto b_hue = GetHue(b); |
| 706 | |
| 707 | if (a_hue != b_hue) { |
| 708 | return a_hue < b_hue; |
| 709 | } |
| 710 | return GetLum(a) < GetLum(b); |
| 711 | }); |
| 712 | |
| 713 | // now print the colors |