From 103b1a3f3a12cb3c18e29671cc02acbaa755efdb Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Mon, 3 Sep 2012 09:52:17 +0200 Subject: [PATCH] i3bar: Split flat line logic to read_flat_input --- i3bar/src/child.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 2ef22845..227a1435 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -191,6 +191,18 @@ static unsigned char *get_buffer(ev_io *watcher, int *ret_buffer_len) { return buffer; } +static void read_flat_input(char *buffer, int length) { + struct status_block *first = TAILQ_FIRST(&statusline_head); + /* Clear the old buffer if any. */ + I3STRING_FREE(first->full_text); + /* Remove the trailing newline and terminate the string at the same + * time. */ + if (buffer[length-1] == '\n' || buffer[length-1] == '\r') + buffer[length-1] = '\0'; + else buffer[length] = '\0'; + first->full_text = i3string_from_utf8(buffer); +} + /* * Callbalk for stdin. We read a line from stdin and store the result * in statusline @@ -231,15 +243,7 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) { status, rec, json_input); } } else { - struct status_block *first = TAILQ_FIRST(&statusline_head); - /* Clear the old buffer if any. */ - I3STRING_FREE(first->full_text); - /* Remove the trailing newline and terminate the string at the same - * time. */ - if (buffer[rec-1] == '\n' || buffer[rec-1] == '\r') - buffer[rec-1] = '\0'; - else buffer[rec] = '\0'; - first->full_text = i3string_from_utf8((const char *)buffer); + read_flat_input((char*)buffer, rec); } free(buffer); draw_bars(); -- 2.39.5