///////////////////////////////////////////////////////////////////////////
| 54 | |
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | int CmdColor::execute(std::string& output) { |
| 57 | int rc = 0; |
| 58 | |
| 59 | // Get the non-attribute, non-fancy command line arguments. |
| 60 | auto legend = false; |
| 61 | auto words = Context::getContext().cli2.getWords(); |
| 62 | for (auto& word : words) |
| 63 | if (closeEnough("legend", word)) legend = true; |
| 64 | |
| 65 | std::stringstream out; |
| 66 | if (Context::getContext().color()) { |
| 67 | // If the description contains 'legend', show all the colors currently in |
| 68 | // use. |
| 69 | if (legend) { |
| 70 | out << "\nHere are the colors currently in use:\n"; |
| 71 | |
| 72 | Table view; |
| 73 | view.width(Context::getContext().getWidth()); |
| 74 | if (Context::getContext().config.getBoolean("color")) view.forceColor(); |
| 75 | view.add("Color"); |
| 76 | view.add("Definition"); |
| 77 | |
| 78 | for (auto& item : Context::getContext().config) { |
| 79 | // Skip items with 'color' in their name, that are not referring to |
| 80 | // actual colors. |
| 81 | if (item.first != "_forcecolor" && item.first != "color" && item.first.find("color") == 0) { |
| 82 | Color color(Context::getContext().config.get(item.first)); |
| 83 | int row = view.addRow(); |
| 84 | view.set(row, 0, item.first, color); |
| 85 | view.set(row, 1, item.second, color); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | out << view.render() << '\n'; |
| 90 | } |
| 91 | |
| 92 | // If there is something in the description, then assume that is a color, |
| 93 | // and display it as a sample. |
| 94 | else if (words.size()) { |
| 95 | Color one("black on bright yellow"); |
| 96 | Color two("underline cyan on bright blue"); |
| 97 | Color three("color214 on color202"); |
| 98 | Color four("rgb150 on rgb020"); |
| 99 | Color five("underline grey10 on grey3"); |
| 100 | Color six("red on color173"); |
| 101 | |
| 102 | std::string swatch; |
| 103 | for (auto word = words.begin(); word != words.end(); ++word) { |
| 104 | if (word != words.begin()) swatch += ' '; |
| 105 | |
| 106 | swatch += *word; |
| 107 | } |
| 108 | |
| 109 | Color sample(swatch); |
| 110 | |
| 111 | out << '\n' |
| 112 | << "Use this command to see how colors are displayed by your terminal.\n" |
| 113 | << "\n\n" |