Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds flag for lowercase hex code #105

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/hyprpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ 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 +651,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 +661,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
Loading