From 85a2b9b79d1f5422bee87ef9ca0cd33a02440c1c Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Thu, 18 Aug 2016 13:43:18 +0200 Subject: added uptime function --- README.md | 1 + config.def.h | 1 + slstatus.c | 18 ++++++++++++++++++ slstatus.h | 1 + 4 files changed, 21 insertions(+) diff --git a/README.md b/README.md index feb63f5..dad5df7 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The following information is included: - load avg - ram numbers (free ram, percentage, total ram and used ram) - temperature +- uptime - volume percentage (alsa) - wifi percentage and essid diff --git a/config.def.h b/config.def.h index 2dd05de..5fb52b3 100644 --- a/config.def.h +++ b/config.def.h @@ -34,6 +34,7 @@ static const char unknowntext[] = "n/a"; - run_command (run custom shell command) [argument: command] - temp (temperature in degrees) [argument: temperature file] - uid (uid of current user) [argument: NULL] +- uptime (uptime) [argument: NULL] - username (username of current user) [argument: NULL] - vol_perc (alsa volume and mute status in percent) [argument: soundcard] - wifi_perc (wifi signal in percent) [argument: wifi card interface name] diff --git a/slstatus.c b/slstatus.c index 87e705d..fee56fc 100644 --- a/slstatus.c +++ b/slstatus.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -521,6 +522,23 @@ temp(const char *file) return smprintf("%d°C", temperature / 1000); } +/* uptime */ +char * +uptime(const char *null) +{ + struct sysinfo info; + int hours = 0; + int minutes = 0; + + /* get info */ + sysinfo(&info); + hours = info.uptime / 3600; + minutes = (info.uptime - hours * 3600 ) / 60; + + /* return it */ + return smprintf("%dh %dm", hours, minutes); +} + /* username */ char * username(const char *null) diff --git a/slstatus.h b/slstatus.h index 5efc5f2..9d6de2e 100644 --- a/slstatus.h +++ b/slstatus.h @@ -33,6 +33,7 @@ char *ram_total(const char *); char *run_command(const char *); char *temp(const char *); char *uid(const char*); +char *uptime(const char*); char *username(const char*); char *vol_perc(const char *); char *wifi_perc(const char *); -- cgit v1.2.3