From 079569e6b45d92f679c04b42c03995e73160c241 Mon Sep 17 00:00:00 2001 From: Rico Schiekel Date: Mon, 7 Jan 2008 14:11:22 +0100 Subject: [PATCH] tell textbox widget colors usage is simple: ,---- | echo " widget_tell #[fg_color] #[bg_color] " | awesome-client | e.g. | echo "0 widget_tell t normal behaviour" | awesome-client | echo "0 widget_tell t #ff0000 red text on default background" | awesome-client | echo "0 widget_tell t #ffffff #ff0000 white text on red background" | awesome-client | ... `---- the fg and bg colors are optional. if not given, the last state is used. --- widgets/textbox.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/widgets/textbox.c b/widgets/textbox.c index 10900bea..83f9b3d5 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -66,10 +66,42 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, static void textbox_tell(Widget *widget, char *command) { + char *tok; + int i, color; + ssize_t command_len = a_strlen(command) + 1; + char* text = p_new(char, command_len); + Data *d = widget->data; if (d->text) p_delete(&d->text); - d->text = a_strdup(command); + + for(tok = strtok(command, " "), i = color = 0; tok; tok = strtok(NULL, " "), i++) + { + if(*tok == '#' && i < 2) + { + switch(i) + { + case 0: + d->fg = initxcolor(get_phys_screen(widget->statusbar->screen), + tok); + break; + case 1: + d->bg = initxcolor(get_phys_screen(widget->statusbar->screen), + tok); + break; + }; + color++; + } + else + { + if(i > color) + a_strcat(text, command_len, " "); + a_strcat(text, command_len, tok); + } + } + + d->text = a_strdup(text); + p_delete(&text); } Widget *