Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tmux output format to i3status #484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions i3status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/i3status.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef enum {
O_XMOBAR,
O_I3BAR,
O_LEMONBAR,
O_TMUX,
O_TERM,
O_NONE
} output_format_t;
Expand Down
17 changes: 15 additions & 2 deletions man/i3status.man
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/auto_detect_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 16 additions & 1 deletion src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ char *color(const char *colorstr) {
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", 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 <CSI><col>;1m (bright/bold
* output), where col is a 3-bit rgb-value with b in the
Expand Down Expand Up @@ -68,6 +76,13 @@ void print_separator(const char *separator) {
printf("<fc=%s>%s</fc>", 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)
Expand Down Expand Up @@ -154,4 +169,4 @@ char *trim(const char *s) {
char *f = ltrim(r);
free(r);
return f;
}
}