From 6cd43818617a6e24fb1c0b94de1c4ed96248891b Mon Sep 17 00:00:00 2001 From: Andreas Grapentin Date: Sat, 5 Mar 2022 19:55:42 +0100 Subject: [PATCH] first version of tmux output_format --- i3status.c | 2 ++ include/i3status.h | 1 + man/i3status.man | 17 +++++++++++++++-- src/auto_detect_format.c | 2 ++ src/output.c | 17 ++++++++++++++++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/i3status.c b/i3status.c index 437144f6..21bce97f 100644 --- a/i3status.c +++ b/i3status.c @@ -567,6 +567,8 @@ int main(int argc, char *argv[]) { output_format = O_I3BAR; else if (strcasecmp(output_str, "lemonbar") == 0) output_format = O_LEMONBAR; + else if (strcasecmp(output_str, "tmux") == 0) + output_format = O_TMUX; else if (strcasecmp(output_str, "term") == 0) output_format = O_TERM; else if (strcasecmp(output_str, "none") == 0) diff --git a/include/i3status.h b/include/i3status.h index fe44780b..5b214834 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -6,6 +6,7 @@ typedef enum { O_XMOBAR, O_I3BAR, O_LEMONBAR, + O_TMUX, O_TERM, O_NONE } output_format_t; diff --git a/man/i3status.man b/man/i3status.man index a9d7a021..6301cff2 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -5,7 +5,7 @@ v2.14, November 2021 == NAME -i3status - Generates a status line for i3bar, dzen2, xmobar or lemonbar +i3status - Generates a status line for i3bar, dzen2, xmobar, lemonbar or tmux == SYNOPSIS @@ -172,6 +172,8 @@ with the xmonad Window Manager. lemonbar:: lemonbar is a lightweight bar based entirely on XCB. It has full UTF-8 support and is EWMH compliant. +tmux:: +tmux is a simple terminal multiplexer that supports multiple panes and a status bar. term:: Use ANSI Escape sequences to produce a terminal-output as close as possible to the graphical outputs. This makes debugging your config file a little bit @@ -722,6 +724,17 @@ is set to +xmobar+. *Note*: +min_width+ is not supported. i3status | xmobar -o -t "%StdinReader%" -c "[Run StdinReader]" --------------------------------------------------------------------- +== Using i3status with tmux + +To use i3status with tmux, just ensure that +output_format+ is set to +tmux+ +and configure the status bar in tmux to execute i3status. *Note*: +min_width+ +is not supported. + +*Example tmux configuration for usage of i3status*: +--------------------------------------------------------------------- +set -g status-right '#(i3status)' +--------------------------------------------------------------------- + == What about CPU frequency? While talking about specific things, please understand this section as a @@ -775,7 +788,7 @@ after changing the system volume, for example. == SEE ALSO -+strftime(3)+, +date(1)+, +glob(3)+, +dzen2(1)+, +xmobar(1)+ ++strftime(3)+, +date(1)+, +glob(3)+, +dzen2(1)+, +xmobar(1)+, +tmux(1)+ == AUTHORS diff --git a/src/auto_detect_format.c b/src/auto_detect_format.c index 5bb05f3e..4810f400 100644 --- a/src/auto_detect_format.c +++ b/src/auto_detect_format.c @@ -51,6 +51,8 @@ static char *format_for_process(const char *name) { return "dzen2"; else if (strcasecmp(name, "xmobar") == 0) return "xmobar"; + else if (strcasecmp(name, "tmux") == 0) + return "tmux"; else return NULL; } diff --git a/src/output.c b/src/output.c index 9a180497..d1c04dbe 100644 --- a/src/output.c +++ b/src/output.c @@ -29,6 +29,14 @@ char *color(const char *colorstr) { (void)snprintf(colorbuf, sizeof(colorbuf), "", cfg_getstr(cfg_general, colorstr)); else if (output_format == O_LEMONBAR) (void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%s}", cfg_getstr(cfg_general, colorstr)); + else if (output_format == O_TMUX) { + /* The hex color codes for tmux need to be lowercase, because + * #F is a reserved variable that is replaced before colors are + * interpreted. This is arguably a bug in tmux. */ + char *str = cfg_getstr(cfg_general, colorstr); + int col = strtol(str + 1, NULL, 16); + (void)snprintf(colorbuf, sizeof(colorbuf), "#[fg=#%06x]", col); + } else if (output_format == O_TERM) { /* The escape-sequence for color is ;1m (bright/bold * output), where col is a 3-bit rgb-value with b in the @@ -68,6 +76,13 @@ void print_separator(const char *separator) { printf("%s", cfg_getstr(cfg_general, "color_separator"), separator); else if (output_format == O_LEMONBAR) printf("%%{F%s}%s%%{F-}", cfg_getstr(cfg_general, "color_separator"), separator); + else if (output_format == O_TMUX) { + /* This is the same situation as in `color` above. color hex + * codes need to be lowercase in tmux. */ + char *str = cfg_getstr(cfg_general, "color_separator"); + int col = strtol(str + 1, NULL, 16); + printf("#[fg=#%06x]%s#[default]", col, separator); + } else if (output_format == O_TERM) printf("%s%s%s", color("color_separator"), separator, endcolor()); else if (output_format == O_NONE) @@ -154,4 +169,4 @@ char *trim(const char *s) { char *f = ltrim(r); free(r); return f; -} \ No newline at end of file +}