Skip to content

Commit d0855b6

Browse files
committed
update
1 parent e96c6ab commit d0855b6

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

README

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
kc
22

3-
KISS colors, an on-the-fly palette changer written in C, inspired by Dylan Araps' okpal [0].
3+
KISS colors, an on-the-fly color palette changer written in C.
44

55

66
BACKGROUND
77
----------
88

9-
This code base is partially-functional at this time and will be promoted to release
10-
once the following features are implemented:
9+
This project was inspired by Dylan Arap's okpal [0] palette change. This code
10+
base is partially-functional at this time and will be promoted to release once
11+
the following features are implemented:
1112

12-
- [ ] Select palette
13+
- [x] Select palette
1314
- [ ] Select random palette
1415
- [x] List all palettes
1516
- [x] Set light theme
1617
- [x] Print help/usage.
1718
- [x] Print Version
1819
- [x] Print current palette
19-
- [ ] save new palette to .config/
20+
- [x] save new palette to .config/
2021

2122

2223
INSTALLATION

kc

14.1 KB
Binary file not shown.

kc.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sys/stat.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <unistd.h>
@@ -26,19 +27,18 @@ find_palettes(void)
2627
int
2728
select_palette(void)
2829
{
29-
size_t len = 255;
30-
char *line = malloc(sizeof(char) * len);
30+
// size_t len = 255;
31+
p.len = 255;
32+
char *line = malloc(sizeof(char) * p.len);
3133
char *envvar, *envval;
32-
FILE *fp = fopen(p.SEL, "r");
33-
setenv("LC_ALL", "C", 1);
34-
system("exec 6>&1 >/dev/null");
35-
while(fgets(line, len, fp) != NULL)
34+
p.fp = fopen(p.SEL, "r");
35+
while(fgets(line, p.len, p.fp) != NULL)
3636
{
3737
envvar = strtok(line, "=");
3838
envval = strtok(NULL, "=");
3939
setenv(envvar, envval, 1);
4040
}
41-
fclose(fp);
41+
fclose(p.fp);
4242
free(line);
4343
sprintf(p.PRI, "printf %%b \"\
4444
\\e]4;0;#$(echo $color00)\\e\\ \
@@ -60,12 +60,16 @@ select_palette(void)
6060
\\e]10;#$(echo $foreground)\\e\\ \
6161
\\e]11;#$(echo $background)\\e\\ \
6262
\\e]12;#$(echo $cursor)\\e\\ \"", p.CONF);
63-
sprintf(p.CLI, "%s > %s/sequence", p.PRI, p.CONF);
64-
system(p.CLI);
65-
sprintf(p.CLI, "%s > %s/current", p.PRI, p.CONF);
66-
system(p.CLI);
63+
p.fp = fopen(p.CSEQ, "w");
64+
fprintf(p.fp, "%s", p.PRI);
65+
fclose(p.fp);
66+
p.fp = fopen(p.CCUR, "w");
67+
fprintf(p.fp, "%s", p.SEL);
68+
fclose(p.fp);
6769
sprintf(p.CLI, "%s > /dev/fd/0", p.PRI);
6870
system(p.CLI);
71+
sprintf(p.CLI, "%s > /dev/pts/0", p.PRI);
72+
system(p.CLI);
6973
return 0;
7074
}
7175

@@ -79,29 +83,31 @@ int
7983
list_palette(void)
8084
{
8185
struct dirent *de;
82-
DIR *dr = opendir(p.SEL);
86+
p.dr = opendir(p.SEL);
8387

84-
if (dr == NULL)
88+
if (p.dr == NULL)
8589
{
8690
printf("Could not open directory");
8791
return 1;
8892
}
8993

90-
while((de = readdir(dr)) != NULL)
94+
while((de = readdir(p.dr)) != NULL)
9195
{
9296
printf("->%s\n", de->d_name);
9397
}
9498

95-
closedir(dr);
99+
closedir(p.dr);
96100
return 0;
97101
}
98102

99103
int
100104
print_palette(void)
101105
{
102-
FILE *fp = fopen(p.CONF, "r");
103-
fclose(fp);
104-
printf("\nUsing: %s\n", p.SEL);
106+
char str[60];
107+
p.fp = fopen(p.CCUR, "r");
108+
fgets(str, 60, p.fp);
109+
printf("\nUsing: %s\n", str);
110+
fclose(p.fp);
105111
for (int i = 0; i < 15; i++)
106112
{
107113
printf("\e[48;5;%dm \e[0m", i);
@@ -127,7 +133,13 @@ main(int argc, char **argv)
127133
exit(2);
128134
}
129135
strcat(p.CONF, "/kc");
130-
136+
if ( mkdir(p.CONF,0777) == 0 )
137+
{
138+
printf("Created 'kc' directory in XDG_CONFIG_HOME.");
139+
}
140+
sprintf(p.CCUR, "%s/current", p.CONF);
141+
sprintf(p.CSEQ, "%s/sequence", p.CONF);
142+
131143
if (find_palettes() == 1)
132144
{
133145
fprintf(stderr, "Palette directory not found\n");

kc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ struct
22
{
33
int cval;
44
int errf;
5-
char *MODE; // "light" or "dark"
5+
FILE *fp;
6+
DIR *dr;
7+
size_t len;
8+
char *MODE; // "light" or "dark"
69
char *CONF; // configuration path
10+
char CCUR[255]; // configuration path, current file
11+
char CSEQ[255]; // configuration path, sequence file
712
char SEL[1024]; // selected palette
813
char SEQ[1024];
914
char PRI[1024];

0 commit comments

Comments
 (0)