MCPcopy Create free account
hub / github.com/duckdb/duckdb / DisplayColors

Function DisplayColors

tools/shell/shell_metadata_command.cpp:656–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

654}
655
656MetadataResult 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

Callers

nothing calls this directly

Calls 10

FindColorGroupFunction · 0.85
GetHueFunction · 0.85
GetLumFunction · 0.85
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45
PrintTextMethod · 0.45
PrintMethod · 0.45

Tested by

no test coverage detected