Skip to content

Commit

Permalink
feat: adds flag for lowercase hexcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
bun137 committed Jan 16, 2025
1 parent 444c40e commit b7402aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/hyprpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,12 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {

if (!m_bDisableHexPreview) {
const auto currentColor = getColorFromPixel(pSurface, CLICKPOS);
std::string hexBuffer = std::format("#{:02X}{:02X}{:02X}", currentColor.r, currentColor.g, currentColor.b);
std::string hexBuffer;
if (m_bUseLowerCase) {
hexBuffer = std::format("#{:02x}{:02x}{:02x}", currentColor.r, currentColor.g, currentColor.b);
} else {
hexBuffer = std::format("#{:02X}{:02X}{:02X}", currentColor.r, currentColor.g, currentColor.b);
}

cairo_set_source_rgba(PCAIRO, 0.0, 0.0, 0.0, 0.5);

Expand Down Expand Up @@ -647,8 +652,8 @@ void CHyprpicker::initMouse() {
break;
}
case OUTPUT_HEX: {
auto toHex = [](int i) -> std::string {
const char* DS = "0123456789ABCDEF";
auto toHex = [this](int i) -> std::string {
const char* DS = m_bUseLowerCase ? "0123456789abcdef" : "0123456789ABCDEF";

std::string result = "";

Expand All @@ -657,6 +662,9 @@ void CHyprpicker::initMouse() {

return result;
};
auto hexR = toHex(COL.r);
auto hexG = toHex(COL.g);
auto hexB = toHex(COL.b);

if (m_bFancyOutput)
Debug::log(NONE, "\033[38;2;%i;%i;%i;48;2;%i;%i;%im#%s%s%s\033[0m", FG, FG, FG, COL.r, COL.g, COL.b, toHex(COL.r).c_str(), toHex(COL.g).c_str(),
Expand Down
1 change: 1 addition & 0 deletions src/hyprpicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CHyprpicker {
bool m_bNoZoom = false;
bool m_bNoFractional = false;
bool m_bDisableHexPreview = false;
bool m_bUseLowerCase = false;

bool m_bRunning = true;

Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static void help(void) {
<< " -v | --verbose | Enable more logs\n"
<< " -t | --no-fractional | Disable fractional scaling support\n"
<< " -d | --disable-hex-preview | Disable live preview of Hex code\n"
<< " -l | --lowercase-hex | Outputs the hexcode in lowercase\n"
<< " -V | --version | Print version info\n";
}

Expand All @@ -34,10 +35,11 @@ int main(int argc, char** argv, char** envp) {
{"quiet", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
{"disable-hex-preview", no_argument, NULL, 'd'},
{"lowercase-hex", no_argument, NULL, 'l'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}};

int c = getopt_long(argc, argv, ":f:hnarzqvtdV", long_options, &option_index);
int c = getopt_long(argc, argv, ":f:hnarzqvtdlV", long_options, &option_index);
if (c == -1)
break;

Expand Down Expand Up @@ -67,6 +69,7 @@ int main(int argc, char** argv, char** envp) {
case 'q': Debug::quiet = true; break;
case 'v': Debug::verbose = true; break;
case 'd': g_pHyprpicker->m_bDisableHexPreview = true; break;
case 'l': g_pHyprpicker->m_bUseLowerCase = true; break;
case 'V': {
std::cout << "hyprpicker v" << HYPRPICKER_VERSION << "\n";
exit(0);
Expand Down

0 comments on commit b7402aa

Please sign in to comment.