mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-13 11:15:27 +00:00
Fix instead of workaround for d0edfa7004
This commit is contained in:
parent
4139ec096f
commit
f1c47e5fc4
@ -2583,11 +2583,10 @@
|
|||||||
may also contain variables. 'step' is optional and defaults
|
may also contain variables. 'step' is optional and defaults
|
||||||
to 1 if not set. If a var creates output on multiple lines
|
to 1 if not set. If a var creates output on multiple lines
|
||||||
then the lines are placed behind each other separated with
|
then the lines are placed behind each other separated with
|
||||||
a '|'-sign. The effect of $color is disabled inside scroll.
|
a '|'-sign. If you change the textcolor inside $scroll it
|
||||||
If you want spaces between the start and the end of 'text',
|
will automatically have it's old value back at the end of
|
||||||
place them at the end of 'text' not at the front ("4 foobar"
|
$scroll. The end and the start of text will be seperated by
|
||||||
can generate "arfo" but "4 foobar " will keep the space like
|
'length' number of spaces.
|
||||||
this "ar f").
|
|
||||||
<para /></listitem>
|
<para /></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
77
src/conky.c
77
src/conky.c
@ -2992,7 +2992,12 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
} else {
|
} else {
|
||||||
obj->data.scroll.step = 1;
|
obj->data.scroll.step = 1;
|
||||||
}
|
}
|
||||||
obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
|
obj->data.scroll.text = malloc(strlen(arg + n1) + obj->data.scroll.show + 1);
|
||||||
|
for(n2 = 0; (unsigned int) n2 < obj->data.scroll.show; n2++) {
|
||||||
|
obj->data.scroll.text[n2] = ' ';
|
||||||
|
}
|
||||||
|
obj->data.scroll.text[n2] = 0;
|
||||||
|
strcat(obj->data.scroll.text, arg + n1);
|
||||||
obj->data.scroll.start = 0;
|
obj->data.scroll.start = 0;
|
||||||
obj->sub = malloc(sizeof(struct text_object));
|
obj->sub = malloc(sizeof(struct text_object));
|
||||||
extract_variable_text_internal(obj->sub,
|
extract_variable_text_internal(obj->sub,
|
||||||
@ -5792,50 +5797,68 @@ static void generate_text_internal(char *p, int p_max_size,
|
|||||||
snprintf(p, p_max_size, "%s", buf);
|
snprintf(p, p_max_size, "%s", buf);
|
||||||
}
|
}
|
||||||
OBJ(scroll) {
|
OBJ(scroll) {
|
||||||
unsigned int j, k, colorchanges = 0;
|
unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
|
||||||
char *tmp, buf[max_user_text];
|
char *pwithcolors;
|
||||||
|
char buf[max_user_text];
|
||||||
generate_text_internal(buf, max_user_text,
|
generate_text_internal(buf, max_user_text,
|
||||||
*obj->sub, cur);
|
*obj->sub, cur);
|
||||||
|
|
||||||
if (strlen(buf) <= obj->data.scroll.show) {
|
|
||||||
snprintf(p, p_max_size, "%s", buf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(j = 0; buf[j] != 0; j++) {
|
for(j = 0; buf[j] != 0; j++) {
|
||||||
switch(buf[j]) {
|
switch(buf[j]) {
|
||||||
case '\n': //place all the lines behind each other with LINESEPARATOR between them
|
case '\n': //place all the lines behind each other with LINESEPARATOR between them
|
||||||
#define LINESEPARATOR '|'
|
#define LINESEPARATOR '|'
|
||||||
buf[j]=LINESEPARATOR;
|
buf[j]=LINESEPARATOR;
|
||||||
break;
|
break;
|
||||||
case 1: //make sure $color isn't treated like a char
|
case 1: //every 1 is a color change (1, not '1')
|
||||||
strfold(buf+j, 1);
|
|
||||||
colorchanges++;
|
colorchanges++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//scroll the output obj->data.scroll.start places by copying that many chars from
|
//no scrolling necessary if the length of the text to scroll is too short
|
||||||
//the front of the string to tmp, scrolling the rest to the front and placing tmp
|
if (strlen(buf) - colorchanges <= obj->data.scroll.show) {
|
||||||
//at the back of the string
|
snprintf(p, p_max_size, "%s", buf);
|
||||||
tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
|
break;
|
||||||
strncpy(tmp, buf, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
|
|
||||||
for(j = obj->data.scroll.start; buf[j] != 0; j++){
|
|
||||||
buf[j - obj->data.scroll.start] = buf[j];
|
|
||||||
}
|
}
|
||||||
strcpy(&buf[j - obj->data.scroll.start], tmp);
|
//make sure a colorchange at the front is not part of the string we are going to show
|
||||||
free(tmp);
|
while(*(buf + obj->data.scroll.start) == 1) {
|
||||||
//only show the requested number of chars
|
obj->data.scroll.start++;
|
||||||
if(obj->data.scroll.show < j) {
|
}
|
||||||
for(k = 0; k < colorchanges; k++) {
|
//place all chars that should be visible in p, including colorchanges
|
||||||
buf[obj->data.scroll.show + k] = 1;
|
for(j=0; j < obj->data.scroll.show + visibcolorchanges; j++) {
|
||||||
|
p[j] = *(buf + obj->data.scroll.start + j);
|
||||||
|
if(p[j] == 1) {
|
||||||
|
visibcolorchanges++;
|
||||||
}
|
}
|
||||||
buf[obj->data.scroll.show + colorchanges] = 0;
|
//if there is still room fill it with spaces
|
||||||
|
if( ! p[j]) break;
|
||||||
}
|
}
|
||||||
//next time, scroll a place more or reset scrolling if we are at the end
|
for(; j < obj->data.scroll.show + visibcolorchanges; j++) {
|
||||||
|
p[j] = ' ';
|
||||||
|
}
|
||||||
|
p[j] = 0;
|
||||||
|
//count colorchanges in front of the visible part and place that many colorchanges in front of the visible part
|
||||||
|
for(j = 0; j < obj->data.scroll.start; j++) {
|
||||||
|
if(buf[j] == 1) frontcolorchanges++;
|
||||||
|
}
|
||||||
|
pwithcolors=malloc(strlen(p) + 1 + colorchanges - visibcolorchanges);
|
||||||
|
for(j = 0; j < frontcolorchanges; j++) {
|
||||||
|
pwithcolors[j] = 1;
|
||||||
|
}
|
||||||
|
pwithcolors[j] = 0;
|
||||||
|
strcat(pwithcolors,p);
|
||||||
|
strend = strlen(pwithcolors);
|
||||||
|
//and place the colorchanges not in front or in the visible part behind the visible part
|
||||||
|
for(j = 0; j < colorchanges - frontcolorchanges - visibcolorchanges; j++) {
|
||||||
|
pwithcolors[strend + j] = 1;
|
||||||
|
}
|
||||||
|
pwithcolors[strend + j] = 0;
|
||||||
|
strcpy(p, pwithcolors);
|
||||||
|
free(pwithcolors);
|
||||||
|
//scroll
|
||||||
obj->data.scroll.start += obj->data.scroll.step;
|
obj->data.scroll.start += obj->data.scroll.step;
|
||||||
if(obj->data.scroll.start >= j){
|
if(buf[obj->data.scroll.start] == 0){
|
||||||
obj->data.scroll.start = 0;
|
obj->data.scroll.start = 0;
|
||||||
}
|
}
|
||||||
snprintf(p, p_max_size, "%s", buf);
|
//reset color when scroll is finished
|
||||||
new_fg(p + strlen(p), obj->data.scroll.resetcolor);
|
new_fg(p + strlen(p), obj->data.scroll.resetcolor);
|
||||||
}
|
}
|
||||||
OBJ(combine) {
|
OBJ(combine) {
|
||||||
|
Loading…
Reference in New Issue
Block a user