Change output format to be a config option instead of a compile time define
This commit is contained in:
parent
6cf9059664
commit
013fdece8d
12
i3status.c
12
i3status.c
@ -41,6 +41,7 @@ int main(int argc, char *argv[]) {
|
|||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
|
||||||
cfg_opt_t general_opts[] = {
|
cfg_opt_t general_opts[] = {
|
||||||
|
CFG_STR("output_format", "dzen2", CFGF_NONE),
|
||||||
CFG_BOOL("colors", 1, CFGF_NONE),
|
CFG_BOOL("colors", 1, CFGF_NONE),
|
||||||
CFG_INT("interval", 1, CFGF_NONE),
|
CFG_INT("interval", 1, CFGF_NONE),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
@ -137,6 +138,17 @@ int main(int argc, char *argv[]) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
cfg_general = cfg_getsec(cfg, "general");
|
cfg_general = cfg_getsec(cfg, "general");
|
||||||
|
if (cfg_general == NULL)
|
||||||
|
die("Could not get section \"general\"\n");
|
||||||
|
|
||||||
|
char *output_str = cfg_getstr(cfg_general, "output_format");
|
||||||
|
if (strcasecmp(output_str, "dzen2") == 0)
|
||||||
|
output_format = O_DZEN2;
|
||||||
|
else if (strcasecmp(output_str, "xmobar") == 0)
|
||||||
|
output_format = O_XMOBAR;
|
||||||
|
else if (strcasecmp(output_str, "none") == 0)
|
||||||
|
output_format = O_NONE;
|
||||||
|
else die("Unknown output format: \"%s\"\n", output_str);
|
||||||
|
|
||||||
if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||||
die("Could not create socket\n");
|
die("Could not create socket\n");
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
#ifndef _I3STATUS_H
|
#ifndef _I3STATUS_H
|
||||||
#define _I3STATUS_H
|
#define _I3STATUS_H
|
||||||
|
|
||||||
#if !defined(DZEN) && !defined(XMOBAR)
|
enum { O_DZEN2, O_XMOBAR, O_NONE } output_format;
|
||||||
#error "You have to enable either -DDZEN or -DXMOBAR"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <confuse.h>
|
#include <confuse.h>
|
||||||
|
|
||||||
#ifdef DZEN
|
|
||||||
#define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)"
|
|
||||||
#elif XMOBAR
|
|
||||||
#define BAR "<fc=#333333> | </fc>"
|
|
||||||
#endif
|
|
||||||
#define BEGINS_WITH(haystack, needle) (strncmp(haystack, needle, strlen(needle)) == 0)
|
#define BEGINS_WITH(haystack, needle) (strncmp(haystack, needle, strlen(needle)) == 0)
|
||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
|
27
src/output.c
27
src/output.c
@ -20,11 +20,11 @@ char *color(const char *colorstr) {
|
|||||||
colorbuf[0] = '\0';
|
colorbuf[0] = '\0';
|
||||||
return colorbuf;
|
return colorbuf;
|
||||||
}
|
}
|
||||||
#ifdef DZEN
|
if (output_format == O_DZEN2)
|
||||||
(void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
|
(void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
|
||||||
#elif XMOBAR
|
else if (output_format == O_XMOBAR)
|
||||||
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
|
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
|
||||||
#endif
|
|
||||||
return colorbuf;
|
return colorbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,15 +33,16 @@ char *color(const char *colorstr) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char *endcolor() {
|
char *endcolor() {
|
||||||
#ifdef XMOBAR
|
if (output_format == O_XMOBAR)
|
||||||
return "</fc>";
|
return "</fc>";
|
||||||
#else
|
else return "";
|
||||||
return "";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_seperator() {
|
void print_seperator() {
|
||||||
#if defined(DZEN) || defined(XMOBAR)
|
if (output_format == O_DZEN2)
|
||||||
printf("%s", BAR);
|
printf("^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)");
|
||||||
#endif
|
else if (output_format == O_XMOBAR)
|
||||||
|
printf("<fc=#333333> | </fc>");
|
||||||
|
else if (output_format == O_NONE)
|
||||||
|
printf(" | ");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user