103 if (r < 0 || r > 255)
return NULL;
104 if (g < 0 || g > 255)
return NULL;
105 if (b < 0 || b > 255)
return NULL;
107 CSTR formatted = cstr_init();
111 cstr_set(&formatted,
"\033[38;2;");
113 snprintf(tmp,
sizeof(tmp),
"%u", r);
114 cstr_add(&formatted, tmp);
115 cstr_add(&formatted,
";");
117 snprintf(tmp,
sizeof(tmp),
"%u", g);
118 cstr_add(&formatted, tmp);
119 cstr_add(&formatted,
";");
121 snprintf(tmp,
sizeof(tmp),
"%u", b);
122 cstr_add(&formatted, tmp);
123 cstr_add(&formatted,
"m");
125 char *ret = CSTR_sys_strdup(formatted.data);
127 cstr_destroy(&formatted);
201 CSTR result = cstr_init();
202 cstr_set(&result, msg);
212 const int start = cstr_findFrom(&result,
"${", pos);
214 if (start == CSTR_NPOS)
217 const int end = cstr_findFrom(&result,
"}", start + 2);
219 if (end == CSTR_NPOS)
222 int len = (end - start) + 1;
224 cstr_erase(&result, start, len);
239 CSTR substr = cstr_init();
243 const int start = cstr_findFrom(&result,
"${", pos);
245 if (start == CSTR_NPOS)
248 const int end = cstr_findFrom(&result,
"}", start + 2);
250 if (end == CSTR_NPOS)
253 int len = (end - start) + 1;
255 cstr_set(&substr, result.data);
256 cstr_substr(&substr, start, len);
280 cstr_erase(&result, start, len);
281 cstr_insert(&result, rgbStr, start);
284 pos = start + strlen(rgbStr);
291 cstr_destroy(&substr);
294 char *ret = CSTR_sys_strdup(result.data);
296 cstr_destroy(&result);
304 const char *lowerInfo)
306 CSTR docs = cstr_init();
309 CSTR tmpContent = cstr_init();
310 cstr_set(&tmpContent,
"");
315 cstr_clear(&tmpContent);
317 cstr_add(&tmpContent, title ? title :
"");
318 cstr_add(&tmpContent,
"${R}\n");
324 cstr_add(&docs, result);
329 cstr_clear(&tmpContent);
330 cstr_add(&tmpContent,
"${ITALIC}");
331 cstr_add(&tmpContent, topInfo ? topInfo :
"");
332 cstr_add(&tmpContent,
"${R}\n");
338 cstr_add(&docs, result);
344 for (
size_t i = 0 ; i < argpar->
args.size ; i++)
348 cstr_clear(&tmpContent);
354 cstr_add(&tmpContent, info->
id);
361 cstr_add(&tmpContent, parsedColor);
362 cstr_add(&tmpContent,
" [ ");
367 cstr_add(&tmpContent, info->
param);
369 if (strlen(info->
sparam) > 0)
371 cstr_add(&tmpContent,
"|");
372 cstr_add(&tmpContent, info->
sparam);
375 for (
size_t i = 0 ; i < info->
aliases.size ; i++)
377 const char **aliasName = cvec_get(&info->
aliases, i);
379 if (!aliasName && !*aliasName)
382 cstr_add(&tmpContent,
"|");
383 cstr_add(&tmpContent, *aliasName);
391 cstr_add(&tmpContent,
" ]");
392 cstr_add(&tmpContent, parsedColor);
397 cstr_add(&tmpContent,
"; ");
398 cstr_add(&tmpContent, info->
help);
399 cstr_add(&tmpContent,
"\n");
401 cstr_add(&docs, tmpContent.data);
407 cstr_clear(&tmpContent);
408 cstr_add(&tmpContent,
"${ITALIC}");
409 cstr_add(&tmpContent, lowerInfo ? lowerInfo :
"");
410 cstr_add(&tmpContent,
"${R}");
416 cstr_add(&docs, result);
420 char *data = CSTR_sys_strdup(docs.data);
423 cstr_destroy(&tmpContent);
char * apc_generateHelp(APC_ArgParser *argpar, const char *title, const char *topInfo, const char *lowerInfo)
Automatically generate help and pass it to the string to return.