1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <locale.h>
#define SHMNAME "/breathing_color_shm"
typedef struct {
uint32_t seq;
char color[8];
} ColorShm;
static ColorShm *accentshm;
static char accentcol[8] = "#005577";
static int
openaccent(void)
{
int fd;
if (accentshm)
return 0;
if ((fd = shm_open(SHMNAME, O_RDONLY, 0)) < 0)
return -1;
accentshm = mmap(NULL, sizeof(ColorShm), PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if (accentshm == MAP_FAILED) {
accentshm = NULL;
return -1;
}
return 0;
}
static void
updateaccent(void)
{
uint32_t s1, s2;
char tmp[8];
if (!accentshm && openaccent() < 0)
return;
do {
s1 = accentshm->seq;
memcpy(tmp, accentshm->color, 8);
s2 = accentshm->seq;
} while (s1 != s2);
if (tmp[0] == '#')
memcpy(accentcol, tmp, 8);
}
static void
hex2rgb(const char *hex, int *r, int *g, int *b)
{
unsigned int ri, gi, bi;
if (sscanf(hex + 1, "%02x%02x%02x", &ri, &gi, &bi) != 3) {
*r = 0x00; *g = 0x55; *b = 0x77;
return;
}
*r = ri; *g = gi; *b = bi;
}
static const char *icon[] = {
" ██████████████ ██████████████ ",
" ██████████████ ██████████████ ",
" ██████▓▓▓█████ █████▓▓▓██████ ",
" █████▓▓▓▓█████ █████▓▓▓▓█████ ",
" █████▓▓▓▓█████ █████▓▓▓▓█████ ",
" █████▓▓▓▓▓████ ████▓▓▓▓▓█████ ",
" █████▓▓▓▓▓████████ █████████████████████ ████████▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓█████ █████████████████████ █████▓▓▓▓▓▓▓██████ ",
"▓▓▓▓▓▓▓▓ ██████▓▓▓▓▓▓▓█████ █████████████████████ █████▓▓▓▓▓▓▓██████ ▓▓▓▓▓▓▓▓",
"▓▓▓▓▓▓▓▓▓ █████▓▓▓▓▓████ ████▓▒▒▒▒▓▓▓▒▒▒▒▓████ ████▓▓▓▓▓█████ ▓▓▓▓▓▓▓▓▓",
"▓▓▓▓▓▓▓▓▓ █████▓▓▓▓▓████ ████▓▒▒▒▒▓▓▓▒▒▒▒▓████ ████▓▓▓▓▓█████ ▓▓▓▓▓▓▓▓▓",
"▓▓▓▓▒░░░▒▓▓▓▓ █████▓▓▓▓▓▓▓▓█████▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓█████▓▓▓▓▓▓▓▓█████ ▓▓▓▓▒░░░▒▓▓▓▓",
"▓▓▓▓▒░░░▒▓▓▓▓ █████▓▓▓▓▓▓▓▓█████▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓█████▓▓▓▓▓▓▓▓█████ ▓▓▓▓▒░░░░▓▓▓▓",
"▓▓▓▓▒▒▒▒░░░░▒▓▓▓▓ █████████▓▓▓▓▓▒▒▒▓███▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓███▓▒▒▒▒▓▓▓▓█████████ ▓▓▓▓▒░░░░▒▒▒▒▓▓▓▓",
" ▒▒▒▒▒░░░░▒▓▓▓▓ ██████████▓▓▓▒▒▒▒▓███▓▓▓▓▓███████████▓▓▓▓▓███▓▒▒▒▒▓▓▓▓█████████ ▓▓▓▓▒░░░░▒▒▒▒▒ ",
" ▓▓▓▓▓░░░░▒▒▒▒▓▓▓▓████████████▓▒▒▒▓███████▓▓▓▓█████▓▓▓▓███████▓▒▒▒▒▓████████████▓▓▓▒▒▒▒░░░░▒▓▓▓▓ ",
" ████▓▒░░░░░░▒▒▓▓▓████████████▓▒▒▒▓████████▓▓▓▓▓▓▓▓▓▓▓████████▓▒▒▒▓████████████▓▓▓▓▒░░░░░░░▓████ ",
" ████▓▒▒▒▒░░░░▒▓▓▓▓███████████▓▒▒▒▓▓▓▓████▓▒▒▒▒▒▒▒▒▒▒▒▓████▓▓▓▓▒▒▒▓████████████▓▓▓▒▒░░░▒▒▒▒▓████ ",
" ▓▓▓▓▓▒░░░▒▒▒▒▓▓▓▓▓███████▓▒▒▒▒▒▒▒▓███▒░░░░░░░░░░░▒▓██▓▒▒▒▒▒▒▒▒▓██████▓▓▓▓▓▒▒▒▒░░░▒▓▓▓▓▓ ",
" ▓▓▓▓▓▒░░░▒▒▒▒▒▓▓▓▓███████▓▒▒▒▒▒▒▒▓███▒░░░░░░░░░░░▒▓██▓▒▒▒▒▒▒▒▓▓██████▓▓▓▓▓▒▒▒▒░░░▒▓▓▓▓▓ ",
" ▓▓▓▓▓▒░░░▒▒▒▒▒▒▒▒▓▓▓▓████▓▓▓▒▒░░░▒███▒░░░░░░░░░░░▒▓██▓░░░▒▒▓▓▓████▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▓▓▓▓▓ ",
" ▓▓▓▓▓▒░░░▒▒▒▒▒▒▒▒▓▓▓▓████▓▓▓▒▒░░░▒███▒░░░░░░░░░░░▒▓██▓░░░▒▒▓▓▓████▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▓▓▓▓▓ ",
" ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓██████▓▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░▒▓██████▓▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓ ",
" ▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓██████▓▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░▒▓██████▓▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓ ",
" ████▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓████ ",
" ████▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓████ ",
" █████▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓█████ ",
" █████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████ ",
" █████▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓▓▓▓█████ ",
" ████▓▓▒▒▒▓███████████▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░░░░░░░▒▒▓▓▓▓▓▓▓███████████▓▒▒▒▒▓████ ",
" ████▓▓▓▓▒▒▒▒▓▓▓▓████████▓▓▓▓▓▓▓▓▒▒▒▒▒░░░░░░░░░░░░▒▒▒▒▓▓▓▓▓▓▓▓█████████▓▓▓▒▒▒▒▓▓▓▓████ ",
" █████▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓████████████▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓████████████▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓█████ ",
" █████▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓████████████▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓████████████▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓█████ ",
" █████▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓███████████████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓█████ ",
" █████▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓███████████████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓█████ ",
" █████▓▓▓▓▓▓▓▓▓▓▓▓█████████████████████▓▓▓██████▓▓█████████████████████▓▓▓▓▓▓▓▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓▓████████▓▓▓█████████████▓▓▓█████▓▓▓█████████████▓▓▓████████▓▓▓▓▓▓▓▓▓█████ ",
" █████████▓▓▓▓▓████████▓▓▓▓████████████▓▓▓█████▓▓▓▓████████████▓▓▓████████▓▓▓▓▓█████████ ",
" █████▓▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████▓▓▓▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓▓████████▓▓▓█████████▓▓▓▓▓▓▓▓▓▓▓█████████▓▓▓████████▓▓▓▓▓▓▓▓██████ ",
" ██████▓▓▓▓▓▓▓▓████████████████████▓▓▓▓▓▓▓▓▓▓▓████████████████████▓▓▓▓▓▓▓▓██████ ",
" ██████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████████████████████ ",
" ██████████████████████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████████████████████ ",
" ██████▓▓▓▓▓▓██████▓▓▓████▓▓▓▓▓████▓▓▓██████▓▓▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓█████▓▓▓████▓▓▓▓▓████▓▓▓██████▓▓▓▓▓▓▓█████ ",
" █████▓▓▓▓▓▓▓▓█████████████████████████████▓▓▓▓▓▓▓▓█████ ",
" █████▓▓▓▓▓▓▓▓█████████▓▓▓█████▓▓▓█████████▓▓▓▓▓▓▓▓█████ ",
" ██████▓▓▓▓▓▓▓█████████▓▓▓▓███▓▓▓▓██████████▓▓▓▓▓▓██████ ",
" ██████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██████████████████ ",
" █████████████████████▓▓▓▓▓▓▓▓▓▓▓▓▓█████████████████████ ",
" █████████████████▓▓▓▓▓▓▓▓▓▓▓██████████████████ ",
" ██████████████████████████████████████████████ ",
" █████████████ ",
" █████████████ ",
NULL};
int
main(void)
{
setlocale(LC_ALL, "");
openaccent();
updateaccent();
int r, g, b;
hex2rgb(accentcol, &r, &g, &b);
for (int i = 0; icon[i]; i++)
printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m\n", r, g, b, icon[i]);
printf("\n");
char host[256] = "";
gethostname(host, sizeof host);
struct utsname uts;
uname(&uts);
struct sysinfo info;
sysinfo(&info);
char os[128] = "Unknown";
FILE *fp = fopen("/etc/os-release", "r");
if (fp) {
char line[256];
while (fgets(line, sizeof line, fp)) {
if (strncmp(line, "PRETTY_NAME=", 12) == 0) {
char *p = line + 12;
if (*p == '"') p++;
char *e = strchr(p, '"');
if (e) *e = '\0';
snprintf(os, sizeof os, "%s", p);
break;
}
}
fclose(fp);
}
long updays = info.uptime / 86400;
long uphours = (info.uptime / 3600) % 24;
long upmins = (info.uptime / 60) % 60;
char cpu[128] = "Unknown";
fp = fopen("/proc/cpuinfo", "r");
if (fp) {
char line[256];
while (fgets(line, sizeof line, fp)) {
if (strncmp(line, "model name", 10) == 0) {
char *p = strchr(line, ':');
if (p) {
p += 2;
p[strcspn(p, "\n")] = '\0';
snprintf(cpu, sizeof cpu, "%s", p);
}
break;
}
}
fclose(fp);
}
long totalmem = info.totalram / 1024 / 1024;
long freemem = info.freeram / 1024 / 1024;
long usedmem = totalmem - freemem;
char shell[64];
snprintf(shell, sizeof shell, "%s", getenv("SHELL") ? getenv("SHELL") : "Unknown");
char term[64];
snprintf(term, sizeof term, "%s", getenv("TERM") ? getenv("TERM") : "Unknown");
char packages[32] = "Unknown";
if ((fp = popen("dpkg-query -f '${binary:Package}\\n' -W 2>/dev/null | wc -l", "r"))) {
if (fgets(packages, sizeof packages, fp))
packages[strcspn(packages, "\n")] = '\0';
pclose(fp);
}
printf("\x1b[38;2;%d;%d;%dmHost:\x1b[0m %s\n", r, g, b, host);
printf("\x1b[38;2;%d;%d;%dmOS:\x1b[0m %s\n", r, g, b, os);
printf("\x1b[38;2;%d;%d;%dmKernel:\x1b[0m %s\n", r, g, b, uts.release);
printf("\x1b[38;2;%d;%d;%dmUptime:\x1b[0m %ldd %ldh %ldm\n", r, g, b, updays, uphours, upmins);
printf("\x1b[38;2;%d;%d;%dmPackages:\x1b[0m %s\n", r, g, b, packages);
printf("\x1b[38;2;%d;%d;%dmShell:\x1b[0m %s\n", r, g, b, shell);
printf("\x1b[38;2;%d;%d;%dmTerminal:\x1b[0m %s\n", r, g, b, term);
printf("\x1b[38;2;%d;%d;%dmCPU:\x1b[0m %s\n", r, g, b, cpu);
printf("\x1b[38;2;%d;%d;%dmMemory:\x1b[0m %ldMiB / %ldMiB\n", r, g, b, usedmem, totalmem);
return 0;
}
|