History

a few fixes and a "snarf all" menu option

Sigrid Haflínudóttir committed 6 years ago

Commit 29e9efb1 parent 35d64482 files · +47 −22Browse files

Unified · Split

2 files
  1. README.md +15 −2
  2. picker.c +32 −20
README.md+15−2
@@ -1,4 +1,17 @@
11 # picker
22
3−HSLuv color picker for Plan 9.
4−It's WIP so the code look horrible and doesn't make any sense right now.
3+Color picker for Plan 9. It has HSLuv, HPLuv, and RGB color space
4+modes and is intended to be used mainly by external programs that need
5+a way to change their color palette.
6+
7+## Installing
8+
9+```
10+cd /tmp && \
11+hget https://github.com/ftrvxmtrx/picker/archive/master.tar.gz | tar xz && \
12+cd picker-master && mk install
13+```
14+
15+## Documentation
16+
17+See the man page.
picker.c+32−20
@@ -109,8 +109,9 @@ static Space spaces[] = { · 108 unmodified lines
109109 },
110110 };
111111
112−static char *menu2i[nelem(spaces)+2] = {
112+static char *menu2i[nelem(spaces)+3] = {
113113 "snarf",
114+ "snarf all",
114115 };
115116 static Menu menu2 = { .item = menu2i };
116117
@@ -184,6 +185,12 @@ slider(int si, int w) · 67 unmodified lines
184185 return s;
185186 }
186187
188+static int
189+color2str(Color *c, char *s)
190+{
191+ return nchan > 3 ? sprint(s, "%08lux", c->u) : sprint(s, "%06lux", c->u>>8);
192+}
193+
187194 static void
188195 redraw(void)
189196 {
@@ -242,10 +249,7 @@ redraw(void) · 52 unmodified lines
242249 draw(screen, r, colors[curcolor].i, nil, ZP);
243250
244251 /* current color in hex */
245− if (nchan > 3)
246− sprint(hex, "%08lux", colors[curcolor].u);
247− else
248− sprint(hex, "%06lux", colors[curcolor].u>>8);
252+ color2str(&colors[curcolor], hex);
249253 r.min.x += Dx(r)/2 - stringwidth(font, hex)/2;
250254 r.min.y += Dy(r)/2 - font->height/2;
251255 stringbg(screen, r.min, display->white, ZP, font, hex, display->black, ZP);
@@ -351,6 +355,7 @@ threadmain(int argc, char **argv) · 99 unmodified lines
351355 Color *c;
352356 int i, once;
353357 ulong u;
358+ char buf[16];
354359
355360 space = &spaces[0];
356361 nchan = 3;
@@ -391,7 +396,7 @@ threadmain(int argc, char **argv) · 34 unmodified lines
391396 }
392397
393398 for (i = 0; i < nelem(spaces); i++)
394− menu2i[i+1] = spaces[i].name;
399+ menu2i[i+2] = spaces[i].name;
395400
396401 if (initdraw(nil, nil, "picker") < 0)
397402 sysfatal("initdraw: %r");
@@ -461,26 +466,33 @@ changed: · 63 unmodified lines
461466 goto next;
462467 }
463468 }
464− } else if (m.buttons == 2) {
465− if ((i = menuhit(2, mctl, &menu2, nil)) >= 0) {
469+ } else if (m.buttons == 2 && (i = menuhit(2, mctl, &menu2, nil)) >= 0) {
470+ if (i >= 2) {
471+ space = &spaces[i-2];
472+ space->fromrgb(c->rgba, c->v);
473+ for (i = 0; i < 3; i++)
474+ c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
475+ goto changed;
476+ }
477+
478+ int f;
479+ if ((f = open("/dev/snarf", OWRITE)) >= 0) {
466480 if (i == 0) {
467− int f;
468− if ((f = open("/dev/snarf", OWRITE)) >= 0) {
469− write(f, hex, strlen(hex));
470− close(f);
471− }
481+ write(f, hex, strlen(hex));
472482 } else {
473− space = &spaces[i];
474− space->fromrgb(c->rgba, c->v);
475− for (i = 0; i < 3; i++)
476− c->v[i] = MAX(0.0, MIN(space->max[i], c->v[i]));
477− goto changed;
483+ for (i = 0; i < ncolors; i++) {
484+ write(f, buf, color2str(&colors[i], buf));
485+ if (i != ncolors-1)
486+ write(f, " ", 1);
487+ }
478488 }
489+ close(f);
479490 }
480491 } else if (m.buttons == 4) {
481− if (enter(nchan < 4 ? "rgb:" : "rgba:", hex+1, sizeof(hex)-1, mctl, kctl, nil) > 0) {
492+ strcpy(buf, hex);
493+ if (enter(nchan < 4 ? "rgb:" : "rgba:", buf, sizeof(buf), mctl, kctl, nil) > 0) {
482494 u = c->u;
483− if (str2color(hex+1, c) == 0 && c->u != u) {
495+ if (str2color(buf, c) == 0 && c->u != u) {
484496 c->u = ~c->u; /* just for the update to kick in */
485497 goto changed;
486498 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t