summaryrefslogtreecommitdiff
path: root/i3status.c
diff options
context:
space:
mode:
authorAxel Wagner <mail@merovius.de>2013-05-16 22:49:13 +0200
committerMichael Stapelberg <michael@stapelberg.de>2013-05-19 19:51:01 +0200
commit7a372b0f4627b9482d1276238348a1432c13fbe3 (patch)
tree0512bedece7ba0157c89f917c138934920ac1373 /i3status.c
parent8445d6a929303ca8d63f8d04fd7594a05a2734d6 (diff)
Implement term-output-format
Diffstat (limited to 'i3status.c')
-rw-r--r--i3status.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/i3status.c b/i3status.c
index df233f7..5311ca9 100644
--- a/i3status.c
+++ b/i3status.c
@@ -48,12 +48,15 @@ int general_socket;
cfg_t *cfg, *cfg_general, *cfg_section;
/*
- * Exit upon SIGPIPE because when we have nowhere to write to, gathering
- * system information is pointless.
+ * Exit upon SIGPIPE because when we have nowhere to write to, gathering system
+ * information is pointless. Also exit explicitly on SIGTERM and SIGINT because
+ * only this will trigger a reset of the cursor in the terminal output-format.
*
*/
-void sigpipe(int signum) {
- fprintf(stderr, "Received SIGPIPE, exiting\n");
+void fatalsig(int signum) {
+ fprintf(stderr, "Received SIG%s, exiting\n", signum == SIGPIPE ? "PIPE" :
+ signum == SIGTERM ? "TERM" :
+ "INT");
exit(1);
}
@@ -321,8 +324,10 @@ int main(int argc, char *argv[]) {
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
- action.sa_handler = sigpipe;
+ action.sa_handler = fatalsig;
sigaction(SIGPIPE, &action, NULL);
+ sigaction(SIGTERM, &action, NULL);
+ sigaction(SIGINT, &action, NULL);
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = sigusr1;
@@ -376,6 +381,8 @@ int main(int argc, char *argv[]) {
output_format = O_XMOBAR;
else if (strcasecmp(output_str, "i3bar") == 0)
output_format = O_I3BAR;
+ else if (strcasecmp(output_str, "term") == 0)
+ output_format = O_TERM;
else if (strcasecmp(output_str, "none") == 0)
output_format = O_NONE;
else die("Unknown output format: \"%s\"\n", output_str);
@@ -400,6 +407,12 @@ int main(int argc, char *argv[]) {
yajl_gen_array_open(json_gen);
yajl_gen_clear(json_gen);
}
+ if (output_format == O_TERM) {
+ /* Save the cursor-position and hide the cursor */
+ printf("\033[s\033[?25l");
+ /* Undo at exit */
+ atexit(&reset_cursor);
+ }
if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
die("Could not create socket\n");
@@ -419,6 +432,9 @@ int main(int argc, char *argv[]) {
gettimeofday(&tv, NULL);
if (output_format == O_I3BAR)
yajl_gen_array_open(json_gen);
+ else if (output_format == O_TERM)
+ /* Restore the cursor-position */
+ printf("\033[u");
for (j = 0; j < cfg_size(cfg, "order"); j++) {
if (j > 0)
print_seperator();