Simplify textbox_tell
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
9c49a65a56
commit
cedfecc68d
|
@ -66,53 +66,34 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
static void
|
static void
|
||||||
textbox_tell(Widget *widget, char *command)
|
textbox_tell(Widget *widget, char *command)
|
||||||
{
|
{
|
||||||
char *tok, *ntok, buf[8];
|
char *ntok, *tok;
|
||||||
int i = 0, color = 0;
|
ssize_t command_len = a_strlen(command);
|
||||||
ssize_t command_len = a_strlen(command) + 1;
|
int i = 0, phys_screen = get_phys_screen(widget->statusbar->screen);
|
||||||
char* text = p_new(char, command_len);
|
|
||||||
|
|
||||||
Data *d = widget->data;
|
Data *d = widget->data;
|
||||||
if (d->text)
|
if (d->text)
|
||||||
p_delete(&d->text);
|
p_delete(&d->text);
|
||||||
|
|
||||||
for(tok = command ; tok; tok = ntok, i++)
|
for (i = 0, tok = command; tok && i < 2 && *tok == '#'; i++)
|
||||||
{
|
{
|
||||||
/* get next token */
|
ntok = strchr(tok, ' ');
|
||||||
ntok = strchr(tok + 1, ' ');
|
if((!ntok && command_len - (tok - command) == 7) ||
|
||||||
|
ntok - tok == 7)
|
||||||
/* if not first time in the loop, drop the space and put it in the
|
|
||||||
* string */
|
|
||||||
if(i)
|
|
||||||
{
|
{
|
||||||
tok++;
|
if (ntok)
|
||||||
a_strcat(text, command_len, " ");
|
*ntok = 0;
|
||||||
}
|
if (!i)
|
||||||
|
d->fg = initxcolor(phys_screen, tok);
|
||||||
if(*tok == '#' && i < 2)
|
|
||||||
{
|
|
||||||
if(ntok)
|
|
||||||
a_strncpy(buf, ssizeof(buf), tok, ntok - tok);
|
|
||||||
switch(i)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
d->fg = initxcolor(get_phys_screen(widget->statusbar->screen),
|
|
||||||
buf);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
d->bg = initxcolor(get_phys_screen(widget->statusbar->screen),
|
|
||||||
buf);
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
color++;
|
|
||||||
}
|
|
||||||
else if(ntok)
|
|
||||||
a_strncat(text, command_len, tok, ntok - tok);
|
|
||||||
else
|
else
|
||||||
a_strcat(text, command_len, tok);
|
d->bg = initxcolor(phys_screen, tok);
|
||||||
|
if (ntok)
|
||||||
|
*ntok = ' ';
|
||||||
|
tok = ntok + (ntok != NULL);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
d->text = a_strdup(text);
|
break;
|
||||||
p_delete(&text);
|
}
|
||||||
|
d->text = a_strdup(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
|
|
Loading…
Reference in New Issue