diff --git a/src/conky.c b/src/conky.c index 008803c1..1266298c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3940,7 +3940,6 @@ static void generate_text_internal(char *p, int p_max_size, #endif OBJ(execbar) { double barnum; - int i = 0, j = 0; read_exec(obj->data.s, p, text_buffer_size); barnum = get_barnum(p); @@ -3953,22 +3952,7 @@ static void generate_text_internal(char *p, int p_max_size, }else{ #endif if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X; - barnum = round_to_int( ( barnum * obj->a ) / 100); - #ifdef HAVE_OPENMP - #pragma omp parallel for - #endif /* HAVE_OPENMP */ - for(i=0; i<(int)barnum; i++) { - *(p+i)='#'; - } - /* gcc seems to think i is not initialized properly :/ */ - j = i; - #ifdef HAVE_OPENMP - #pragma omp parallel for - #endif /* HAVE_OPENMP */ - for(i = j/* cheats */; i < obj->a; i++) { - *(p+i)='_'; - } - *(p+i)=0; + new_bar_in_shell(p, p_max_size, barnum, obj->a); #ifdef X11 } #endif diff --git a/src/specials.c b/src/specials.c index a68d1690..c522808c 100644 --- a/src/specials.c +++ b/src/specials.c @@ -380,6 +380,29 @@ void new_bg(char *buf, long c) } #endif +void new_bar_in_shell(char* buffer, int buf_max_size, double usage, int width) +{ + if(width<=buf_max_size){ + int i = 0, j = 0, scaledusage = round_to_int( usage * width / 100); + + #ifdef HAVE_OPENMP + #pragma omp parallel for + #endif /* HAVE_OPENMP */ + for(i=0; i<(int)scaledusage; i++) { + *(buffer+i)='#'; + } + /* gcc seems to think i is not initialized properly :/ */ + j = i; + #ifdef HAVE_OPENMP + #pragma omp parallel for + #endif /* HAVE_OPENMP */ + for(i = j/* cheats */; i < width; i++) { + *(buffer+i)='_'; + } + *(buffer+i)=0; + } +} + void new_outline(char *buf, long c) { new_special(buf, OUTLINE)->arg = c; diff --git a/src/specials.h b/src/specials.h index d46e1ab1..b60acfd3 100644 --- a/src/specials.h +++ b/src/specials.h @@ -105,6 +105,7 @@ void new_graph(char *, int, int, unsigned int, void new_hr(char *, int); void new_stippled_hr(char *, int, int); #endif +void new_bar_in_shell(char *, int, double, int); void new_fg(char *, long); void new_bg(char *, long); void new_outline(char *, long);