From a4a4cf09e8f5337fb3d7498d272acd21195f1ecb 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 | 12 +++++++++++- 5 files changed, 31 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..43eb2993 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,8 @@ 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) + printf("#[fg=%s]%s#[default]", cfg_getstr(cfg_general, "color_separator"), separator); else if (output_format == O_TERM) printf("%s%s%s", color("color_separator"), separator, endcolor()); else if (output_format == O_NONE) @@ -154,4 +164,4 @@ char *trim(const char *s) { char *f = ltrim(r); free(r); return f; -} \ No newline at end of file +}