tell textbox widget colors

usage is simple:
,----
| echo "<screen> widget_tell <mytextbox> #[fg_color] #[bg_color] <text>" | 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.
This commit is contained in:
Rico Schiekel 2008-01-07 14:11:22 +01:00 committed by Julien Danjou
parent 44e6edf4d1
commit 079569e6b4
1 changed files with 33 additions and 1 deletions

View File

@ -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 *