Skip to content

Commit 6cd4381

Browse files
committed
first version of tmux output_format
1 parent 28399bf commit 6cd4381

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

i3status.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ int main(int argc, char *argv[]) {
567567
output_format = O_I3BAR;
568568
else if (strcasecmp(output_str, "lemonbar") == 0)
569569
output_format = O_LEMONBAR;
570+
else if (strcasecmp(output_str, "tmux") == 0)
571+
output_format = O_TMUX;
570572
else if (strcasecmp(output_str, "term") == 0)
571573
output_format = O_TERM;
572574
else if (strcasecmp(output_str, "none") == 0)

include/i3status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ typedef enum {
66
O_XMOBAR,
77
O_I3BAR,
88
O_LEMONBAR,
9+
O_TMUX,
910
O_TERM,
1011
O_NONE
1112
} output_format_t;

man/i3status.man

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ v2.14, November 2021
55

66
== NAME
77

8-
i3status - Generates a status line for i3bar, dzen2, xmobar or lemonbar
8+
i3status - Generates a status line for i3bar, dzen2, xmobar, lemonbar or tmux
99

1010
== SYNOPSIS
1111

@@ -172,6 +172,8 @@ with the xmonad Window Manager.
172172
lemonbar::
173173
lemonbar is a lightweight bar based entirely on XCB. It has full UTF-8 support
174174
and is EWMH compliant.
175+
tmux::
176+
tmux is a simple terminal multiplexer that supports multiple panes and a status bar.
175177
term::
176178
Use ANSI Escape sequences to produce a terminal-output as close as possible to
177179
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.
722724
i3status | xmobar -o -t "%StdinReader%" -c "[Run StdinReader]"
723725
---------------------------------------------------------------------
724726

727+
== Using i3status with tmux
728+
729+
To use i3status with tmux, just ensure that +output_format+ is set to +tmux+
730+
and configure the status bar in tmux to execute i3status. *Note*: +min_width+
731+
is not supported.
732+
733+
*Example tmux configuration for usage of i3status*:
734+
---------------------------------------------------------------------
735+
set -g status-right '#(i3status)'
736+
---------------------------------------------------------------------
737+
725738
== What about CPU frequency?
726739

727740
While talking about specific things, please understand this section as a
@@ -775,7 +788,7 @@ after changing the system volume, for example.
775788

776789
== SEE ALSO
777790

778-
+strftime(3)+, +date(1)+, +glob(3)+, +dzen2(1)+, +xmobar(1)+
791+
+strftime(3)+, +date(1)+, +glob(3)+, +dzen2(1)+, +xmobar(1)+, +tmux(1)+
779792

780793
== AUTHORS
781794

src/auto_detect_format.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static char *format_for_process(const char *name) {
5151
return "dzen2";
5252
else if (strcasecmp(name, "xmobar") == 0)
5353
return "xmobar";
54+
else if (strcasecmp(name, "tmux") == 0)
55+
return "tmux";
5456
else
5557
return NULL;
5658
}

src/output.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ char *color(const char *colorstr) {
2929
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
3030
else if (output_format == O_LEMONBAR)
3131
(void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%s}", cfg_getstr(cfg_general, colorstr));
32+
else if (output_format == O_TMUX) {
33+
/* The hex color codes for tmux need to be lowercase, because
34+
* #F is a reserved variable that is replaced before colors are
35+
* interpreted. This is arguably a bug in tmux. */
36+
char *str = cfg_getstr(cfg_general, colorstr);
37+
int col = strtol(str + 1, NULL, 16);
38+
(void)snprintf(colorbuf, sizeof(colorbuf), "#[fg=#%06x]", col);
39+
}
3240
else if (output_format == O_TERM) {
3341
/* The escape-sequence for color is <CSI><col>;1m (bright/bold
3442
* output), where col is a 3-bit rgb-value with b in the
@@ -68,6 +76,13 @@ void print_separator(const char *separator) {
6876
printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
6977
else if (output_format == O_LEMONBAR)
7078
printf("%%{F%s}%s%%{F-}", cfg_getstr(cfg_general, "color_separator"), separator);
79+
else if (output_format == O_TMUX) {
80+
/* This is the same situation as in `color` above. color hex
81+
* codes need to be lowercase in tmux. */
82+
char *str = cfg_getstr(cfg_general, "color_separator");
83+
int col = strtol(str + 1, NULL, 16);
84+
printf("#[fg=#%06x]%s#[default]", col, separator);
85+
}
7186
else if (output_format == O_TERM)
7287
printf("%s%s%s", color("color_separator"), separator, endcolor());
7388
else if (output_format == O_NONE)
@@ -154,4 +169,4 @@ char *trim(const char *s) {
154169
char *f = ltrim(r);
155170
free(r);
156171
return f;
157-
}
172+
}

0 commit comments

Comments
 (0)