Skip to content

Commit 036ef42

Browse files
committed
update
1 parent aa46021 commit 036ef42

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

README

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
kc
22

3-
KISS colors, a global terminal-emulator color palette setter written in C and designed for
4-
KISS Linux.
3+
KISS colors, a terminal-emulator color palette setter written in C and designed
4+
for KISS Linux.
55

66

77
BACKGROUND
88
----------
99

10-
This project was inspired by Dylan Arap's POSIX shell okpal [0]. This code base
11-
is "mostly" functional at this time and will be promoted to release once known
12-
bugs have been closed. Compatibility with the following terminator-emulators
13-
has been tested (with more to come):
10+
This project was inspired by Dylan Arap's POSIX shell 'okpal' [0]. Compatibility
11+
with the following terminator-emulators on KISS Linux have been tested at this
12+
time:
1413

15-
- simple terminal, st [2]
14+
- simple terminal, st [2]
15+
16+
As there are no other dependєncies, other than a C compiler, this program should
17+
work on other OS distributions.
1618

1719

1820
INSTALLATION
1921
------------
2022

21-
For kc to work, XDG_CONFIG_HOME environment variable must be defined.
23+
Building and installing from source:
2224

2325
$ git clone https://github.com/mcpcpc/kc.git
2426
$ cd kc/
2527
$ make
2628
$ make install
2729

2830

31+
Installing on KISS Linux:
32+
33+
$ kiss b kc && kiss i kc
34+
35+
2936
USAGE
3037
-----
3138

@@ -39,7 +46,16 @@ kc [-s palette|-L|-r] [l|-v|-p]
3946
-v Show version information
4047

4148

49+
NEW PALETTES
50+
------------
51+
52+
Users can contribute their own custom color palettes by creating a Pull Request.
53+
54+
4255
REFERENCES
4356
----------
4457
[0] https://github.com/dylanaraps/okpal
4558
[1] https://pubs.opengroup.org/onlinepubs/7908799/xsh/getopt.html
59+
[2] Note that background, foreground and cursor color setting does not work
60+
without applying the 'OSC 10 11 12' patch.
61+
https://st.suckless.org

kc

-3.09 KB
Binary file not shown.

kc.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#include <sys/stat.h>
1+
#include <dirent.h>
22
#include <stdio.h>
33
#include <stdlib.h>
4-
#include <unistd.h>
5-
#include <dirent.h>
64
#include <string.h>
7-
#include "kc.h"
5+
#include <sys/stat.h>
86
#include <time.h>
7+
#include <unistd.h>
8+
9+
#include "kc.h"
910

1011
int
1112
find_palettes(void)
@@ -32,6 +33,13 @@ select_palette(void)
3233
p.line = malloc(sizeof(char) * p.len);
3334
char *envvar, *envval;
3435
p.fp = fopen(p.SEL, "r");
36+
37+
if (p.fp == NULL)
38+
{
39+
fprintf(stderr, "Selected palette does not exist. Do nothing\n");
40+
return 1;
41+
}
42+
3543
while(fgets(p.line, p.len, p.fp) != NULL)
3644
{
3745
envvar = strtok(p.line, "=");
@@ -68,6 +76,8 @@ select_palette(void)
6876
fclose(p.fp);
6977
sprintf(p.CLI, "%s > /dev/fd/0", p.PRI);
7078
system(p.CLI);
79+
sprintf(p.CLI, "%s > /dev/pts/%ѕ", p.PRI, 2);
80+
system(p.CLI);
7181
return 0;
7282
}
7383

@@ -110,12 +120,12 @@ random_palette(void)
110120
}
111121
closedir(p.dr);
112122
srand(time(0));
113-
int v = (rand() % (p.randf - 2 + 1)) + 2;
123+
p.i = (rand() % (p.randf - 2 + 1)) + 2;
114124
p.randf = 0;
115125
p.dr = opendir(p.SEL);
116126
while((de = readdir(p.dr)) != NULL)
117127
{
118-
if (v == p.randf)
128+
if (p.i == p.randf)
119129
{
120130
strcat(p.SEL, "/");
121131
strcat(p.SEL, de->d_name);
@@ -134,11 +144,11 @@ print_palette(void)
134144
fgets(p.line,p.len, p.fp);
135145
printf("\nUsing: %s\n", p.line);
136146
fclose(p.fp);
137-
for (int i = 0; i < 15; i++)
147+
for (p.i = 0; p.i < 15; p.i++)
138148
{
139-
printf("\033[48;5;%dm \033[0m", i);
149+
printf("\033[48;5;%dm \033[0m", p.i);
140150

141-
if (i == 7)
151+
if (p.i == 7)
142152
{
143153
printf("\n");
144154
}
@@ -185,7 +195,6 @@ main(int argc, char **argv)
185195
sprintf(p.SEL, "%s/%s", p.SEQ, p.MODE);
186196
random_palette();
187197
select_palette();
188-
print_palette();
189198
break;
190199
case 'l':
191200
sprintf(p.SEL, "%s/%s", p.SEQ, p.MODE);
@@ -194,9 +203,6 @@ main(int argc, char **argv)
194203
case 'L':
195204
p.MODE = "light";
196205
break;
197-
case 'p':
198-
print_palette();
199-
break;
200206
case 'v':
201207
printf("0.0.1\n");
202208
break;
@@ -206,8 +212,10 @@ main(int argc, char **argv)
206212
case 's':
207213
sprintf(p.SEL, "%s/%s/%s", p.SEQ, p.MODE, optarg);
208214
select_palette();
209-
print_palette();
210215
break;
216+
case 'p':
217+
print_palette();
218+
break;
211219
case ':':
212220
fprintf(stderr, "Option -%c requires an operand\n", optopt);
213221
p.errf++;

kc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
struct
22
{
3-
int cval;
3+
int i;
4+
int cval;
45
int errf;
56
int randf;
67
FILE *fp;

0 commit comments

Comments
 (0)