summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2009-10-16 20:14:40 +0200
committerMichael Stapelberg <michael@stapelberg.de>2009-10-16 20:14:40 +0200
commitb88a55ffa6df3d6e48c5814171f6e8e42449b3e9 (patch)
treecbd5215aedc43a0bea7a92e87b0b3c8fe419f1b0
parentcb9bab4255a19b201d5bb13220421e687866484d (diff)
Implement format_up/format_down for ethernet
-rw-r--r--i3status.c5
-rw-r--r--i3status.conf3
-rw-r--r--i3status.h2
-rw-r--r--src/print_eth_info.c9
4 files changed, 13 insertions, 6 deletions
diff --git a/i3status.c b/i3status.c
index 6ada1d4..0e35eab 100644
--- a/i3status.c
+++ b/i3status.c
@@ -59,7 +59,8 @@ int main(int argc, char *argv[]) {
};
cfg_opt_t ethernet_opts[] = {
- CFG_STR("format", "E: %ip (%speed)", CFGF_NONE),
+ CFG_STR("format_up", "E: %ip (%speed)", CFGF_NONE),
+ CFG_STR("format_down", "E: down", CFGF_NONE),
CFG_END()
};
@@ -153,7 +154,7 @@ int main(int argc, char *argv[]) {
print_wireless_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
CASE_SEC_TITLE("ethernet")
- print_eth_info(title, cfg_getstr(sec, "format"));
+ print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
CASE_SEC_TITLE("battery")
print_battery_info(atoi(title), cfg_getstr(sec, "format"));
diff --git a/i3status.conf b/i3status.conf
index 6140f06..2c5f276 100644
--- a/i3status.conf
+++ b/i3status.conf
@@ -21,7 +21,8 @@ wireless wlan0 {
ethernet eth0 {
# if you use %speed, i3status requires root privileges
- format = "E: %ip (%speed)"
+ format_up = "E: %ip (%speed)"
+ format_down = "E: down"
}
battery 0 {
diff --git a/i3status.h b/i3status.h
index b6fdd86..3fa9644 100644
--- a/i3status.h
+++ b/i3status.h
@@ -69,7 +69,7 @@ const char *get_ip_addr();
void print_wireless_info(const char *interface, const char *format_up, const char *format_down);
void print_run_watch(const char *title, const char *pidfile, const char *format);
void print_cpu_temperature_info(int zone, const char *format);
-void print_eth_info(const char *interface, const char *format);
+void print_eth_info(const char *interface, const char *format_up, const char *format_down);
void print_load();
bool process_runs(const char *path);
diff --git a/src/print_eth_info.c b/src/print_eth_info.c
index 7624383..1da0502 100644
--- a/src/print_eth_info.c
+++ b/src/print_eth_info.c
@@ -74,11 +74,16 @@ static void print_eth_speed(const char *interface) {
* Combines ethernet IP addresses and speed (if requested) for displaying
*
*/
-void print_eth_info(const char *interface, const char *format) {
+void print_eth_info(const char *interface, const char *format_up, const char *format_down) {
const char *walk;
const char *ip_address = get_ip_addr(interface);
- for (walk = format; *walk != '\0'; walk++) {
+ if (ip_address == NULL) {
+ printf("%s", format_down);
+ return;
+ }
+
+ for (walk = format_up; *walk != '\0'; walk++) {
if (*walk != '%') {
putchar(*walk);
continue;